Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
-
|
5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
-
"""
|
7 |
-
|
8 |
-
# client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct")
|
9 |
-
# client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
10 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
11 |
|
12 |
-
# client = InferenceClient("meta-llama/Meta-Llama-3-8B-Instruct" , "HPAI-BSC/Llama3-Aloe-8B-Alpha")
|
13 |
-
# client = InferenceClient("Xenova/gpt-4o")
|
14 |
-
# client = InferenceClient("mistralai/mamba-codestral-7B-v0.1")
|
15 |
-
# client = InferenceClient("deepseek-ai/DeepSeek-Coder-V2-Instruct")
|
16 |
-
|
17 |
def respond(
|
18 |
message,
|
19 |
history: list[tuple[str, str]],
|
@@ -24,16 +14,14 @@ def respond(
|
|
24 |
):
|
25 |
messages = [{"role": "system", "content": system_message}]
|
26 |
|
27 |
-
for
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
messages.append({"role": "assistant", "content": val[1]})
|
32 |
|
33 |
messages.append({"role": "user", "content": message})
|
34 |
|
35 |
response = ""
|
36 |
-
|
37 |
for message in client.chat_completion(
|
38 |
messages,
|
39 |
max_tokens=max_tokens,
|
@@ -42,17 +30,14 @@ def respond(
|
|
42 |
top_p=top_p,
|
43 |
):
|
44 |
token = message.choices[0].delta.content
|
45 |
-
|
46 |
response += token
|
47 |
yield response
|
48 |
|
49 |
-
|
50 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
51 |
-
"""
|
52 |
demo = gr.ChatInterface(
|
53 |
respond,
|
54 |
additional_inputs=[
|
55 |
-
gr.Textbox(value="You are a friendly Chatbot.
|
56 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
57 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
58 |
gr.Slider(
|
@@ -65,6 +50,5 @@ demo = gr.ChatInterface(
|
|
65 |
],
|
66 |
)
|
67 |
|
68 |
-
|
69 |
if __name__ == "__main__":
|
70 |
-
demo.launch(show_error=True)
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
+
# Initialize the InferenceClient with the chosen model
|
|
|
|
|
|
|
|
|
|
|
5 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
6 |
|
|
|
|
|
|
|
|
|
|
|
7 |
def respond(
|
8 |
message,
|
9 |
history: list[tuple[str, str]],
|
|
|
14 |
):
|
15 |
messages = [{"role": "system", "content": system_message}]
|
16 |
|
17 |
+
for user_msg, bot_msg in history:
|
18 |
+
messages.append({"role": "user", "content": user_msg})
|
19 |
+
if bot_msg:
|
20 |
+
messages.append({"role": "assistant", "content": bot_msg})
|
|
|
21 |
|
22 |
messages.append({"role": "user", "content": message})
|
23 |
|
24 |
response = ""
|
|
|
25 |
for message in client.chat_completion(
|
26 |
messages,
|
27 |
max_tokens=max_tokens,
|
|
|
30 |
top_p=top_p,
|
31 |
):
|
32 |
token = message.choices[0].delta.content
|
|
|
33 |
response += token
|
34 |
yield response
|
35 |
|
36 |
+
# Setup the Gradio interface
|
|
|
|
|
37 |
demo = gr.ChatInterface(
|
38 |
respond,
|
39 |
additional_inputs=[
|
40 |
+
gr.Textbox(value="You are a friendly Chatbot. Your name is QuizBot, you are a code expert. Output everything in JSON format.", label="System message"),
|
41 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
42 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
43 |
gr.Slider(
|
|
|
50 |
],
|
51 |
)
|
52 |
|
|
|
53 |
if __name__ == "__main__":
|
54 |
+
demo.launch(show_error=True)
|