Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -62,7 +62,10 @@ def fetch_fields(object_name):
|
|
| 62 |
return gr.update(choices=[]), f"Error: {error}"
|
| 63 |
return gr.update(choices=fields), "Fields fetched successfully"
|
| 64 |
|
| 65 |
-
def process_pdf(
|
|
|
|
|
|
|
|
|
|
| 66 |
text_data, error = extract_text_from_pdf(pdf_path)
|
| 67 |
if error:
|
| 68 |
return f"Error: {error}"
|
|
@@ -71,7 +74,10 @@ def process_pdf(pdf_path):
|
|
| 71 |
return f"Error: {error}"
|
| 72 |
return f"Text: {text_data}\nKey-Value Pairs: {kv_pairs}"
|
| 73 |
|
| 74 |
-
def display_mappings(
|
|
|
|
|
|
|
|
|
|
| 75 |
sf, error = get_salesforce_client()
|
| 76 |
if error:
|
| 77 |
return f"Error: {error}"
|
|
@@ -89,7 +95,10 @@ def display_mappings(pdf_path, object_name):
|
|
| 89 |
output += f"{key} -> {field} (Confidence: {confidence_scores[key]})\n"
|
| 90 |
return output
|
| 91 |
|
| 92 |
-
def migrate_to_salesforce(
|
|
|
|
|
|
|
|
|
|
| 93 |
sf, error = get_salesforce_client()
|
| 94 |
if error:
|
| 95 |
log_failure(pdf_path, object_name, error)
|
|
@@ -129,7 +138,7 @@ def display_failures():
|
|
| 129 |
return "No failures logged"
|
| 130 |
|
| 131 |
def retry_migration(pdf_path, object_name):
|
| 132 |
-
return migrate_to_salesforce(pdf_path, object_name)
|
| 133 |
|
| 134 |
# Gradio UI
|
| 135 |
with gr.Blocks() as app:
|
|
|
|
| 62 |
return gr.update(choices=[]), f"Error: {error}"
|
| 63 |
return gr.update(choices=fields), "Fields fetched successfully"
|
| 64 |
|
| 65 |
+
def process_pdf(pdf_paths):
|
| 66 |
+
if not pdf_paths or not isinstance(pdf_paths, list) or not pdf_paths[0]:
|
| 67 |
+
return "Error: No valid PDF file provided"
|
| 68 |
+
pdf_path = pdf_paths[0] # Take the first file from the list
|
| 69 |
text_data, error = extract_text_from_pdf(pdf_path)
|
| 70 |
if error:
|
| 71 |
return f"Error: {error}"
|
|
|
|
| 74 |
return f"Error: {error}"
|
| 75 |
return f"Text: {text_data}\nKey-Value Pairs: {kv_pairs}"
|
| 76 |
|
| 77 |
+
def display_mappings(pdf_paths, object_name):
|
| 78 |
+
if not pdf_paths or not isinstance(pdf_paths, list) or not pdf_paths[0]:
|
| 79 |
+
return "Error: No valid PDF file provided"
|
| 80 |
+
pdf_path = pdf_paths[0] # Take the first file from the list
|
| 81 |
sf, error = get_salesforce_client()
|
| 82 |
if error:
|
| 83 |
return f"Error: {error}"
|
|
|
|
| 95 |
output += f"{key} -> {field} (Confidence: {confidence_scores[key]})\n"
|
| 96 |
return output
|
| 97 |
|
| 98 |
+
def migrate_to_salesforce(pdf_paths, object_name):
|
| 99 |
+
if not pdf_paths or not isinstance(pdf_paths, list) or not pdf_paths[0]:
|
| 100 |
+
return "Error: No valid PDF file provided"
|
| 101 |
+
pdf_path = pdf_paths[0] # Take the first file from the list
|
| 102 |
sf, error = get_salesforce_client()
|
| 103 |
if error:
|
| 104 |
log_failure(pdf_path, object_name, error)
|
|
|
|
| 138 |
return "No failures logged"
|
| 139 |
|
| 140 |
def retry_migration(pdf_path, object_name):
|
| 141 |
+
return migrate_to_salesforce([pdf_path], object_name) # Wrap single path in list for consistency
|
| 142 |
|
| 143 |
# Gradio UI
|
| 144 |
with gr.Blocks() as app:
|