Spaces:
Sleeping
Sleeping
Indent 2
Browse files- Gradio_UI.py +42 -42
Gradio_UI.py
CHANGED
|
@@ -266,49 +266,49 @@ class GradioUI:
|
|
| 266 |
)
|
| 267 |
|
| 268 |
def launch(self, **kwargs):
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
)
|
| 286 |
-
|
| 287 |
-
# Composant image dédié
|
| 288 |
-
image_output = gr.Image(label="Dernière image générée", visible=True)
|
| 289 |
-
|
| 290 |
-
if self.file_upload_folder is not None:
|
| 291 |
-
upload_file = gr.File(label="Upload a file")
|
| 292 |
-
upload_status = gr.Textbox(label="Upload Status", interactive=False, visible=False)
|
| 293 |
-
upload_file.change(
|
| 294 |
-
self.upload_file,
|
| 295 |
-
[upload_file, file_uploads_log],
|
| 296 |
-
[upload_status, file_uploads_log],
|
| 297 |
)
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
self.
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 312 |
|
| 313 |
|
| 314 |
__all__ = ["stream_to_gradio", "GradioUI"]
|
|
|
|
| 266 |
)
|
| 267 |
|
| 268 |
def launch(self, **kwargs):
|
| 269 |
+
import gradio as gr
|
| 270 |
+
|
| 271 |
+
with gr.Blocks(fill_height=True) as demo:
|
| 272 |
+
stored_messages = gr.State([])
|
| 273 |
+
file_uploads_log = gr.State([])
|
| 274 |
+
current_image = gr.State(None)
|
| 275 |
+
|
| 276 |
+
chatbot = gr.Chatbot(
|
| 277 |
+
label="Agent",
|
| 278 |
+
type="messages",
|
| 279 |
+
avatar_images=(
|
| 280 |
+
None,
|
| 281 |
+
"https://huggingface.co/datasets/agents-course/course-images/resolve/main/en/communication/Alfred.png",
|
| 282 |
+
),
|
| 283 |
+
resizeable=True,
|
| 284 |
+
scale=2,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
)
|
| 286 |
+
|
| 287 |
+
# Composant image dédié
|
| 288 |
+
image_output = gr.Image(label="Dernière image générée", visible=True)
|
| 289 |
+
|
| 290 |
+
if self.file_upload_folder is not None:
|
| 291 |
+
upload_file = gr.File(label="Upload a file")
|
| 292 |
+
upload_status = gr.Textbox(label="Upload Status", interactive=False, visible=False)
|
| 293 |
+
upload_file.change(
|
| 294 |
+
self.upload_file,
|
| 295 |
+
[upload_file, file_uploads_log],
|
| 296 |
+
[upload_status, file_uploads_log],
|
| 297 |
+
)
|
| 298 |
+
|
| 299 |
+
text_input = gr.Textbox(lines=1, label="Chat Message")
|
| 300 |
+
|
| 301 |
+
text_input.submit(
|
| 302 |
+
self.log_user_message,
|
| 303 |
+
[text_input, file_uploads_log],
|
| 304 |
+
[stored_messages, text_input],
|
| 305 |
+
).then(
|
| 306 |
+
self.interact_with_agent,
|
| 307 |
+
[stored_messages, chatbot, current_image],
|
| 308 |
+
[chatbot, image_output], # <= chatbot + image
|
| 309 |
+
)
|
| 310 |
+
|
| 311 |
+
demo.launch(debug=True, share=True, **kwargs)
|
| 312 |
|
| 313 |
|
| 314 |
__all__ = ["stream_to_gradio", "GradioUI"]
|