Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,17 +30,14 @@ def read_uploaded_file(uploaded_file):
|
|
| 30 |
elif ext == ".txt":
|
| 31 |
return uploaded_file.read().decode("utf-8").strip()
|
| 32 |
|
| 33 |
-
elif ext
|
| 34 |
try:
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
tmp_path = tmp.name
|
| 39 |
-
text = textract.process(tmp_path)
|
| 40 |
-
os.remove(tmp_path)
|
| 41 |
-
return text.decode("utf-8").strip()
|
| 42 |
except Exception as e:
|
| 43 |
-
return f"Error reading
|
|
|
|
| 44 |
|
| 45 |
else:
|
| 46 |
return "Unsupported file type."
|
|
|
|
| 30 |
elif ext == ".txt":
|
| 31 |
return uploaded_file.read().decode("utf-8").strip()
|
| 32 |
|
| 33 |
+
elif ext == ".docx":
|
| 34 |
try:
|
| 35 |
+
doc = Document(file_path)
|
| 36 |
+
text = "\n".join([para.text for para in doc.paragraphs])
|
| 37 |
+
return text.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
except Exception as e:
|
| 39 |
+
return f"Error reading DOCX file: {str(e)}"
|
| 40 |
+
|
| 41 |
|
| 42 |
else:
|
| 43 |
return "Unsupported file type."
|