ikraamkb commited on
Commit
29f74d3
·
verified ·
1 Parent(s): b20b9f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
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: UploadFile):
55
- ext = file.filename.split(".")[-1].lower()
56
- if ext == "pdf":
 
 
 
 
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: