Update app.py
Browse files
app.py
CHANGED
|
@@ -151,23 +151,24 @@ def gradio_extraction(uploaded_files):
|
|
| 151 |
file_paths = []
|
| 152 |
|
| 153 |
for file in uploaded_files:
|
| 154 |
-
|
|
|
|
| 155 |
tmp_path = Path(tempfile.gettempdir()) / file_name
|
| 156 |
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 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,
|