NaimaAqeel commited on
Commit
a37ef5b
·
verified ·
1 Parent(s): 6959bbb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -75,15 +75,14 @@ def preprocess_text(text):
75
  def upload_files(files):
76
  try:
77
  for file in files:
78
- if isinstance(file, str): # Assuming `file` is a string (file path)
79
- if file.endswith('.pdf'):
80
- text = extract_text_from_pdf(file)
81
- elif file.endswith('.docx'):
82
- text = extract_text_from_docx(file)
83
- else:
84
- return {"error": "Unsupported file format"}
85
  else:
86
- return {"error": "Invalid file format: expected a string"}
87
 
88
  # Preprocess text
89
  sentences = preprocess_text(text)
@@ -103,6 +102,7 @@ def upload_files(files):
103
  print(f"Error processing files: {e}")
104
  return {"error": str(e)} # Provide informative error message
105
 
 
106
  def process_and_query(state, files, question):
107
  if files:
108
  upload_result = upload_files(files)
 
75
  def upload_files(files):
76
  try:
77
  for file in files:
78
+ file_path = file.name # Assuming `file` is a Gradio File object
79
+
80
+ if file_path.endswith('.pdf'):
81
+ text = extract_text_from_pdf(file_path)
82
+ elif file_path.endswith('.docx'):
83
+ text = extract_text_from_docx(file_path)
 
84
  else:
85
+ return {"error": f"Unsupported file format: {file_path}"}
86
 
87
  # Preprocess text
88
  sentences = preprocess_text(text)
 
102
  print(f"Error processing files: {e}")
103
  return {"error": str(e)} # Provide informative error message
104
 
105
+
106
  def process_and_query(state, files, question):
107
  if files:
108
  upload_result = upload_files(files)