NaimaAqeel commited on
Commit
ca47d69
·
verified ·
1 Parent(s): 6a2ef85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -87,10 +87,16 @@ def extract_text_from_docx(path):
87
  # ===============================
88
  def upload_document(file):
89
  ext = os.path.splitext(file.name)[-1].lower()
 
 
 
 
 
 
90
  if ext == ".pdf":
91
- text = extract_text_from_pdf(file.name)
92
  elif ext == ".docx":
93
- text = extract_text_from_docx(file.name)
94
  else:
95
  return "Unsupported file type."
96
 
@@ -104,8 +110,12 @@ def upload_document(file):
104
  with open(document_texts_path, "wb") as f:
105
  pickle.dump(document_texts, f)
106
 
 
 
 
107
  return "Document uploaded and indexed successfully."
108
 
 
109
  # ===============================
110
  # GENERATION PIPELINE (FLAN-T5)
111
  # ===============================
 
87
  # ===============================
88
  def upload_document(file):
89
  ext = os.path.splitext(file.name)[-1].lower()
90
+
91
+ # Save uploaded file temporarily
92
+ temp_path = f"temp_upload{ext}"
93
+ with open(temp_path, "wb") as f:
94
+ f.write(file.read())
95
+
96
  if ext == ".pdf":
97
+ text = extract_text_from_pdf(temp_path)
98
  elif ext == ".docx":
99
+ text = extract_text_from_docx(temp_path)
100
  else:
101
  return "Unsupported file type."
102
 
 
110
  with open(document_texts_path, "wb") as f:
111
  pickle.dump(document_texts, f)
112
 
113
+ # Remove the temporary file after processing (optional)
114
+ os.remove(temp_path)
115
+
116
  return "Document uploaded and indexed successfully."
117
 
118
+
119
  # ===============================
120
  # GENERATION PIPELINE (FLAN-T5)
121
  # ===============================