Update app.py
Browse files
app.py
CHANGED
@@ -3,11 +3,11 @@ from huggingface_hub import InferenceClient
|
|
3 |
import os
|
4 |
import json
|
5 |
|
6 |
-
api_key=os.environ.get('qwen_API_KEY')
|
7 |
"""
|
8 |
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
|
9 |
"""
|
10 |
-
client = InferenceClient("Qwen/Qwen2.5-72B-Instruct",token=api_key)
|
11 |
|
12 |
def respond(
|
13 |
message,
|
@@ -29,18 +29,20 @@ def respond(
|
|
29 |
|
30 |
response = ""
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
-
response += token
|
42 |
-
yield response
|
43 |
-
|
44 |
example_prompts = [
|
45 |
["How to cook Kung Pao chicken the tastiest?"],
|
46 |
["Help me create an email expressing my greetings to an old friend."],
|
@@ -60,7 +62,6 @@ demo = gr.ChatInterface(
|
|
60 |
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
61 |
],
|
62 |
chatbot=gr.Chatbot(show_label=True, show_copy_button=True)
|
63 |
-
|
64 |
)
|
65 |
|
66 |
if __name__ == "__main__":
|
|
|
3 |
import os
|
4 |
import json
|
5 |
|
6 |
+
api_key = os.environ.get('qwen_API_KEY')
|
7 |
"""
|
8 |
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
|
9 |
"""
|
10 |
+
client = InferenceClient("Qwen/Qwen2.5-72B-Instruct", token=api_key)
|
11 |
|
12 |
def respond(
|
13 |
message,
|
|
|
29 |
|
30 |
response = ""
|
31 |
|
32 |
+
try:
|
33 |
+
async for message in client.chat_completion(
|
34 |
+
messages,
|
35 |
+
max_tokens=max_tokens,
|
36 |
+
stream=True,
|
37 |
+
temperature=temperature,
|
38 |
+
top_p=top_p
|
39 |
+
):
|
40 |
+
token = message.choices[0].delta.content
|
41 |
+
response += token
|
42 |
+
yield response
|
43 |
+
except Exception as e:
|
44 |
+
yield f"An error occurred: {e}"
|
45 |
|
|
|
|
|
|
|
46 |
example_prompts = [
|
47 |
["How to cook Kung Pao chicken the tastiest?"],
|
48 |
["Help me create an email expressing my greetings to an old friend."],
|
|
|
62 |
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
63 |
],
|
64 |
chatbot=gr.Chatbot(show_label=True, show_copy_button=True)
|
|
|
65 |
)
|
66 |
|
67 |
if __name__ == "__main__":
|