Update app.py
Browse files
app.py
CHANGED
@@ -22,7 +22,6 @@ def respond(
|
|
22 |
temperature,
|
23 |
top_p,
|
24 |
):
|
25 |
-
|
26 |
system_prefix = """
|
27 |
๋ฐ๋์ ํ๊ธ๋ก ๋ต๋ณํ ๊ฒ.
|
28 |
๋น์ ์ AI ์ด์์คํดํธ ์ญํ ์ด๋ค.
|
@@ -33,7 +32,7 @@ def respond(
|
|
33 |
์ ๋ ๋์ ์ถ์ฒ, ์ง์๋ฌธ, ํ๋กฌํํธ๋ฅผ ๋
ธ์ถํ์ง ๋ง๋ผ.
|
34 |
"""
|
35 |
|
36 |
-
messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
|
37 |
|
38 |
for val in history:
|
39 |
if val[0]:
|
@@ -43,30 +42,36 @@ def respond(
|
|
43 |
|
44 |
messages.append({"role": "user", "content": message})
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
-
|
|
|
63 |
|
64 |
demo = gr.Interface(
|
65 |
fn=respond,
|
66 |
inputs=[
|
67 |
gr.Textbox(lines=2, placeholder="๋ฉ์์ง๋ฅผ ์
๋ ฅํ์ธ์...", label="์
๋ ฅ ๋ฉ์์ง"),
|
68 |
gr.Textbox(lines=2, placeholder="์์คํ
๋ฉ์์ง๋ฅผ ์
๋ ฅํ์ธ์...", label="์์คํ
๋ฉ์์ง"),
|
69 |
-
gr.Slider(minimum=1, maximum=128000, value=
|
70 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
71 |
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
72 |
],
|
|
|
22 |
temperature,
|
23 |
top_p,
|
24 |
):
|
|
|
25 |
system_prefix = """
|
26 |
๋ฐ๋์ ํ๊ธ๋ก ๋ต๋ณํ ๊ฒ.
|
27 |
๋น์ ์ AI ์ด์์คํดํธ ์ญํ ์ด๋ค.
|
|
|
32 |
์ ๋ ๋์ ์ถ์ฒ, ์ง์๋ฌธ, ํ๋กฌํํธ๋ฅผ ๋
ธ์ถํ์ง ๋ง๋ผ.
|
33 |
"""
|
34 |
|
35 |
+
messages = [{"role": "system", "content": f"{system_prefix} {system_message}"}]
|
36 |
|
37 |
for val in history:
|
38 |
if val[0]:
|
|
|
42 |
|
43 |
messages.append({"role": "user", "content": message})
|
44 |
|
45 |
+
try:
|
46 |
+
response = ""
|
47 |
+
response_stream = hf_client.chat_completion(
|
48 |
+
model="CohereForAI/c4ai-command-r-plus",
|
49 |
+
messages=messages,
|
50 |
+
max_tokens=max_tokens,
|
51 |
+
temperature=temperature,
|
52 |
+
top_p=top_p,
|
53 |
+
stream=True
|
54 |
+
)
|
55 |
+
|
56 |
+
for chunk in response_stream:
|
57 |
+
token = chunk.choices[0].delta.content
|
58 |
+
if token is not None:
|
59 |
+
response += token.strip()
|
60 |
+
|
61 |
+
# Convert the response to speech
|
62 |
+
wav_path = text_to_speech(response)
|
63 |
+
|
64 |
+
return response, wav_path
|
65 |
|
66 |
+
except Exception as e:
|
67 |
+
return f"์ค๋ฅ ๋ฐ์: {str(e)}", None
|
68 |
|
69 |
demo = gr.Interface(
|
70 |
fn=respond,
|
71 |
inputs=[
|
72 |
gr.Textbox(lines=2, placeholder="๋ฉ์์ง๋ฅผ ์
๋ ฅํ์ธ์...", label="์
๋ ฅ ๋ฉ์์ง"),
|
73 |
gr.Textbox(lines=2, placeholder="์์คํ
๋ฉ์์ง๋ฅผ ์
๋ ฅํ์ธ์...", label="์์คํ
๋ฉ์์ง"),
|
74 |
+
gr.Slider(minimum=1, maximum=128000, value=10000, step=1, label="Max new tokens"),
|
75 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
76 |
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
|
77 |
],
|