Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,11 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
client = InferenceClient("
|
| 5 |
|
| 6 |
def respond(message, history):
|
|
|
|
|
|
|
| 7 |
|
| 8 |
messages = [{"role": "system", "content": "You are a friendly chatbot."}]
|
| 9 |
|
|
@@ -12,14 +14,20 @@ def respond(message, history):
|
|
| 12 |
|
| 13 |
messages.append({"role": "user", "content": message})
|
| 14 |
|
| 15 |
-
|
| 16 |
messages,
|
| 17 |
max_tokens=100,
|
| 18 |
-
temperature=1.2
|
|
|
|
| 19 |
)
|
| 20 |
-
|
| 21 |
-
return response['choices'][0]['message']['content'].strip()
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
chatbot = gr.ChatInterface(respond, type="messages")
|
| 24 |
|
| 25 |
chatbot.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 5 |
|
| 6 |
def respond(message, history):
|
| 7 |
+
|
| 8 |
+
response=""
|
| 9 |
|
| 10 |
messages = [{"role": "system", "content": "You are a friendly chatbot."}]
|
| 11 |
|
|
|
|
| 14 |
|
| 15 |
messages.append({"role": "user", "content": message})
|
| 16 |
|
| 17 |
+
stream = client.chat_completion(
|
| 18 |
messages,
|
| 19 |
max_tokens=100,
|
| 20 |
+
temperature=1.2,
|
| 21 |
+
stream=True
|
| 22 |
)
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
for message in stream:
|
| 25 |
+
token = message.choices[0].delta.content
|
| 26 |
+
|
| 27 |
+
if token is not None:
|
| 28 |
+
response += token
|
| 29 |
+
yield response
|
| 30 |
+
|
| 31 |
chatbot = gr.ChatInterface(respond, type="messages")
|
| 32 |
|
| 33 |
chatbot.launch()
|