Spaces:
Running
Running
Update Gradio_UI.py
Browse files- Gradio_UI.py +53 -53
Gradio_UI.py
CHANGED
@@ -289,60 +289,60 @@ class GradioUI:
|
|
289 |
# [text_input, file_uploads_log],
|
290 |
# [stored_messages, text_input],
|
291 |
# ).then(self.interact_with_agent, [stored_messages, chatbot], [chatbot])
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
chatbot = gr.Chatbot(
|
300 |
-
label="Agent",
|
301 |
-
type="messages",
|
302 |
-
avatar_images=(
|
303 |
-
None,
|
304 |
-
"https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/communication/Alfred.png",
|
305 |
-
),
|
306 |
-
resizeable=True,
|
307 |
-
scale=1,
|
308 |
-
)
|
309 |
-
|
310 |
-
# Show temporary hint when chat loads
|
311 |
-
demo.load(
|
312 |
-
lambda: [{"role": "assistant", "content": "Draw me...", "temp_hint": True}],
|
313 |
-
inputs=None,
|
314 |
-
outputs=chatbot,
|
315 |
-
)
|
316 |
-
|
317 |
-
# When any message is added, clear the temporary hint
|
318 |
-
def update_chat_display(messages):
|
319 |
-
if messages and isinstance(messages[-1], dict) and messages[-1].get("temp_hint"):
|
320 |
-
return []
|
321 |
-
return messages
|
322 |
-
|
323 |
-
chatbot.change(
|
324 |
-
update_chat_display,
|
325 |
-
stored_messages,
|
326 |
-
chatbot,
|
327 |
-
)
|
328 |
-
|
329 |
-
# Rest of your existing code
|
330 |
-
if self.file_upload_folder is not None:
|
331 |
-
upload_file = gr.File(label="Upload a file")
|
332 |
-
upload_status = gr.Textbox(label="Upload Status", interactive=False, visible=False)
|
333 |
-
upload_file.change(
|
334 |
-
self.upload_file,
|
335 |
-
[upload_file, file_uploads_log],
|
336 |
-
[upload_status, file_uploads_log],
|
337 |
-
)
|
338 |
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
346 |
demo.launch(debug=True, share=True, **kwargs)
|
347 |
|
348 |
|
|
|
289 |
# [text_input, file_uploads_log],
|
290 |
# [stored_messages, text_input],
|
291 |
# ).then(self.interact_with_agent, [stored_messages, chatbot], [chatbot])
|
292 |
+
def launch(self, **kwargs):
|
293 |
+
import gradio as gr
|
294 |
+
|
295 |
+
with gr.Blocks(fill_height=True) as demo:
|
296 |
+
stored_messages = gr.State([])
|
297 |
+
file_uploads_log = gr.State([])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
298 |
|
299 |
+
chatbot = gr.Chatbot(
|
300 |
+
label="Agent",
|
301 |
+
type="messages",
|
302 |
+
avatar_images=(
|
303 |
+
None,
|
304 |
+
"https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/communication/Alfred.png",
|
305 |
+
),
|
306 |
+
resizeable=True,
|
307 |
+
scale=1,
|
308 |
+
)
|
309 |
+
|
310 |
+
# Show temporary hint when chat loads
|
311 |
+
demo.load(
|
312 |
+
lambda: [{"role": "assistant", "content": "Draw me...", "temp_hint": True}],
|
313 |
+
inputs=None,
|
314 |
+
outputs=chatbot,
|
315 |
+
)
|
316 |
+
|
317 |
+
# When any message is added, clear the temporary hint
|
318 |
+
def update_chat_display(messages):
|
319 |
+
if messages and isinstance(messages[-1], dict) and messages[-1].get("temp_hint"):
|
320 |
+
return []
|
321 |
+
return messages
|
322 |
+
|
323 |
+
chatbot.change(
|
324 |
+
update_chat_display,
|
325 |
+
stored_messages,
|
326 |
+
chatbot,
|
327 |
+
)
|
328 |
+
|
329 |
+
# Rest of your existing code
|
330 |
+
if self.file_upload_folder is not None:
|
331 |
+
upload_file = gr.File(label="Upload a file")
|
332 |
+
upload_status = gr.Textbox(label="Upload Status", interactive=False, visible=False)
|
333 |
+
upload_file.change(
|
334 |
+
self.upload_file,
|
335 |
+
[upload_file, file_uploads_log],
|
336 |
+
[upload_status, file_uploads_log],
|
337 |
+
)
|
338 |
+
|
339 |
+
text_input = gr.Textbox(lines=1, label="Chat Message", placeholder="Type 'Draw me...' to get started")
|
340 |
+
text_input.submit(
|
341 |
+
self.log_user_message,
|
342 |
+
[text_input, file_uploads_log],
|
343 |
+
[stored_messages, text_input],
|
344 |
+
).then(self.interact_with_agent, stored_messages, chatbot)
|
345 |
+
|
346 |
demo.launch(debug=True, share=True, **kwargs)
|
347 |
|
348 |
|