Spaces:
Sleeping
Sleeping
Commit Β·
77e94ac
1
Parent(s): 41bb926
π Fix: handle NamedString and ensure bytes are written
Browse files
app.py
CHANGED
|
@@ -65,8 +65,20 @@ def process_file(file):
|
|
| 65 |
try:
|
| 66 |
ext = os.path.splitext(file.name)[1].lower()
|
| 67 |
with tempfile.NamedTemporaryFile(delete=False, suffix=ext) as tmp:
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
tmp.flush()
|
| 71 |
full_text = extract_text(tmp.name, ext)
|
| 72 |
|
|
|
|
| 65 |
try:
|
| 66 |
ext = os.path.splitext(file.name)[1].lower()
|
| 67 |
with tempfile.NamedTemporaryFile(delete=False, suffix=ext) as tmp:
|
| 68 |
+
# Ensure we always write bytes regardless of file type
|
| 69 |
+
# Ensure we always write bytes regardless of file type
|
| 70 |
+
if hasattr(file, "read"):
|
| 71 |
+
file_bytes = file.read()
|
| 72 |
+
elif isinstance(file, str):
|
| 73 |
+
with open(file, "rb") as f:
|
| 74 |
+
file_bytes = f.read()
|
| 75 |
+
elif isinstance(file, bytes):
|
| 76 |
+
file_bytes = file
|
| 77 |
+
else:
|
| 78 |
+
file_bytes = bytes(str(file), encoding='utf-8') # fallback for NamedString
|
| 79 |
+
|
| 80 |
+
tmp.write(file_bytes)
|
| 81 |
+
|
| 82 |
tmp.flush()
|
| 83 |
full_text = extract_text(tmp.name, ext)
|
| 84 |
|