KarthikMuraliM commited on
Commit
356851f
·
verified ·
1 Parent(s): ff3c37a

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +9 -2
main.py CHANGED
@@ -80,10 +80,17 @@ async def process_analysis_request(files: List[UploadFile] = File(...)):
80
  with tempfile.TemporaryDirectory() as work_dir:
81
  # --- 1. FILE HANDLING (Using the Robust In-Memory Method) ---
82
  work_path = Path(work_dir)
83
- if not files: raise HTTPException(status.HTTP_400_BAD_REQUEST, "No files uploaded.")
84
 
85
- file_contents = {f.filename: await f.read() for f in files}
 
 
86
 
 
 
 
 
 
 
87
  questions_file_name, attached_file_names = None, []
88
  first_txt_file_name = None
89
  q_pattern = re.compile(r'question', re.IGNORECASE)
 
80
  with tempfile.TemporaryDirectory() as work_dir:
81
  # --- 1. FILE HANDLING (Using the Robust In-Memory Method) ---
82
  work_path = Path(work_dir)
 
83
 
84
+ # Manually parse the form data from the raw request. This is the key change.
85
+ form_data = await request.form()
86
+ all_files: List[UploadFile] = [part for part in form_data.values() if isinstance(part, UploadFile) and part.filename]
87
 
88
+ if not all_files: raise HTTPException(status.HTTP_400_BAD_REQUEST, "No files were uploaded.")
89
+
90
+ # Read all files into memory to avoid stream issues
91
+ file_contents = {f.filename: await f.read() for f in all_files}
92
+
93
+ # --- Now, perform the proven logic on the filenames ---
94
  questions_file_name, attached_file_names = None, []
95
  first_txt_file_name = None
96
  q_pattern = re.compile(r'question', re.IGNORECASE)