NaimaAqeel commited on
Commit
248e7bd
·
verified ·
1 Parent(s): 3feab75

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -68,23 +68,22 @@ else:
68
  def preprocess_text(text):
69
  sentences = sent_tokenize(text)
70
  return sentences
71
-
72
  def upload_files(files):
73
  global faiss_index
74
  try:
75
  for file in files:
76
  file_name = file.name
77
 
78
- # Check if file content is available directly
79
- if hasattr(file, "content"):
80
- file_content = file.content
81
  else:
82
- return {"error": "File content not accessible"}
83
 
84
  if file_name.endswith('.pdf'):
85
- text = extract_text_from_pdf(file_content)
86
  elif file_name.endswith('.docx'):
87
- text = extract_text_from_docx(file_content)
88
  else:
89
  return {"error": "Unsupported file format"}
90
 
 
68
  def preprocess_text(text):
69
  sentences = sent_tokenize(text)
70
  return sentences
 
71
  def upload_files(files):
72
  global faiss_index
73
  try:
74
  for file in files:
75
  file_name = file.name
76
 
77
+ # Extract file content
78
+ if isinstance(file, str):
79
+ file_content = file
80
  else:
81
+ file_content = file.read().decode("utf-8")
82
 
83
  if file_name.endswith('.pdf'):
84
+ text = extract_text_from_pdf(file_content.encode())
85
  elif file_name.endswith('.docx'):
86
+ text = extract_text_from_docx(file_content.encode())
87
  else:
88
  return {"error": "Unsupported file format"}
89