Vira21 commited on
Commit
5353dbf
1 Parent(s): 3c54509

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -59,7 +59,7 @@ text_splitter = CharacterTextSplitter()
59
  def process_text_file(file: AskFileResponse):
60
  with tempfile.NamedTemporaryFile(mode="wb", delete=False, suffix=".txt") as temp_file:
61
  temp_file_path = temp_file.name
62
- temp_file.write(file.content)
63
 
64
  text_loader = TextFileLoader(temp_file_path)
65
  documents = text_loader.load_documents()
@@ -67,9 +67,8 @@ def process_text_file(file: AskFileResponse):
67
  return texts
68
 
69
  def process_pdf_file(file: AskFileResponse):
70
- with tempfile.NamedTemporaryFile(mode="wb", delete=False, suffix=".pdf") as temp_file:
71
- temp_file_path = temp_file.name
72
- temp_file.write(file.content)
73
 
74
  extracted_text = ""
75
  with pdfplumber.open(temp_file_path) as pdf:
@@ -79,6 +78,8 @@ def process_pdf_file(file: AskFileResponse):
79
  texts = text_splitter.split_texts([extracted_text])
80
  return texts
81
 
 
 
82
  def process_csv_file(file: AskFileResponse):
83
  with tempfile.NamedTemporaryFile(mode="wb", delete=False, suffix=".csv") as temp_file:
84
  temp_file_path = temp_file.name
@@ -108,9 +109,10 @@ async def on_chat_start():
108
  for file in files:
109
  file_type = file.name.split(".")[-1].lower()
110
 
111
- msg = cl.Message(content=f"Processing `{file.name}`...", disable_human_feedback=True)
112
  await msg.send()
113
 
 
114
  # Process each file based on its type
115
  if file_type == "txt":
116
  texts = process_text_file(file)
 
59
  def process_text_file(file: AskFileResponse):
60
  with tempfile.NamedTemporaryFile(mode="wb", delete=False, suffix=".txt") as temp_file:
61
  temp_file_path = temp_file.name
62
+ temp_file.write(file.read)
63
 
64
  text_loader = TextFileLoader(temp_file_path)
65
  documents = text_loader.load_documents()
 
67
  return texts
68
 
69
  def process_pdf_file(file: AskFileResponse):
70
+ # Use the path attribute to read the file directly
71
+ temp_file_path = file.path # Get the path of the uploaded file
 
72
 
73
  extracted_text = ""
74
  with pdfplumber.open(temp_file_path) as pdf:
 
78
  texts = text_splitter.split_texts([extracted_text])
79
  return texts
80
 
81
+
82
+
83
  def process_csv_file(file: AskFileResponse):
84
  with tempfile.NamedTemporaryFile(mode="wb", delete=False, suffix=".csv") as temp_file:
85
  temp_file_path = temp_file.name
 
109
  for file in files:
110
  file_type = file.name.split(".")[-1].lower()
111
 
112
+ msg = cl.Message(content=f"Processing `{file.name}`...")
113
  await msg.send()
114
 
115
+
116
  # Process each file based on its type
117
  if file_type == "txt":
118
  texts = process_text_file(file)