Spaces:
Runtime error
Runtime error
Leonardo
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -545,19 +545,25 @@ class GradioUI:
|
|
| 545 |
)
|
| 546 |
yield messages
|
| 547 |
|
| 548 |
-
def handle_file_upload(self,
|
| 549 |
"""
|
| 550 |
Handle file uploads with proper validation and security.
|
| 551 |
Args:
|
| 552 |
-
|
| 553 |
file_uploads_log: List of uploaded files
|
| 554 |
Returns:
|
| 555 |
-
Tuple of (status textbox, updated file_uploads_log)
|
| 556 |
"""
|
| 557 |
-
if
|
| 558 |
-
return
|
|
|
|
|
|
|
|
|
|
| 559 |
|
| 560 |
try:
|
|
|
|
|
|
|
|
|
|
| 561 |
# Validate file exists
|
| 562 |
if not os.path.exists(file.name):
|
| 563 |
return (
|
|
@@ -600,7 +606,7 @@ class GradioUI:
|
|
| 600 |
shutil.copy(file.name, file_path)
|
| 601 |
|
| 602 |
return (
|
| 603 |
-
gr.Textbox(value=f"File uploaded: {
|
| 604 |
file_uploads_log + [file_path],
|
| 605 |
)
|
| 606 |
|
|
@@ -736,7 +742,7 @@ class GradioUI:
|
|
| 736 |
self.components.file_uploader = gr.File(
|
| 737 |
label="Upload a file",
|
| 738 |
file_types=["pdf", "docx", "txt", "md", "json"],
|
| 739 |
-
type="
|
| 740 |
)
|
| 741 |
self.components.upload_status = gr.Textbox(
|
| 742 |
label="Upload status", interactive=False, visible=False
|
|
|
|
| 545 |
)
|
| 546 |
yield messages
|
| 547 |
|
| 548 |
+
def handle_file_upload(self, files, file_uploads_log):
|
| 549 |
"""
|
| 550 |
Handle file uploads with proper validation and security.
|
| 551 |
Args:
|
| 552 |
+
files: Files to upload
|
| 553 |
file_uploads_log: List of uploaded files
|
| 554 |
Returns:
|
| 555 |
+
Tuple of (status textbox, updated file_uploads_log, updated upload button visibility)
|
| 556 |
"""
|
| 557 |
+
if not files:
|
| 558 |
+
return (
|
| 559 |
+
gr.Textbox(value="No file uploaded", visible=True),
|
| 560 |
+
file_uploads_log,
|
| 561 |
+
)
|
| 562 |
|
| 563 |
try:
|
| 564 |
+
# Process the file (files[0] since we're using file_count="single")
|
| 565 |
+
file = files[0]
|
| 566 |
+
|
| 567 |
# Validate file exists
|
| 568 |
if not os.path.exists(file.name):
|
| 569 |
return (
|
|
|
|
| 606 |
shutil.copy(file.name, file_path)
|
| 607 |
|
| 608 |
return (
|
| 609 |
+
gr.Textbox(value=f"File uploaded: {original_name}", visible=True),
|
| 610 |
file_uploads_log + [file_path],
|
| 611 |
)
|
| 612 |
|
|
|
|
| 742 |
self.components.file_uploader = gr.File(
|
| 743 |
label="Upload a file",
|
| 744 |
file_types=["pdf", "docx", "txt", "md", "json"],
|
| 745 |
+
type="file",
|
| 746 |
)
|
| 747 |
self.components.upload_status = gr.Textbox(
|
| 748 |
label="Upload status", interactive=False, visible=False
|