Spaces:
Sleeping
Sleeping
Commit
ยท
72f13fa
1
Parent(s):
e0d1ddf
๐ Fix: Final file handling logic for Hugging Face Spaces
Browse files
app.py
CHANGED
|
@@ -70,13 +70,18 @@ def process_file(file):
|
|
| 70 |
try:
|
| 71 |
ext = os.path.splitext(getattr(file, "name", "file.pdf"))[1].lower()
|
| 72 |
with tempfile.NamedTemporaryFile(delete=False, suffix=ext) as tmp:
|
| 73 |
-
#
|
| 74 |
if hasattr(file, "read"):
|
|
|
|
| 75 |
file_bytes = file.read()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
elif isinstance(file, bytes):
|
| 77 |
file_bytes = file
|
| 78 |
else:
|
| 79 |
-
return "โ Error:
|
| 80 |
|
| 81 |
tmp.write(file_bytes)
|
| 82 |
tmp.flush()
|
|
|
|
| 70 |
try:
|
| 71 |
ext = os.path.splitext(getattr(file, "name", "file.pdf"))[1].lower()
|
| 72 |
with tempfile.NamedTemporaryFile(delete=False, suffix=ext) as tmp:
|
| 73 |
+
# Read bytes correctly depending on file type
|
| 74 |
if hasattr(file, "read"):
|
| 75 |
+
# Hugging Face NamedString or file-like
|
| 76 |
file_bytes = file.read()
|
| 77 |
+
elif isinstance(file, str) and os.path.exists(file):
|
| 78 |
+
# Local file path fallback
|
| 79 |
+
with open(file, "rb") as f:
|
| 80 |
+
file_bytes = f.read()
|
| 81 |
elif isinstance(file, bytes):
|
| 82 |
file_bytes = file
|
| 83 |
else:
|
| 84 |
+
return "โ Error: Could not process uploaded file."
|
| 85 |
|
| 86 |
tmp.write(file_bytes)
|
| 87 |
tmp.flush()
|