Update app.py
Browse files
app.py
CHANGED
@@ -87,12 +87,21 @@ def chatbot(input_text, image, audio, openai_api_key, reasoning_effort, model_ch
|
|
87 |
# Append the response to the history
|
88 |
history.append((f"User: {input_text}", f"Assistant: {response}"))
|
89 |
|
90 |
-
return "", history
|
91 |
|
92 |
# Function to clear the chat history
|
93 |
def clear_history():
|
94 |
-
return "", []
|
95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
# Custom CSS styles with animations and button colors
|
97 |
custom_css = """
|
98 |
/* General body styles */
|
@@ -180,6 +189,29 @@ custom_css = """
|
|
180 |
#clear-history:active {
|
181 |
transform: scale(0.95);
|
182 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
/* Chat history styles */
|
184 |
.gradio-chatbot .message {
|
185 |
margin-bottom: 10px;
|
@@ -266,10 +298,37 @@ def create_interface():
|
|
266 |
with gr.Row():
|
267 |
openai_api_key = gr.Textbox(label="Enter OpenAI API Key", type="password", placeholder="sk-...", interactive=True)
|
268 |
|
|
|
269 |
with gr.Row():
|
270 |
-
|
271 |
-
|
272 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
273 |
|
274 |
with gr.Row():
|
275 |
reasoning_effort = gr.Dropdown(
|
@@ -287,9 +346,25 @@ def create_interface():
|
|
287 |
|
288 |
chat_history = gr.Chatbot()
|
289 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
# Button interactions
|
291 |
-
submit_btn.click(
|
292 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
293 |
|
294 |
return demo
|
295 |
|
|
|
87 |
# Append the response to the history
|
88 |
history.append((f"User: {input_text}", f"Assistant: {response}"))
|
89 |
|
90 |
+
return "", None, None, history
|
91 |
|
92 |
# Function to clear the chat history
|
93 |
def clear_history():
|
94 |
+
return "", None, None, []
|
95 |
|
96 |
+
# Function to update visible components based on input type selection
|
97 |
+
def update_input_type(choice):
|
98 |
+
if choice == "Text":
|
99 |
+
return gr.update(visible=True), gr.update(visible=False), gr.update(visible=False)
|
100 |
+
elif choice == "Image":
|
101 |
+
return gr.update(visible=True), gr.update(visible=True), gr.update(visible=False)
|
102 |
+
elif choice == "Voice":
|
103 |
+
return gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)
|
104 |
+
|
105 |
# Custom CSS styles with animations and button colors
|
106 |
custom_css = """
|
107 |
/* General body styles */
|
|
|
189 |
#clear-history:active {
|
190 |
transform: scale(0.95);
|
191 |
}
|
192 |
+
/* Input type selector buttons */
|
193 |
+
#input-type-group {
|
194 |
+
display: flex;
|
195 |
+
justify-content: center;
|
196 |
+
gap: 10px;
|
197 |
+
margin-bottom: 20px;
|
198 |
+
}
|
199 |
+
.input-type-btn {
|
200 |
+
background-color: #6c757d;
|
201 |
+
color: white;
|
202 |
+
border: none;
|
203 |
+
border-radius: 8px;
|
204 |
+
padding: 10px 15px;
|
205 |
+
font-size: 1rem;
|
206 |
+
cursor: pointer;
|
207 |
+
transition: all 0.3s ease;
|
208 |
+
}
|
209 |
+
.input-type-btn.selected {
|
210 |
+
background-color: #007bff;
|
211 |
+
}
|
212 |
+
.input-type-btn:hover {
|
213 |
+
background-color: #5a6268;
|
214 |
+
}
|
215 |
/* Chat history styles */
|
216 |
.gradio-chatbot .message {
|
217 |
margin-bottom: 10px;
|
|
|
298 |
with gr.Row():
|
299 |
openai_api_key = gr.Textbox(label="Enter OpenAI API Key", type="password", placeholder="sk-...", interactive=True)
|
300 |
|
301 |
+
# Input type selector
|
302 |
with gr.Row():
|
303 |
+
input_type = gr.Radio(
|
304 |
+
["Text", "Image", "Voice"],
|
305 |
+
label="Choose Input Type",
|
306 |
+
value="Text"
|
307 |
+
)
|
308 |
+
|
309 |
+
# Create the input components (initially text is visible, others are hidden)
|
310 |
+
with gr.Row():
|
311 |
+
# Text input
|
312 |
+
input_text = gr.Textbox(
|
313 |
+
label="Enter Text Question",
|
314 |
+
placeholder="Ask a question or provide text",
|
315 |
+
lines=2,
|
316 |
+
visible=True
|
317 |
+
)
|
318 |
+
|
319 |
+
# Image input
|
320 |
+
image_input = gr.Image(
|
321 |
+
label="Upload an Image",
|
322 |
+
type="pil",
|
323 |
+
visible=False
|
324 |
+
)
|
325 |
+
|
326 |
+
# Audio input
|
327 |
+
audio_input = gr.Audio(
|
328 |
+
label="Upload or Record Audio",
|
329 |
+
type="filepath",
|
330 |
+
visible=False
|
331 |
+
)
|
332 |
|
333 |
with gr.Row():
|
334 |
reasoning_effort = gr.Dropdown(
|
|
|
346 |
|
347 |
chat_history = gr.Chatbot()
|
348 |
|
349 |
+
# Connect the input type selector to the update function
|
350 |
+
input_type.change(
|
351 |
+
fn=update_input_type,
|
352 |
+
inputs=[input_type],
|
353 |
+
outputs=[input_text, image_input, audio_input]
|
354 |
+
)
|
355 |
+
|
356 |
# Button interactions
|
357 |
+
submit_btn.click(
|
358 |
+
fn=chatbot,
|
359 |
+
inputs=[input_text, image_input, audio_input, openai_api_key, reasoning_effort, model_choice, chat_history],
|
360 |
+
outputs=[input_text, image_input, audio_input, chat_history]
|
361 |
+
)
|
362 |
+
|
363 |
+
clear_btn.click(
|
364 |
+
fn=clear_history,
|
365 |
+
inputs=[],
|
366 |
+
outputs=[input_text, image_input, audio_input, chat_history]
|
367 |
+
)
|
368 |
|
369 |
return demo
|
370 |
|