Spaces:
Sleeping
Sleeping
Adding some UI Stuff
Browse files
app.py
CHANGED
@@ -43,21 +43,66 @@ def respond(
|
|
43 |
"""
|
44 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
45 |
"""
|
46 |
-
demo = gr.ChatInterface(
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
|
63 |
if __name__ == "__main__":
|
|
|
43 |
"""
|
44 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
45 |
"""
|
46 |
+
# demo = gr.ChatInterface(
|
47 |
+
# respond,
|
48 |
+
# additional_inputs=[
|
49 |
+
# gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
50 |
+
# gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
51 |
+
# gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
52 |
+
# gr.Slider(
|
53 |
+
# minimum=0.1,
|
54 |
+
# maximum=1.0,
|
55 |
+
# value=0.95,
|
56 |
+
# step=0.05,
|
57 |
+
# label="Top-p (nucleus sampling)",
|
58 |
+
# ),
|
59 |
+
# ],
|
60 |
+
# )
|
61 |
+
|
62 |
+
with gr.Blocks() as demo:
|
63 |
+
gr.Markdown("## Zephyr Chatbot with Custom UI")
|
64 |
+
|
65 |
+
chatbot = gr.Chatbot()
|
66 |
+
state = gr.State([])
|
67 |
+
|
68 |
+
with gr.Row():
|
69 |
+
msg = gr.Textbox(label="Type your message...", scale=6)
|
70 |
+
send_btn = gr.Button("Send", scale=1)
|
71 |
+
|
72 |
+
role_dropdown = gr.Dropdown(choices=["SDE", "BA"], label="Select Role", value="SDE")
|
73 |
+
|
74 |
+
system = gr.Textbox(value="You are a friendly chatbot.", label="System message")
|
75 |
+
max_tokens = gr.Slider(1, 2048, value=512, label="Max tokens")
|
76 |
+
temperature = gr.Slider(0.1, 4.0, value=0.7, label="Temperature", step=0.1)
|
77 |
+
top_p = gr.Slider(0.1, 1.0, value=0.95, label="Top-p", step=0.05)
|
78 |
+
|
79 |
+
with gr.Row():
|
80 |
+
clear_btn = gr.Button("Clear Chat")
|
81 |
+
dummy_btn = gr.Button("Dummy Action")
|
82 |
+
|
83 |
+
def handle_submit(message, history, system, max_tokens, temperature, top_p):
|
84 |
+
response_gen = response(message, history, system, max_tokens, temperature, top_p)
|
85 |
+
final_response = ""
|
86 |
+
for r in response_gen:
|
87 |
+
final_response = r
|
88 |
+
updated_history = history + [(message, final_response)]
|
89 |
+
return updated_history, updated_history, ""
|
90 |
+
|
91 |
+
send_btn.click(
|
92 |
+
handle_submit,
|
93 |
+
[msg, state, system, max_tokens, temperature, top_p],
|
94 |
+
[chatbot, state, msg],
|
95 |
+
)
|
96 |
+
|
97 |
+
msg.submit(
|
98 |
+
handle_submit,
|
99 |
+
[msg, state, system, max_tokens, temperature, top_p],
|
100 |
+
[chatbot, state, msg],
|
101 |
+
)
|
102 |
+
|
103 |
+
clear_btn.click(lambda: ([], [], ""), None, [chatbot, state, msg])
|
104 |
+
|
105 |
+
dummy_btn.click(lambda: gr.Info("Dummy action clicked!"), None, None)
|
106 |
|
107 |
|
108 |
if __name__ == "__main__":
|