seawolf2357
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,3 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import aiohttp
|
3 |
-
import os
|
4 |
-
import json
|
5 |
-
from collections import deque
|
6 |
-
|
7 |
-
TOKEN = os.getenv("HUGGINGFACE_API_TOKEN")
|
8 |
-
|
9 |
-
if not TOKEN:
|
10 |
-
raise ValueError("API token is not set. Please set the HUGGINGFACE_API_TOKEN environment variable.")
|
11 |
-
|
12 |
-
memory = deque(maxlen=10)
|
13 |
-
|
14 |
async def respond(
|
15 |
message,
|
16 |
history: list[tuple[str, str]],
|
@@ -54,27 +41,11 @@ async def respond(
|
|
54 |
content = response_json["choices"][0]["message"]["content"]
|
55 |
yield content
|
56 |
except json.JSONDecodeError:
|
57 |
-
# Log the error or handle it appropriately
|
58 |
pass
|
59 |
except StopAsyncIteration:
|
60 |
-
# Handle the case where the stream is prematurely terminated
|
61 |
pass
|
62 |
finally:
|
63 |
-
#
|
64 |
-
yield "Stream ended"
|
65 |
-
|
66 |
-
theme = "Nymbo/Nymbo_Theme"
|
67 |
-
|
68 |
-
demo = gr.ChatInterface(
|
69 |
-
fn=respond,
|
70 |
-
theme=theme,
|
71 |
-
additional_inputs=[
|
72 |
-
gr.Textbox(value="AI Assistant Role", label="System message"),
|
73 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
74 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
75 |
-
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
76 |
-
]
|
77 |
-
)
|
78 |
|
79 |
if __name__ == "__main__":
|
80 |
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
async def respond(
|
2 |
message,
|
3 |
history: list[tuple[str, str]],
|
|
|
41 |
content = response_json["choices"][0]["message"]["content"]
|
42 |
yield content
|
43 |
except json.JSONDecodeError:
|
|
|
44 |
pass
|
45 |
except StopAsyncIteration:
|
|
|
46 |
pass
|
47 |
finally:
|
48 |
+
pass # 스트림 종료 시 아무것도 하지 않음
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
if __name__ == "__main__":
|
51 |
demo.launch()
|