Commit
·
a3ea183
1
Parent(s):
eeb9742
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,26 +1,16 @@
|
|
| 1 |
-
from huggingface_hub import InferenceClient
|
| 2 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
def format_prompt(message, history):
|
| 7 |
-
prompt = "<s>"
|
| 8 |
-
for user_prompt, bot_response in history:
|
| 9 |
-
prompt += f"[INST] {user_prompt} [/INST]"
|
| 10 |
-
prompt += f" {bot_response} "
|
| 11 |
-
prompt += f"[INST] {message} [/INST]"
|
| 12 |
-
return prompt
|
| 13 |
-
|
| 14 |
-
def generate(
|
| 15 |
-
prompt, history, temperature=0.3, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
|
| 16 |
-
):
|
| 17 |
-
temperature = float(temperature)
|
| 18 |
-
if temperature < 1e-2:
|
| 19 |
-
temperature = 1e-2
|
| 20 |
top_p = float(top_p)
|
| 21 |
|
| 22 |
generate_kwargs = dict(
|
| 23 |
-
temperature=
|
| 24 |
max_new_tokens=max_new_tokens,
|
| 25 |
top_p=top_p,
|
| 26 |
repetition_penalty=repetition_penalty,
|
|
@@ -28,7 +18,7 @@ def generate(
|
|
| 28 |
seed=42,
|
| 29 |
)
|
| 30 |
|
| 31 |
-
formatted_prompt =
|
| 32 |
|
| 33 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
| 34 |
output = ""
|
|
@@ -38,11 +28,12 @@ def generate(
|
|
| 38 |
yield output
|
| 39 |
return output
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
| 47 |
|
| 48 |
-
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from huggingface_hub import InferenceClient
|
| 3 |
+
|
| 4 |
+
client = InferenceClient("mistralai/Mistral-7B-v0.1")
|
| 5 |
+
|
| 6 |
+
# Fixed temperature value
|
| 7 |
+
fixed_temperature = 0.9 # You can adjust this value as needed
|
| 8 |
|
| 9 |
+
def generate(prompt, max_new_tokens=6056, top_p=0.95, repetition_penalty=1.0):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
top_p = float(top_p)
|
| 11 |
|
| 12 |
generate_kwargs = dict(
|
| 13 |
+
temperature=fixed_temperature,
|
| 14 |
max_new_tokens=max_new_tokens,
|
| 15 |
top_p=top_p,
|
| 16 |
repetition_penalty=repetition_penalty,
|
|
|
|
| 18 |
seed=42,
|
| 19 |
)
|
| 20 |
|
| 21 |
+
formatted_prompt = f"<s>[INST] {prompt} [/INST]"
|
| 22 |
|
| 23 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
| 24 |
output = ""
|
|
|
|
| 28 |
yield output
|
| 29 |
return output
|
| 30 |
|
| 31 |
+
iface = gr.Interface(
|
| 32 |
+
fn=generate,
|
| 33 |
+
inputs="text",
|
| 34 |
+
outputs="text",
|
| 35 |
+
title="Mistralai-Mistral-7B-Instruct Chat",
|
| 36 |
+
live=False # Set live to False to add a "Submit" button
|
| 37 |
+
)
|
| 38 |
|
| 39 |
+
iface.launch()
|