Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,53 +1,20 @@
|
|
1 |
import gradio as gr
|
2 |
-
from huggingface_hub import InferenceClient
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
def respond(
|
7 |
-
message,
|
8 |
-
history,
|
9 |
-
system_message,
|
10 |
-
max_tokens,
|
11 |
-
temperature,
|
12 |
-
top_p,
|
13 |
-
):
|
14 |
-
messages = [{"role": "system", "content": system_message}]
|
15 |
-
|
16 |
-
for val in history:
|
17 |
-
if val[0]:
|
18 |
-
messages.append({"role": "user", "content": val[0]})
|
19 |
if val[1]:
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
for message in client.chat_completion(
|
27 |
-
messages,
|
28 |
-
max_tokens=max_tokens,
|
29 |
-
stream=True,
|
30 |
-
temperature=temperature,
|
31 |
-
top_p=top_p,
|
32 |
-
):
|
33 |
-
token = message.choices[0].delta.content
|
34 |
-
|
35 |
-
response += token
|
36 |
-
yield response
|
37 |
|
38 |
demo = gr.Interface(
|
39 |
fn=respond,
|
40 |
-
inputs=
|
41 |
-
gr.Textbox(label="λ©μμ§"),
|
42 |
-
gr.Textbox(label="μμ€ν
λ©μμ§"),
|
43 |
-
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="μ΅λ μλ‘μ΄ ν ν°"),
|
44 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="μ¨λ"),
|
45 |
-
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (Nucleus Sampling)"),
|
46 |
-
],
|
47 |
outputs="text",
|
48 |
-
title="
|
49 |
-
description="
|
50 |
)
|
51 |
|
52 |
-
|
53 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
+
def respond(val):
|
4 |
+
if len(val) > 1:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
if val[1]:
|
6 |
+
# do something
|
7 |
+
pass
|
8 |
+
else:
|
9 |
+
# handle the case where val has only one element
|
10 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
demo = gr.Interface(
|
13 |
fn=respond,
|
14 |
+
inputs="text",
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
outputs="text",
|
16 |
+
title="My App",
|
17 |
+
description="This is my app"
|
18 |
)
|
19 |
|
20 |
+
demo.launch()
|
|