seawolf2357 commited on
Commit
77ed574
ยท
verified ยท
1 Parent(s): 3e050a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -53,6 +53,7 @@ def respond(
53
 
54
  response = requests.post("https://api-inference.huggingface.co/v1/chat/completions", headers=headers, json=payload, stream=True)
55
 
 
56
  response_text = ""
57
  for chunk in response.iter_content(chunk_size=None):
58
  if chunk:
@@ -62,10 +63,8 @@ def respond(
62
  # content ์˜์—ญ๋งŒ ์ถœ๋ ฅ
63
  if "choices" in response_json:
64
  content = response_json["choices"][0]["message"]["content"]
65
- response_text = content
66
- # ๋งˆ์ง€๋ง‰ ๋Œ€ํ™”์— ๋ชจ๋ธ์˜ ์‘๋‹ต์„ ์ถ”๊ฐ€ํ•˜์—ฌ ๋ฉ”๋ชจ๋ฆฌ์— ์ €์žฅ
67
- memory[-1] = (message, response_text)
68
- yield content
69
  except json.JSONDecodeError:
70
  continue # ์œ ํšจํ•˜์ง€ ์•Š์€ JSON์ด ์žˆ์„ ๊ฒฝ์šฐ ๋ฌด์‹œํ•˜๊ณ  ๋‹ค์Œ ์ฒญํฌ๋กœ ๋„˜์–ด๊ฐ
71
 
@@ -81,6 +80,7 @@ demo = gr.ChatInterface(
81
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
82
  gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
83
  ],
 
84
  )
85
 
86
  if __name__ == "__main__":
 
53
 
54
  response = requests.post("https://api-inference.huggingface.co/v1/chat/completions", headers=headers, json=payload, stream=True)
55
 
56
+ # Stream ๋ฐฉ์‹์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ถœ๋ ฅ
57
  response_text = ""
58
  for chunk in response.iter_content(chunk_size=None):
59
  if chunk:
 
63
  # content ์˜์—ญ๋งŒ ์ถœ๋ ฅ
64
  if "choices" in response_json:
65
  content = response_json["choices"][0]["message"]["content"]
66
+ response_text += content
67
+ yield response_text # ๋ˆ„์ ๋œ ์‘๋‹ต์„ ์ŠคํŠธ๋ฆผ ๋ฐฉ์‹์œผ๋กœ ๋ฐ˜ํ™˜
 
 
68
  except json.JSONDecodeError:
69
  continue # ์œ ํšจํ•˜์ง€ ์•Š์€ JSON์ด ์žˆ์„ ๊ฒฝ์šฐ ๋ฌด์‹œํ•˜๊ณ  ๋‹ค์Œ ์ฒญํฌ๋กœ ๋„˜์–ด๊ฐ
70
 
 
80
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
81
  gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
82
  ],
83
+ streaming=True # ์ŠคํŠธ๋ฆฌ๋ฐ ๋ชจ๋“œ ํ™œ์„ฑํ™”
84
  )
85
 
86
  if __name__ == "__main__":