Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -500,18 +500,26 @@ def handle_file_upload(file):
|
|
| 500 |
return "ℹ️ No file uploaded.", ""
|
| 501 |
|
| 502 |
try:
|
| 503 |
-
|
| 504 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 505 |
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
f"🔢 **Chunks:** {num_chunks}\n\n"
|
| 511 |
-
f"You can now ask questions about this document!"
|
| 512 |
-
), filename
|
| 513 |
except Exception as e:
|
| 514 |
-
return f"❌
|
|
|
|
| 515 |
|
| 516 |
def clear_uploaded_file():
|
| 517 |
"""Clear uploaded file and reload KB index."""
|
|
|
|
| 500 |
return "ℹ️ No file uploaded.", ""
|
| 501 |
|
| 502 |
try:
|
| 503 |
+
# Gradio File with type="filepath" -> file is a string
|
| 504 |
+
if isinstance(file, str):
|
| 505 |
+
file_path = file
|
| 506 |
+
filename = Path(file).name
|
| 507 |
+
else:
|
| 508 |
+
# Fallback for other types (e.g. temp file object)
|
| 509 |
+
file_path = getattr(file, "name", None)
|
| 510 |
+
if not file_path:
|
| 511 |
+
raise ValueError("Unsupported file object from Gradio.")
|
| 512 |
+
filename = Path(file_path).name
|
| 513 |
+
|
| 514 |
+
num_chunks, file_type = kb.build_from_uploaded_file(file_path, filename)
|
| 515 |
|
| 516 |
+
kb.uploaded_file_active = True
|
| 517 |
+
info = f"✅ Indexed {num_chunks} chunks from {file_type} file: **{filename}**"
|
| 518 |
+
return info, filename
|
| 519 |
+
|
|
|
|
|
|
|
|
|
|
| 520 |
except Exception as e:
|
| 521 |
+
return f"❌ Error processing file: {str(e)}", ""
|
| 522 |
+
|
| 523 |
|
| 524 |
def clear_uploaded_file():
|
| 525 |
"""Clear uploaded file and reload KB index."""
|