andreska commited on
Commit
348670d
·
verified ·
1 Parent(s): 3a61d2f

Try to fix streaming

Browse files
Files changed (1) hide show
  1. app.py +12 -17
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
- response_generator = client.text_generation(
16
- prompt,
17
- max_new_tokens=512,
18
- temperature=0.7,
19
- top_p=0.95,
20
- repetition_penalty=1.1,
21
- do_sample=True,
22
  stream=True
23
  )
24
 
25
- response_text = ""
26
- for token in response_generator:
27
- response_text += token.text
28
- yield response_text
 
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)}")