Spaces:
Runtime error
Runtime error
Threatthriver
commited on
Commit
•
1c9a4c1
1
Parent(s):
c51870d
Update app.py
Browse files
app.py
CHANGED
@@ -73,46 +73,47 @@ def show_updates_and_respond(history, system_message, max_tokens, temperature, t
|
|
73 |
model_name=model_name,
|
74 |
)
|
75 |
|
76 |
-
# Define the Gradio interface
|
77 |
with gr.Blocks(css=".gradio-container {border: none;}") as demo:
|
78 |
chat_history = gr.State([]) # Initialize an empty chat history state
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
105 |
)
|
106 |
|
107 |
# Add the "Show Updates" button and output area
|
108 |
-
|
109 |
-
updates_button = gr.Button("Show Latest Updates")
|
110 |
|
111 |
-
# Define the button's click event (now inside the Blocks context)
|
112 |
updates_button.click(
|
113 |
fn=show_updates_and_respond,
|
114 |
-
inputs=[chat_history,
|
115 |
-
outputs=
|
116 |
)
|
117 |
|
118 |
# Launch the Gradio interface in full screen
|
|
|
73 |
model_name=model_name,
|
74 |
)
|
75 |
|
76 |
+
# Define the Gradio interface
|
77 |
with gr.Blocks(css=".gradio-container {border: none;}") as demo:
|
78 |
chat_history = gr.State([]) # Initialize an empty chat history state
|
79 |
+
system_message = gr.Textbox(
|
80 |
+
value="You are a friendly and helpful assistant.",
|
81 |
+
label="System message",
|
82 |
+
lines=2
|
83 |
+
)
|
84 |
+
max_tokens_slider = gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens")
|
85 |
+
temperature_slider = gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="Temperature")
|
86 |
+
top_p_slider = gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)")
|
87 |
+
model_dropdown = gr.Dropdown(
|
88 |
+
choices=list(available_models.keys()),
|
89 |
+
value="Zephyr 7B Beta",
|
90 |
+
label="Select Model",
|
91 |
+
)
|
92 |
+
|
93 |
+
chatbot = gr.Chatbot()
|
94 |
+
|
95 |
+
def user_interaction(message, history, system_message, max_tokens, temperature, top_p, model_name):
|
96 |
+
history = history or []
|
97 |
+
history.append(("User", message))
|
98 |
+
bot_response = next(respond(message, history, system_message, max_tokens, temperature, top_p, model_name))
|
99 |
+
history.append(("Assistant", bot_response))
|
100 |
+
return history, history
|
101 |
+
|
102 |
+
message_input = gr.Textbox(label="Your message")
|
103 |
+
|
104 |
+
message_input.submit(
|
105 |
+
fn=user_interaction,
|
106 |
+
inputs=[message_input, chat_history, system_message, max_tokens_slider, temperature_slider, top_p_slider, model_dropdown],
|
107 |
+
outputs=[chatbot, chat_history],
|
108 |
)
|
109 |
|
110 |
# Add the "Show Updates" button and output area
|
111 |
+
updates_button = gr.Button("Show Latest Updates")
|
|
|
112 |
|
|
|
113 |
updates_button.click(
|
114 |
fn=show_updates_and_respond,
|
115 |
+
inputs=[chat_history, system_message, max_tokens_slider, temperature_slider, top_p_slider, model_dropdown],
|
116 |
+
outputs=[chatbot],
|
117 |
)
|
118 |
|
119 |
# Launch the Gradio interface in full screen
|