Spaces:
Sleeping
Sleeping
Try to fix streaming
Browse files
app.py
CHANGED
|
@@ -2,30 +2,25 @@ import os
|
|
| 2 |
import gradio as gr
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
|
|
|
|
|
|
|
|
|
|
| 5 |
def analyze(project_data, question):
|
| 6 |
try:
|
| 7 |
-
api_key = os.getenv("HF_API_KEY")
|
| 8 |
-
client = InferenceClient(
|
| 9 |
-
model="Qwen/Qwen2.5-72B-Instruct",
|
| 10 |
-
token=api_key
|
| 11 |
-
)
|
| 12 |
-
|
| 13 |
prompt = f"Analyze this project: {project_data}\n\nQuestion: {question}"
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
top_p=0.95,
|
| 20 |
-
repetition_penalty=1.1,
|
| 21 |
-
do_sample=True,
|
| 22 |
stream=True
|
| 23 |
)
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
except Exception as e:
|
| 31 |
print(f"Error details: {str(e)}")
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from huggingface_hub import InferenceClient
|
| 4 |
|
| 5 |
+
api_key = os.getenv("HF_API_KEY")
|
| 6 |
+
client = InferenceClient(api_key=api_key)
|
| 7 |
+
|
| 8 |
def analyze(project_data, question):
|
| 9 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
prompt = f"Analyze this project: {project_data}\n\nQuestion: {question}"
|
| 11 |
|
| 12 |
+
response = client.chat.completions.create(
|
| 13 |
+
model="Qwen/Qwen2.5-72B-Instruct",
|
| 14 |
+
messages=messages,
|
| 15 |
+
max_tokens=1000,
|
|
|
|
|
|
|
|
|
|
| 16 |
stream=True
|
| 17 |
)
|
| 18 |
|
| 19 |
+
answer = ""
|
| 20 |
+
|
| 21 |
+
for chunk in response:
|
| 22 |
+
answer += chunk['choices'][0]['delta']['content']
|
| 23 |
+
yield answer
|
| 24 |
|
| 25 |
except Exception as e:
|
| 26 |
print(f"Error details: {str(e)}")
|