Spaces:
Running
Running
seawolf2357
commited on
Commit
โข
f18ba88
1
Parent(s):
1f29b82
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,21 @@
|
|
1 |
-
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
import os
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
|
9 |
-
TOKEN = os.getenv("HUGGINGFACE_API_TOKEN_V")
|
10 |
|
11 |
-
#
|
12 |
if not TOKEN:
|
13 |
raise ValueError("API token is not set. Please set the HUGGINGFACE_API_TOKEN environment variable.")
|
14 |
|
15 |
-
|
16 |
def respond(
|
17 |
message,
|
18 |
history: list[tuple[str, str]],
|
19 |
-
system_message,
|
20 |
-
max_tokens,
|
21 |
-
temperature,
|
22 |
-
top_p,
|
23 |
):
|
24 |
messages = [{"role": "system", "content": system_message}]
|
25 |
|
@@ -49,8 +45,12 @@ def respond(
|
|
49 |
response_text = ""
|
50 |
for chunk in response.iter_content(chunk_size=None):
|
51 |
if chunk:
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
54 |
|
55 |
theme="Nymbo/Nymbo_Theme"
|
56 |
|
@@ -58,7 +58,7 @@ demo = gr.ChatInterface(
|
|
58 |
respond,
|
59 |
theme=theme,
|
60 |
additional_inputs=[
|
61 |
-
gr.Textbox(value="
|
62 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
63 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
64 |
gr.Slider(
|
@@ -72,4 +72,4 @@ demo = gr.ChatInterface(
|
|
72 |
)
|
73 |
|
74 |
if __name__ == "__main__":
|
75 |
-
demo.launch()
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
import os
|
4 |
|
5 |
+
# ํ๊ฒฝ ๋ณ์์์ API ํ ํฐ ๊ฐ์ ธ์ค๊ธฐ
|
6 |
+
TOKEN = os.getenv("HUGGINGFACE_API_TOKEN")
|
|
|
|
|
7 |
|
8 |
+
# API ํ ํฐ์ด ์ค์ ๋์ด ์๋์ง ํ์ธ
|
9 |
if not TOKEN:
|
10 |
raise ValueError("API token is not set. Please set the HUGGINGFACE_API_TOKEN environment variable.")
|
11 |
|
|
|
12 |
def respond(
|
13 |
message,
|
14 |
history: list[tuple[str, str]],
|
15 |
+
system_message="๋์ ์ด๋ฆ์ ํ๊ธธ๋์ด๋ค",
|
16 |
+
max_tokens=512,
|
17 |
+
temperature=0.7,
|
18 |
+
top_p=0.95,
|
19 |
):
|
20 |
messages = [{"role": "system", "content": system_message}]
|
21 |
|
|
|
45 |
response_text = ""
|
46 |
for chunk in response.iter_content(chunk_size=None):
|
47 |
if chunk:
|
48 |
+
chunk_data = chunk.decode('utf-8')
|
49 |
+
response_json = json.loads(chunk_data)
|
50 |
+
# content ์์ญ๋ง ์ถ๋ ฅ
|
51 |
+
if "choices" in response_json:
|
52 |
+
content = response_json["choices"][0]["message"]["content"]
|
53 |
+
yield content
|
54 |
|
55 |
theme="Nymbo/Nymbo_Theme"
|
56 |
|
|
|
58 |
respond,
|
59 |
theme=theme,
|
60 |
additional_inputs=[
|
61 |
+
gr.Textbox(value="๋์ ์ด๋ฆ์ ํ๊ธธ๋์ด๋ค", label="System message"),
|
62 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
63 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
64 |
gr.Slider(
|
|
|
72 |
)
|
73 |
|
74 |
if __name__ == "__main__":
|
75 |
+
demo.launch()
|