DreamStream-1 commited on
Commit
9f3a072
·
verified ·
1 Parent(s): 0357e05

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -215,11 +215,14 @@ class AdvancedRAG:
215
  if file is None:
216
  raise ValueError("No file provided")
217
 
218
- # Create a new file
219
- with tempfile.NamedTemporaryFile(delete=False, suffix=os.path.splitext(file.name)[1]) as tmp:
220
- # Write the file content to the temporary file
221
- with open(file.path, 'rb') as f:
222
- tmp.write(f.read())
 
 
 
223
  tmp.flush()
224
 
225
  # Upload the file to OpenAI
@@ -395,7 +398,8 @@ with gr.Blocks(title="Document Q&A System", css=custom_css) as demo:
395
  file_input = gr.File(
396
  label="Upload Document",
397
  file_types=[".pdf", ".txt", ".doc", ".docx"],
398
- file_count="single"
 
399
  )
400
  file_output = gr.Textbox(
401
  label="Upload Status",
 
215
  if file is None:
216
  raise ValueError("No file provided")
217
 
218
+ # The file is now a bytes object directly
219
+ file_bytes = file
220
+ if not file_bytes:
221
+ raise ValueError("Empty file")
222
+
223
+ # Create a temporary file with a generic extension
224
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".txt") as tmp:
225
+ tmp.write(file_bytes)
226
  tmp.flush()
227
 
228
  # Upload the file to OpenAI
 
398
  file_input = gr.File(
399
  label="Upload Document",
400
  file_types=[".pdf", ".txt", ".doc", ".docx"],
401
+ file_count="single",
402
+ type="binary" # Specify that we want binary data
403
  )
404
  file_output = gr.Textbox(
405
  label="Upload Status",