Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -75,15 +75,14 @@ def preprocess_text(text):
|
|
75 |
def upload_files(files):
|
76 |
try:
|
77 |
for file in files:
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
return {"error": "Unsupported file format"}
|
85 |
else:
|
86 |
-
return {"error": "
|
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)
|