Spaces:
Sleeping
Sleeping
Add hint to user prompt
Browse files- Gradio_UI.py +82 -29
Gradio_UI.py
CHANGED
|
@@ -258,37 +258,90 @@ class GradioUI:
|
|
| 258 |
"",
|
| 259 |
)
|
| 260 |
|
| 261 |
-
def launch(self, **kwargs):
|
| 262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
"https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/communication/Alfred.png",
|
| 273 |
-
),
|
| 274 |
-
resizeable=True,
|
| 275 |
-
scale=1,
|
| 276 |
)
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
[upload_status, file_uploads_log],
|
| 285 |
-
)
|
| 286 |
-
text_input = gr.Textbox(lines=1, label="Chat Message")
|
| 287 |
-
text_input.submit(
|
| 288 |
-
self.log_user_message,
|
| 289 |
-
[text_input, file_uploads_log],
|
| 290 |
-
[stored_messages, text_input],
|
| 291 |
-
).then(self.interact_with_agent, [stored_messages, chatbot], [chatbot])
|
| 292 |
|
| 293 |
demo.launch(debug=True, share=True, **kwargs)
|
| 294 |
|
|
|
|
| 258 |
"",
|
| 259 |
)
|
| 260 |
|
| 261 |
+
# def launch(self, **kwargs):
|
| 262 |
+
# import gradio as gr
|
| 263 |
+
|
| 264 |
+
# with gr.Blocks(fill_height=True) as demo:
|
| 265 |
+
# stored_messages = gr.State([])
|
| 266 |
+
# file_uploads_log = gr.State([])
|
| 267 |
+
# chatbot = gr.Chatbot(
|
| 268 |
+
# label="Agent",
|
| 269 |
+
# type="messages",
|
| 270 |
+
# avatar_images=(
|
| 271 |
+
# None,
|
| 272 |
+
# "https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/communication/Alfred.png",
|
| 273 |
+
# ),
|
| 274 |
+
# resizeable=True,
|
| 275 |
+
# scale=1,
|
| 276 |
+
# )
|
| 277 |
+
# # If an upload folder is provided, enable the upload feature
|
| 278 |
+
# if self.file_upload_folder is not None:
|
| 279 |
+
# upload_file = gr.File(label="Upload a file")
|
| 280 |
+
# upload_status = gr.Textbox(label="Upload Status", interactive=False, visible=False)
|
| 281 |
+
# upload_file.change(
|
| 282 |
+
# self.upload_file,
|
| 283 |
+
# [upload_file, file_uploads_log],
|
| 284 |
+
# [upload_status, file_uploads_log],
|
| 285 |
+
# )
|
| 286 |
+
# text_input = gr.Textbox(lines=1, label="Chat Message")
|
| 287 |
+
# text_input.submit(
|
| 288 |
+
# self.log_user_message,
|
| 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 |
|