Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,36 +5,32 @@ from huggingface_hub import InferenceClient
|
|
5 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
6 |
|
7 |
# Define the conversation flow
|
8 |
-
def respond(
|
9 |
-
|
10 |
-
history: list[tuple[str, str]],
|
11 |
-
system_message,
|
12 |
-
max_tokens,
|
13 |
-
temperature,
|
14 |
-
top_p,
|
15 |
-
):
|
16 |
-
#... (rest of the code remains the same)
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
|
37 |
-
|
|
|
|
|
|
|
38 |
css = """
|
39 |
body {
|
40 |
background-color: #f9f9f9;
|
@@ -69,7 +65,13 @@ body {
|
|
69 |
background-color: #2980b9;
|
70 |
}
|
71 |
"""
|
72 |
-
demo.css(css)
|
73 |
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
6 |
|
7 |
# Define the conversation flow
|
8 |
+
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
9 |
+
messages = [{"role": "system", "content": system_message}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
for val in history:
|
12 |
+
if val[0]:
|
13 |
+
messages.append({"role": "user", "content": val[0]})
|
14 |
+
if val[1]:
|
15 |
+
messages.append({"role": "assistant", "content": val[1]})
|
16 |
+
|
17 |
+
messages.append({"role": "user", "content": message})
|
18 |
+
|
19 |
+
response = ""
|
20 |
+
|
21 |
+
for message in client.chat_completion(
|
22 |
+
messages,
|
23 |
+
max_tokens=max_tokens,
|
24 |
+
stream=True,
|
25 |
+
temperature=temperature,
|
26 |
+
top_p=top_p,
|
27 |
+
):
|
28 |
+
token = message.choices[0].delta.content
|
29 |
|
30 |
+
response += token
|
31 |
+
yield response
|
32 |
+
|
33 |
+
# Create the chat interface
|
34 |
css = """
|
35 |
body {
|
36 |
background-color: #f9f9f9;
|
|
|
65 |
background-color: #2980b9;
|
66 |
}
|
67 |
"""
|
|
|
68 |
|
69 |
+
demo = gr.Interface(
|
70 |
+
fn=respond,
|
71 |
+
inputs=["text", "state", "text", "slider", "slider", "slider"],
|
72 |
+
outputs="text",
|
73 |
+
title="NVS AI: Health Conversational Chatbot",
|
74 |
+
description="Get answers to your health-related questions!",
|
75 |
+
)
|
76 |
+
|
77 |
+
demo.launch()
|