Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
def greet(name):
|
4 |
+
return "Hello " + name + "!!"
|
5 |
+
|
6 |
+
from huggingface_hub import InferenceClient
|
7 |
+
|
8 |
+
client = InferenceClient(api_key="hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
|
9 |
+
|
10 |
+
messages = [
|
11 |
+
{
|
12 |
+
"role": "user",
|
13 |
+
"content": "What is the capital of France?"
|
14 |
+
}
|
15 |
+
]
|
16 |
+
|
17 |
+
stream = client.chat.completions.create(
|
18 |
+
model="Qwen/Qwen2.5-Math-7B-Instruct",
|
19 |
+
messages=messages,
|
20 |
+
max_tokens=500,
|
21 |
+
stream=True
|
22 |
+
)
|
23 |
+
|
24 |
+
for chunk in stream:
|
25 |
+
print(chunk.choices[0].delta.content, end="")
|
26 |
+
|
27 |
+
|
28 |
+
|
29 |
+
|
30 |
+
demo = gr.Interface(fn=greet, inputs="text", outputs="text")
|
31 |
+
demo.launch()
|