Spaces:
Running
Running
Update ui/manual_dashboard.py
Browse files- ui/manual_dashboard.py +10 -14
ui/manual_dashboard.py
CHANGED
|
@@ -73,7 +73,6 @@ def extract_ocr_text_ui(filename):
|
|
| 73 |
"""Extract text from image using OCR"""
|
| 74 |
try:
|
| 75 |
file_path = os.path.join(UPLOAD_DIR, filename)
|
| 76 |
-
# Run async function in sync context
|
| 77 |
result = asyncio.run(extract_text_ocr(file_path, 'en'))
|
| 78 |
if 'error' in result:
|
| 79 |
return f"β οΈ Error: {result['error']}"
|
|
@@ -96,7 +95,6 @@ def summarize_pdf_ui(filename, length):
|
|
| 96 |
"""Summarize PDF document"""
|
| 97 |
try:
|
| 98 |
file_path = os.path.join(UPLOAD_DIR, filename)
|
| 99 |
-
# Run async function properly
|
| 100 |
result = asyncio.run(summarize_pdf(file_path, max_length=length*100))
|
| 101 |
|
| 102 |
if isinstance(result, dict):
|
|
@@ -113,7 +111,6 @@ def extract_metadata_ui(filename):
|
|
| 113 |
"""Extract metadata from PDF"""
|
| 114 |
try:
|
| 115 |
file_path = os.path.join(UPLOAD_DIR, filename)
|
| 116 |
-
# Run async function properly
|
| 117 |
result = asyncio.run(extract_pdf_metadata(file_path))
|
| 118 |
return json.dumps(result, indent=2)
|
| 119 |
except Exception as e:
|
|
@@ -124,7 +121,6 @@ def extract_metadata_ui(filename):
|
|
| 124 |
def email_ui(recipient, subject, body):
|
| 125 |
"""Draft email"""
|
| 126 |
try:
|
| 127 |
-
# Run async function properly
|
| 128 |
result = asyncio.run(draft_email(
|
| 129 |
recipient=recipient,
|
| 130 |
subject=subject,
|
|
@@ -148,15 +144,12 @@ def email_ui(recipient, subject, body):
|
|
| 148 |
def calendar_ui(title, date, time_str, desc):
|
| 149 |
"""Create calendar event"""
|
| 150 |
try:
|
| 151 |
-
# Combine date and time
|
| 152 |
start_datetime = f"{date} {time_str}"
|
| 153 |
-
# Calculate end time (1 hour later)
|
| 154 |
from datetime import datetime, timedelta
|
| 155 |
start_dt = datetime.strptime(start_datetime, "%Y-%m-%d %H:%M")
|
| 156 |
end_dt = start_dt + timedelta(hours=1)
|
| 157 |
end_datetime = end_dt.strftime("%Y-%m-%d %H:%M")
|
| 158 |
|
| 159 |
-
# Run async function properly
|
| 160 |
result = asyncio.run(create_calendar_event(
|
| 161 |
title=title,
|
| 162 |
start=start_datetime,
|
|
@@ -179,16 +172,15 @@ def calendar_ui(title, date, time_str, desc):
|
|
| 179 |
def organize_files_ui():
|
| 180 |
"""Organize files in upload directory"""
|
| 181 |
try:
|
| 182 |
-
# Run async function properly
|
| 183 |
result = asyncio.run(organize_files(UPLOAD_DIR, strategy='by_type'))
|
| 184 |
return json.dumps(result, indent=2)
|
| 185 |
except Exception as e:
|
| 186 |
return f"β οΈ Error:\n{e}"
|
| 187 |
|
| 188 |
|
| 189 |
-
# ---------------- FORM FILLING (FIXED) ----------------
|
| 190 |
def fill_form_ui(template_file, user_text):
|
| 191 |
-
"""Fill form template with data - FIXED
|
| 192 |
if not template_file:
|
| 193 |
return "β οΈ Upload .docx or .xlsx template", None
|
| 194 |
|
|
@@ -209,6 +201,8 @@ def fill_form_ui(template_file, user_text):
|
|
| 209 |
|
| 210 |
# Parse user input into dictionary with smart field mapping
|
| 211 |
fields = {}
|
|
|
|
|
|
|
| 212 |
for line in user_text.split("\n"):
|
| 213 |
line = line.strip()
|
| 214 |
if not line:
|
|
@@ -219,7 +213,8 @@ def fill_form_ui(template_file, user_text):
|
|
| 219 |
key = parts[0].strip()
|
| 220 |
value = parts[1].strip()
|
| 221 |
|
| 222 |
-
# Store original key
|
|
|
|
| 223 |
fields[key] = value
|
| 224 |
|
| 225 |
# Also store normalized versions
|
|
@@ -246,7 +241,7 @@ def fill_form_ui(template_file, user_text):
|
|
| 246 |
status_msg = f"β
Form filled successfully!\n\n"
|
| 247 |
status_msg += f"π Fields filled: {total}\n"
|
| 248 |
if fields_filled:
|
| 249 |
-
status_msg += f"β {', '.join(fields_filled)}\n\n"
|
| 250 |
if debug_info:
|
| 251 |
status_msg += f"Debug info:\n" + "\n".join([f" β’ {info}" for info in debug_info[:5]])
|
| 252 |
status_msg += f"\n\nπ₯ Download the filled form below"
|
|
@@ -256,7 +251,8 @@ def fill_form_ui(template_file, user_text):
|
|
| 256 |
status_msg += f"1. Make sure field names EXACTLY match the labels in your form\n"
|
| 257 |
status_msg += f"2. Field names are case-insensitive\n"
|
| 258 |
status_msg += f"3. Common formats: 'First Name:', 'FirstName', 'first_name'\n\n"
|
| 259 |
-
|
|
|
|
| 260 |
|
| 261 |
return status_msg, output_path
|
| 262 |
else:
|
|
@@ -345,7 +341,7 @@ def create_manual_dashboard(agent):
|
|
| 345 |
|
| 346 |
btn2.click(calendar_ui, inputs=[title, date, time, desc], outputs=[status, file_out])
|
| 347 |
|
| 348 |
-
# FORM FILLER TAB (FIXED)
|
| 349 |
with gr.Tab("π Form Filler"):
|
| 350 |
with gr.Group():
|
| 351 |
gr.Markdown("""
|
|
|
|
| 73 |
"""Extract text from image using OCR"""
|
| 74 |
try:
|
| 75 |
file_path = os.path.join(UPLOAD_DIR, filename)
|
|
|
|
| 76 |
result = asyncio.run(extract_text_ocr(file_path, 'en'))
|
| 77 |
if 'error' in result:
|
| 78 |
return f"β οΈ Error: {result['error']}"
|
|
|
|
| 95 |
"""Summarize PDF document"""
|
| 96 |
try:
|
| 97 |
file_path = os.path.join(UPLOAD_DIR, filename)
|
|
|
|
| 98 |
result = asyncio.run(summarize_pdf(file_path, max_length=length*100))
|
| 99 |
|
| 100 |
if isinstance(result, dict):
|
|
|
|
| 111 |
"""Extract metadata from PDF"""
|
| 112 |
try:
|
| 113 |
file_path = os.path.join(UPLOAD_DIR, filename)
|
|
|
|
| 114 |
result = asyncio.run(extract_pdf_metadata(file_path))
|
| 115 |
return json.dumps(result, indent=2)
|
| 116 |
except Exception as e:
|
|
|
|
| 121 |
def email_ui(recipient, subject, body):
|
| 122 |
"""Draft email"""
|
| 123 |
try:
|
|
|
|
| 124 |
result = asyncio.run(draft_email(
|
| 125 |
recipient=recipient,
|
| 126 |
subject=subject,
|
|
|
|
| 144 |
def calendar_ui(title, date, time_str, desc):
|
| 145 |
"""Create calendar event"""
|
| 146 |
try:
|
|
|
|
| 147 |
start_datetime = f"{date} {time_str}"
|
|
|
|
| 148 |
from datetime import datetime, timedelta
|
| 149 |
start_dt = datetime.strptime(start_datetime, "%Y-%m-%d %H:%M")
|
| 150 |
end_dt = start_dt + timedelta(hours=1)
|
| 151 |
end_datetime = end_dt.strftime("%Y-%m-%d %H:%M")
|
| 152 |
|
|
|
|
| 153 |
result = asyncio.run(create_calendar_event(
|
| 154 |
title=title,
|
| 155 |
start=start_datetime,
|
|
|
|
| 172 |
def organize_files_ui():
|
| 173 |
"""Organize files in upload directory"""
|
| 174 |
try:
|
|
|
|
| 175 |
result = asyncio.run(organize_files(UPLOAD_DIR, strategy='by_type'))
|
| 176 |
return json.dumps(result, indent=2)
|
| 177 |
except Exception as e:
|
| 178 |
return f"β οΈ Error:\n{e}"
|
| 179 |
|
| 180 |
|
| 181 |
+
# ---------------- FORM FILLING (COMPLETE FIXED) ----------------
|
| 182 |
def fill_form_ui(template_file, user_text):
|
| 183 |
+
"""Fill form template with data - COMPLETE FIXED VERSION"""
|
| 184 |
if not template_file:
|
| 185 |
return "β οΈ Upload .docx or .xlsx template", None
|
| 186 |
|
|
|
|
| 201 |
|
| 202 |
# Parse user input into dictionary with smart field mapping
|
| 203 |
fields = {}
|
| 204 |
+
original_fields = []
|
| 205 |
+
|
| 206 |
for line in user_text.split("\n"):
|
| 207 |
line = line.strip()
|
| 208 |
if not line:
|
|
|
|
| 213 |
key = parts[0].strip()
|
| 214 |
value = parts[1].strip()
|
| 215 |
|
| 216 |
+
# Store original key
|
| 217 |
+
original_fields.append(key)
|
| 218 |
fields[key] = value
|
| 219 |
|
| 220 |
# Also store normalized versions
|
|
|
|
| 241 |
status_msg = f"β
Form filled successfully!\n\n"
|
| 242 |
status_msg += f"π Fields filled: {total}\n"
|
| 243 |
if fields_filled:
|
| 244 |
+
status_msg += f"β {', '.join(set(fields_filled))}\n\n"
|
| 245 |
if debug_info:
|
| 246 |
status_msg += f"Debug info:\n" + "\n".join([f" β’ {info}" for info in debug_info[:5]])
|
| 247 |
status_msg += f"\n\nπ₯ Download the filled form below"
|
|
|
|
| 251 |
status_msg += f"1. Make sure field names EXACTLY match the labels in your form\n"
|
| 252 |
status_msg += f"2. Field names are case-insensitive\n"
|
| 253 |
status_msg += f"3. Common formats: 'First Name:', 'FirstName', 'first_name'\n\n"
|
| 254 |
+
if original_fields:
|
| 255 |
+
status_msg += f"Your input fields:\n" + "\n".join([f" β’ {k}" for k in original_fields[:8]])
|
| 256 |
|
| 257 |
return status_msg, output_path
|
| 258 |
else:
|
|
|
|
| 341 |
|
| 342 |
btn2.click(calendar_ui, inputs=[title, date, time, desc], outputs=[status, file_out])
|
| 343 |
|
| 344 |
+
# FORM FILLER TAB (COMPLETE FIXED)
|
| 345 |
with gr.Tab("π Form Filler"):
|
| 346 |
with gr.Group():
|
| 347 |
gr.Markdown("""
|