Hoctar77 commited on
Commit
3e12a48
·
verified ·
1 Parent(s): dec3aa4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -5
app.py CHANGED
@@ -650,15 +650,35 @@ def process_file(file_obj, doc_type, template_type):
650
  if file_obj is None:
651
  return "Please upload a document first."
652
 
653
- if not hasattr(file_obj, 'name') or not file_obj.name.endswith('.docx'):
654
- return "Please upload a valid .docx file."
655
-
656
  try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
657
  # Process the document and get results
658
  results = process_document(file_obj, doc_type, template_type)
659
  return results
 
660
  except Exception as e:
661
  error_trace = traceback.format_exc()
 
 
 
662
  error_message = f"""An error occurred while processing the document:
663
 
664
  Error: {str(e)}
@@ -666,9 +686,10 @@ Error: {str(e)}
666
  Please ensure:
667
  1. The file is a valid Word document (.docx)
668
  2. The file is not corrupted
669
- 3. The file is not password protected"""
 
 
670
 
671
- logging.error(f"Error processing document: {error_trace}")
672
  return error_message
673
 
674
  # Create the interface with simplified layout for Hugging Face Spaces
 
650
  if file_obj is None:
651
  return "Please upload a document first."
652
 
 
 
 
653
  try:
654
+ # Debug information about the uploaded file
655
+ print(f"Received file: {type(file_obj)}")
656
+ print(f"File attributes: {dir(file_obj)}")
657
+
658
+ # Check if it's a file-like object
659
+ if hasattr(file_obj, 'name'):
660
+ print(f"File name: {file_obj.name}")
661
+
662
+ # For Gradio file upload, the file object should have a name attribute
663
+ # that contains the path to the temporary uploaded file
664
+ if isinstance(file_obj, str):
665
+ # If file_obj is a string (filepath)
666
+ file_path = file_obj
667
+ else:
668
+ # If file_obj is a file-like object
669
+ file_path = file_obj.name
670
+
671
+ print(f"File path: {file_path}")
672
+
673
  # Process the document and get results
674
  results = process_document(file_obj, doc_type, template_type)
675
  return results
676
+
677
  except Exception as e:
678
  error_trace = traceback.format_exc()
679
+ print(f"Error processing file: {str(e)}")
680
+ print(f"Full traceback: {error_trace}")
681
+
682
  error_message = f"""An error occurred while processing the document:
683
 
684
  Error: {str(e)}
 
686
  Please ensure:
687
  1. The file is a valid Word document (.docx)
688
  2. The file is not corrupted
689
+ 3. The file is not password protected
690
+
691
+ Technical details: {str(e)}"""
692
 
 
693
  return error_message
694
 
695
  # Create the interface with simplified layout for Hugging Face Spaces