sid22669 commited on
Commit
72ba853
·
verified ·
1 Parent(s): 67eda41

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -9
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 in [".doc", ".docx"]:
34
  try:
35
- import textract
36
- with tempfile.NamedTemporaryFile(delete=False, suffix=ext) as tmp:
37
- tmp.write(uploaded_file.read())
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 Word file with textract: {str(e)}"
 
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."