capradeepgujaran
commited on
Commit
β’
1ce6811
1
Parent(s):
1719823
Update app.py
Browse files
app.py
CHANGED
@@ -19,7 +19,7 @@ load_dotenv()
|
|
19 |
|
20 |
# Set the path for Tesseract OCR (only needed on Windows)
|
21 |
# On Linux-based systems (like Hugging Face Spaces), Tesseract is usually available via apt
|
22 |
-
#
|
23 |
# pytesseract.pytesseract.tesseract_cmd = r'/usr/bin/tesseract'
|
24 |
|
25 |
# Initialize global variables
|
@@ -77,16 +77,14 @@ def process_upload(files):
|
|
77 |
documents = []
|
78 |
for file in files:
|
79 |
try:
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
text = load_file_based_on_extension(tmp_path)
|
84 |
documents.append(Document(text=text))
|
85 |
-
os.unlink(tmp_path) # Clean up the temporary file
|
86 |
except ValueError as e:
|
87 |
-
return f"Skipping unsupported file: {
|
88 |
except Exception as e:
|
89 |
-
return f"Error processing file {
|
90 |
|
91 |
if documents:
|
92 |
embed_model = OpenAIEmbedding(model="text-embedding-3-large")
|
@@ -166,7 +164,7 @@ def main():
|
|
166 |
with gr.Tab("π€ Upload Documents"):
|
167 |
gr.Markdown("### Upload PDF, DOCX, or TXT files to index")
|
168 |
with gr.Row():
|
169 |
-
file_upload = gr.File(label="Upload Files", file_count="multiple", type="
|
170 |
upload_button = gr.Button("Upload and Index")
|
171 |
upload_status = gr.Textbox(label="Status", interactive=False)
|
172 |
|
|
|
19 |
|
20 |
# Set the path for Tesseract OCR (only needed on Windows)
|
21 |
# On Linux-based systems (like Hugging Face Spaces), Tesseract is usually available via apt
|
22 |
+
# Uncomment and adjust if necessary
|
23 |
# pytesseract.pytesseract.tesseract_cmd = r'/usr/bin/tesseract'
|
24 |
|
25 |
# Initialize global variables
|
|
|
77 |
documents = []
|
78 |
for file in files:
|
79 |
try:
|
80 |
+
file_path = file['path']
|
81 |
+
file_name = file['name']
|
82 |
+
text = load_file_based_on_extension(file_path)
|
|
|
83 |
documents.append(Document(text=text))
|
|
|
84 |
except ValueError as e:
|
85 |
+
return f"Skipping unsupported file: {file_name} ({e})", None
|
86 |
except Exception as e:
|
87 |
+
return f"Error processing file {file_name}: {e}", None
|
88 |
|
89 |
if documents:
|
90 |
embed_model = OpenAIEmbedding(model="text-embedding-3-large")
|
|
|
164 |
with gr.Tab("π€ Upload Documents"):
|
165 |
gr.Markdown("### Upload PDF, DOCX, or TXT files to index")
|
166 |
with gr.Row():
|
167 |
+
file_upload = gr.File(label="Upload Files", file_count="multiple", type="filepath")
|
168 |
upload_button = gr.Button("Upload and Index")
|
169 |
upload_status = gr.Textbox(label="Status", interactive=False)
|
170 |
|