Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -51,21 +51,25 @@ def extract_text_from_xlsx(file):
|
|
51 |
text.append(line)
|
52 |
return "\n".join(text)
|
53 |
|
54 |
-
def summarize_document(file
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
57 |
text = extract_text_from_pdf(file)
|
58 |
-
elif ext == "docx":
|
59 |
text = extract_text_from_docx(file)
|
60 |
-
elif ext == "pptx":
|
61 |
text = extract_text_from_pptx(file)
|
62 |
-
elif ext == "xlsx":
|
63 |
text = extract_text_from_xlsx(file)
|
64 |
else:
|
65 |
return "Unsupported file format."
|
66 |
|
67 |
if not text.strip():
|
68 |
-
return "No extractable text."
|
69 |
|
70 |
text = text[:3000]
|
71 |
try:
|
|
|
51 |
text.append(line)
|
52 |
return "\n".join(text)
|
53 |
|
54 |
+
def summarize_document(file):
|
55 |
+
import os
|
56 |
+
|
57 |
+
name = getattr(file, "name", "")
|
58 |
+
ext = os.path.splitext(name)[1].lower()
|
59 |
+
|
60 |
+
if ext == ".pdf":
|
61 |
text = extract_text_from_pdf(file)
|
62 |
+
elif ext == ".docx":
|
63 |
text = extract_text_from_docx(file)
|
64 |
+
elif ext == ".pptx":
|
65 |
text = extract_text_from_pptx(file)
|
66 |
+
elif ext == ".xlsx":
|
67 |
text = extract_text_from_xlsx(file)
|
68 |
else:
|
69 |
return "Unsupported file format."
|
70 |
|
71 |
if not text.strip():
|
72 |
+
return "No extractable text found."
|
73 |
|
74 |
text = text[:3000]
|
75 |
try:
|