Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
|
|
|
| 3 |
from utils import (
|
| 4 |
get_salesforce_client, get_salesforce_objects, get_object_fields,
|
| 5 |
extract_text_from_pdf, extract_key_value_pairs, map_fields,
|
|
@@ -15,16 +16,34 @@ def upload_pdfs(files):
|
|
| 15 |
if isinstance(files, list):
|
| 16 |
for file in files:
|
| 17 |
if file is not None:
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
else:
|
| 23 |
if files is not None:
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
return f"Uploaded {len(uploaded_files)} PDF(s): {', '.join(uploaded_files)}"
|
| 29 |
|
| 30 |
def fetch_objects():
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
+
from io import BytesIO
|
| 4 |
from utils import (
|
| 5 |
get_salesforce_client, get_salesforce_objects, get_object_fields,
|
| 6 |
extract_text_from_pdf, extract_key_value_pairs, map_fields,
|
|
|
|
| 16 |
if isinstance(files, list):
|
| 17 |
for file in files:
|
| 18 |
if file is not None:
|
| 19 |
+
file_name = os.path.basename(file.name)
|
| 20 |
+
file_path = f"uploads/{file_name}"
|
| 21 |
+
try:
|
| 22 |
+
# Handle NamedString or file-like object
|
| 23 |
+
if hasattr(file, 'read'):
|
| 24 |
+
content = file.read()
|
| 25 |
+
else:
|
| 26 |
+
# Assume NamedString; convert string content to bytes
|
| 27 |
+
content = str(file).encode('utf-8')
|
| 28 |
+
with open(file_path, "wb") as f:
|
| 29 |
+
f.write(content)
|
| 30 |
+
uploaded_files.append(file_path)
|
| 31 |
+
except Exception as e:
|
| 32 |
+
return f"Error processing {file_name}: {str(e)}"
|
| 33 |
else:
|
| 34 |
if files is not None:
|
| 35 |
+
file_name = os.path.basename(files.name)
|
| 36 |
+
file_path = f"uploads/{file_name}"
|
| 37 |
+
try:
|
| 38 |
+
if hasattr(files, 'read'):
|
| 39 |
+
content = files.read()
|
| 40 |
+
else:
|
| 41 |
+
content = str(files).encode('utf-8')
|
| 42 |
+
with open(file_path, "wb") as f:
|
| 43 |
+
f.write(content)
|
| 44 |
+
uploaded_files.append(file_path)
|
| 45 |
+
except Exception as e:
|
| 46 |
+
return f"Error processing {file_name}: {str(e)}"
|
| 47 |
return f"Uploaded {len(uploaded_files)} PDF(s): {', '.join(uploaded_files)}"
|
| 48 |
|
| 49 |
def fetch_objects():
|