Spaces:
Sleeping
Sleeping
Commit
·
83eaee2
1
Parent(s):
0298a9f
test
Browse files
app.py
CHANGED
@@ -1,64 +1,27 @@
|
|
1 |
-
|
2 |
-
from huggingface_hub import InferenceClient
|
3 |
-
|
4 |
-
"""
|
5 |
-
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
6 |
-
"""
|
7 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
8 |
-
|
9 |
-
|
10 |
-
def respond(
|
11 |
-
message,
|
12 |
-
history: list[tuple[str, str]],
|
13 |
-
system_message,
|
14 |
-
max_tokens,
|
15 |
-
temperature,
|
16 |
-
top_p,
|
17 |
-
):
|
18 |
-
messages = [{"role": "system", "content": system_message}]
|
19 |
-
|
20 |
-
for val in history:
|
21 |
-
if val[0]:
|
22 |
-
messages.append({"role": "user", "content": val[0]})
|
23 |
-
if val[1]:
|
24 |
-
messages.append({"role": "assistant", "content": val[1]})
|
25 |
-
|
26 |
-
messages.append({"role": "user", "content": message})
|
27 |
-
|
28 |
-
response = ""
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
""
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
gr.
|
50 |
-
gr.
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
value=0.95,
|
56 |
-
step=0.05,
|
57 |
-
label="Top-p (nucleus sampling)",
|
58 |
-
),
|
59 |
-
],
|
60 |
-
)
|
61 |
-
|
62 |
-
|
63 |
-
if __name__ == "__main__":
|
64 |
-
demo.launch()
|
|
|
1 |
+
# !pip install gradio
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
import gradio as gr
|
4 |
+
from typing import List, Tuple
|
5 |
+
import numpy as np
|
6 |
+
|
7 |
+
def reset() -> List:
|
8 |
+
return []
|
9 |
+
|
10 |
+
def interact(chatbot: List[Tuple[str, str]], user_input: str) -> List[Tuple[str, str]]:
|
11 |
+
responses = ["You are right", "HaHa", "I don't know"]
|
12 |
+
response = np.random.choice(responses, 1)[0]
|
13 |
+
chatbot.append((user_input, response))
|
14 |
+
|
15 |
+
return chatbot
|
16 |
+
|
17 |
+
with gr.Blocks() as demo:
|
18 |
+
gr.Markdown(f"# Gradio Tutorial")
|
19 |
+
chatbot = gr.Chatbot()
|
20 |
+
input_textbox = gr.Textbox(label="Input", value = "")
|
21 |
+
with gr.Row():
|
22 |
+
sent_button = gr.Button(value="Send")
|
23 |
+
reset_button = gr.Button(value="Reset")
|
24 |
+
sent_button.click(interact, inputs=[chatbot, input_textbox], outputs=[chatbot])
|
25 |
+
reset_button.click(reset, outputs=[chatbot])
|
26 |
+
|
27 |
+
demo.launch(debug = True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|