Spaces:
Running
Running
Update app.py
Browse files
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
|
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__":
|