Ayesha-Majeed commited on
Commit
2fd03cf
·
verified ·
1 Parent(s): c6f011f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -151,23 +151,24 @@ def gradio_extraction(uploaded_files):
151
  file_paths = []
152
 
153
  for file in uploaded_files:
154
- file_name = Path(file.name).name
 
155
  tmp_path = Path(tempfile.gettempdir()) / file_name
156
 
157
- # write content to temp file
158
- with open(tmp_path, "wb") as f:
159
- f.write(file.data)
160
  file_paths.append(str(tmp_path))
161
 
162
  processed_data = process_files(file_paths)
163
  extracted_data = extract_with_gemini(processed_data)
164
 
165
- # Save JSON file
166
  with open("output.json", "w", encoding="utf-8") as f:
167
  json.dump(extracted_data, f, indent=2)
168
 
169
  return json.dumps(extracted_data, indent=2), "output.json"
170
 
 
171
  # ==================== Gradio Interface ====================
172
  iface = gr.Interface(
173
  fn=gradio_extraction,
 
151
  file_paths = []
152
 
153
  for file in uploaded_files:
154
+ src_path = Path(file.name)
155
+ file_name = src_path.name
156
  tmp_path = Path(tempfile.gettempdir()) / file_name
157
 
158
+ with open(src_path, "rb") as src, open(tmp_path, "wb") as dst:
159
+ dst.write(src.read())
160
+
161
  file_paths.append(str(tmp_path))
162
 
163
  processed_data = process_files(file_paths)
164
  extracted_data = extract_with_gemini(processed_data)
165
 
 
166
  with open("output.json", "w", encoding="utf-8") as f:
167
  json.dump(extracted_data, f, indent=2)
168
 
169
  return json.dumps(extracted_data, indent=2), "output.json"
170
 
171
+
172
  # ==================== Gradio Interface ====================
173
  iface = gr.Interface(
174
  fn=gradio_extraction,