Leonardo commited on
Commit
7202338
·
verified ·
1 Parent(s): 160f5e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -545,19 +545,25 @@ class GradioUI:
545
  )
546
  yield messages
547
 
548
- def handle_file_upload(self, file, file_uploads_log):
549
  """
550
  Handle file uploads with proper validation and security.
551
  Args:
552
- file: File to upload
553
  file_uploads_log: List of uploaded files
554
  Returns:
555
- Tuple of (status textbox, updated file_uploads_log)
556
  """
557
- if file is None:
558
- return gr.Textbox(value="No file uploaded", visible=True), file_uploads_log
 
 
 
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: {file_path}", visible=True),
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="filepath",
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