Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,19 +2,22 @@ import gradio as gr
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
client = InferenceClient("
|
| 6 |
|
| 7 |
def chat_fn(message, history):
|
| 8 |
try:
|
| 9 |
response = ""
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
| 14 |
except Exception as e:
|
| 15 |
yield f"❌ Erreur Technique: {str(e)}"
|
| 16 |
|
| 17 |
-
demo = gr.ChatInterface(fn=chat_fn, title="Test Connection")
|
| 18 |
|
| 19 |
if __name__ == "__main__":
|
| 20 |
demo.launch()
|
|
|
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
client = InferenceClient("Qwen/Qwen2.5-7B-Instruct", token=os.getenv("SecretToken"))
|
| 6 |
|
| 7 |
def chat_fn(message, history):
|
| 8 |
try:
|
| 9 |
response = ""
|
| 10 |
+
messages = [{"role": "user", "content": message}]
|
| 11 |
+
|
| 12 |
+
for msg in client.chat_completion(messages, max_tokens=512, stream=True):
|
| 13 |
+
token = msg.choices[0].delta.content
|
| 14 |
+
if token:
|
| 15 |
+
response += token
|
| 16 |
+
yield response
|
| 17 |
except Exception as e:
|
| 18 |
yield f"❌ Erreur Technique: {str(e)}"
|
| 19 |
|
| 20 |
+
demo = gr.ChatInterface(fn=chat_fn, title="Test Connection - Qwen 2.5")
|
| 21 |
|
| 22 |
if __name__ == "__main__":
|
| 23 |
demo.launch()
|