Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,13 @@
|
|
1 |
-
from huggingface_hub import InferenceClient
|
2 |
import gradio as gr
|
3 |
|
|
|
|
|
|
|
4 |
# Initialize the InferenceClient
|
5 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
6 |
|
|
|
|
|
7 |
def format_prompt(message, history):
|
8 |
prompt = "<s>"
|
9 |
for user_prompt, bot_response in history:
|
@@ -12,7 +16,7 @@ def format_prompt(message, history):
|
|
12 |
prompt += f"[INST] {message} [/INST]"
|
13 |
return prompt
|
14 |
|
15 |
-
def generate(prompt, history, system_prompt,
|
16 |
temperature = max(float(temperature), 1e-2)
|
17 |
top_p = float(top_p)
|
18 |
|
@@ -34,23 +38,19 @@ def generate(prompt, history, system_prompt, theme, temperature=0.9, max_new_tok
|
|
34 |
yield output
|
35 |
return output
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
"
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
"Soft": gr.themes.Soft()
|
44 |
-
}
|
45 |
-
return theme_mapping.get(theme_name, gr.themes.Soft())
|
46 |
|
47 |
additional_inputs = [
|
48 |
gr.Textbox(label="System Prompt", max_lines=1, interactive=True),
|
49 |
gr.Slider(label="Temperature", value=0.9, minimum=0.0, maximum=1.0, step=0.05, interactive=True, info="Higher values produce more diverse outputs"),
|
50 |
gr.Slider(label="Max new tokens", value=9048, minimum=256, maximum=9048, step=64, interactive=True, info="The maximum numbers of new tokens"),
|
51 |
gr.Slider(label="Top-p (nucleus sampling)", value=0.90, minimum=0.0, maximum=1, step=0.05, interactive=True, info="Higher values sample more low-probability tokens"),
|
52 |
-
gr.Slider(label="Repetition penalty", value=1.2, minimum=1.0, maximum=2.0, step=0.05, interactive=True, info="Penalize repeated tokens")
|
53 |
-
gr.Dropdown(label="Theme", choices=["Default", "Base", "Glass", "Monochrome", "Soft"], interactive=True, info="Select a theme for the app")
|
54 |
]
|
55 |
|
56 |
gr.ChatInterface(
|
@@ -58,7 +58,7 @@ gr.ChatInterface(
|
|
58 |
chatbot=gr.Chatbot(show_label=True, show_share_button=True, show_copy_button=True, likeable=True, layout="panel"),
|
59 |
additional_inputs=additional_inputs,
|
60 |
title="ConvoLite",
|
61 |
-
description=
|
62 |
concurrency_limit=20,
|
63 |
-
|
64 |
-
).launch(show_api=False)
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
# Set the theme
|
4 |
+
gr.Interface.load_theme(gr.themes.Soft())
|
5 |
+
|
6 |
# Initialize the InferenceClient
|
7 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
8 |
|
9 |
+
# This code was mostly written by vericudebuget and gpt-4
|
10 |
+
|
11 |
def format_prompt(message, history):
|
12 |
prompt = "<s>"
|
13 |
for user_prompt, bot_response in history:
|
|
|
16 |
prompt += f"[INST] {message} [/INST]"
|
17 |
return prompt
|
18 |
|
19 |
+
def generate(prompt, history, system_prompt, temperature=0.9, max_new_tokens=9048, top_p=0.95, repetition_penalty=1.0):
|
20 |
temperature = max(float(temperature), 1e-2)
|
21 |
top_p = float(top_p)
|
22 |
|
|
|
38 |
yield output
|
39 |
return output
|
40 |
|
41 |
+
for response in stream:
|
42 |
+
output += response.token.text
|
43 |
+
if "http" in output: # assuming the AI writes a direct image link in its response
|
44 |
+
yield {"image": output} # Gradio will display the image
|
45 |
+
else:
|
46 |
+
yield output
|
|
|
|
|
|
|
47 |
|
48 |
additional_inputs = [
|
49 |
gr.Textbox(label="System Prompt", max_lines=1, interactive=True),
|
50 |
gr.Slider(label="Temperature", value=0.9, minimum=0.0, maximum=1.0, step=0.05, interactive=True, info="Higher values produce more diverse outputs"),
|
51 |
gr.Slider(label="Max new tokens", value=9048, minimum=256, maximum=9048, step=64, interactive=True, info="The maximum numbers of new tokens"),
|
52 |
gr.Slider(label="Top-p (nucleus sampling)", value=0.90, minimum=0.0, maximum=1, step=0.05, interactive=True, info="Higher values sample more low-probability tokens"),
|
53 |
+
gr.Slider(label="Repetition penalty", value=1.2, minimum=1.0, maximum=2.0, step=0.05, interactive=True, info="Penalize repeated tokens")
|
|
|
54 |
]
|
55 |
|
56 |
gr.ChatInterface(
|
|
|
58 |
chatbot=gr.Chatbot(show_label=True, show_share_button=True, show_copy_button=True, likeable=True, layout="panel"),
|
59 |
additional_inputs=additional_inputs,
|
60 |
title="ConvoLite",
|
61 |
+
description= Remember! The AI might give incorect information about people, locations, history, etc...
|
62 |
concurrency_limit=20,
|
63 |
+
|
64 |
+
).launch(show_api=False,)
|