Spaces:
Running
Running
Update ui/manual_dashboard.py
Browse files- ui/manual_dashboard.py +43 -50
ui/manual_dashboard.py
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import json
|
|
@@ -30,7 +35,7 @@ def ensure_dirs():
|
|
| 30 |
ensure_dirs()
|
| 31 |
|
| 32 |
|
| 33 |
-
# ---------------- FILE UPLOAD
|
| 34 |
def handle_file_upload(files):
|
| 35 |
"""Handle file uploads from Gradio"""
|
| 36 |
if not files:
|
|
@@ -180,9 +185,9 @@ def organize_files_ui():
|
|
| 180 |
|
| 181 |
# ---------------- FORM FILLING (COMPLETE FIXED) ----------------
|
| 182 |
def fill_form_ui(template_file, user_text):
|
| 183 |
-
"""Fill form template with data -
|
| 184 |
if not template_file:
|
| 185 |
-
return "β οΈ
|
| 186 |
|
| 187 |
try:
|
| 188 |
# Handle file path
|
|
@@ -199,9 +204,8 @@ def fill_form_ui(template_file, user_text):
|
|
| 199 |
with open(dest_template, "wb") as dst:
|
| 200 |
dst.write(src.read())
|
| 201 |
|
| 202 |
-
# Parse user input into dictionary
|
| 203 |
fields = {}
|
| 204 |
-
original_fields = []
|
| 205 |
|
| 206 |
for line in user_text.split("\n"):
|
| 207 |
line = line.strip()
|
|
@@ -212,22 +216,12 @@ def fill_form_ui(template_file, user_text):
|
|
| 212 |
if len(parts) == 2:
|
| 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
|
| 221 |
-
key_lower = key.lower()
|
| 222 |
-
key_underscore = key.replace(" ", "_").lower()
|
| 223 |
-
|
| 224 |
-
fields[key_lower] = value
|
| 225 |
-
fields[key_underscore] = value
|
| 226 |
|
| 227 |
if not fields:
|
| 228 |
return "β οΈ No fields parsed. Use format:\nField Name: Value", None
|
| 229 |
|
| 230 |
-
# Run async function
|
| 231 |
result = asyncio.run(fill_form(dest_template, fields))
|
| 232 |
|
| 233 |
if isinstance(result, dict):
|
|
@@ -237,22 +231,16 @@ def fill_form_ui(template_file, user_text):
|
|
| 237 |
total = result.get('total_fields', 0)
|
| 238 |
debug_info = result.get('debug_info', [])
|
| 239 |
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
status_msg += f"
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
status_msg += f"π‘ Troubleshooting:\n"
|
| 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:
|
|
@@ -345,35 +333,40 @@ def create_manual_dashboard(agent):
|
|
| 345 |
with gr.Tab("π Form Filler"):
|
| 346 |
with gr.Group():
|
| 347 |
gr.Markdown("""
|
| 348 |
-
###
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
|
|
|
|
|
|
| 352 |
|
| 353 |
-
**
|
|
|
|
|
|
|
|
|
|
| 354 |
|
| 355 |
-
**Example for
|
| 356 |
```
|
| 357 |
-
First Name:
|
| 358 |
-
Last Name:
|
| 359 |
-
Cell Phone: +
|
| 360 |
-
Work Phone:
|
| 361 |
-
Email:
|
| 362 |
-
Membership fee:
|
| 363 |
```
|
| 364 |
""")
|
| 365 |
|
| 366 |
-
template = gr.File(label="Upload Template (.docx or .xlsx)")
|
| 367 |
form_text = gr.Textbox(
|
| 368 |
lines=10,
|
| 369 |
-
label="Enter Field Data
|
| 370 |
-
placeholder="First Name:
|
| 371 |
value=""
|
| 372 |
)
|
| 373 |
|
| 374 |
-
btn3 = gr.Button("Fill Form", variant="primary")
|
| 375 |
-
status2 = gr.Textbox(label="Status", lines=
|
| 376 |
-
file2 = gr.File(label="Download Filled Form")
|
| 377 |
|
| 378 |
btn3.click(fill_form_ui, inputs=[template, form_text], outputs=[status2, file2])
|
| 379 |
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Manual Dashboard UI - FIXED VERSION
|
| 3 |
+
Complete tool-by-tool interface with working form filler
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
import os
|
| 7 |
import gradio as gr
|
| 8 |
import json
|
|
|
|
| 35 |
ensure_dirs()
|
| 36 |
|
| 37 |
|
| 38 |
+
# ---------------- FILE UPLOAD ----------------
|
| 39 |
def handle_file_upload(files):
|
| 40 |
"""Handle file uploads from Gradio"""
|
| 41 |
if not files:
|
|
|
|
| 185 |
|
| 186 |
# ---------------- FORM FILLING (COMPLETE FIXED) ----------------
|
| 187 |
def fill_form_ui(template_file, user_text):
|
| 188 |
+
"""Fill form template with data - COMPLETELY FIXED VERSION"""
|
| 189 |
if not template_file:
|
| 190 |
+
return "β οΈ Please upload a .docx or .xlsx template", None
|
| 191 |
|
| 192 |
try:
|
| 193 |
# Handle file path
|
|
|
|
| 204 |
with open(dest_template, "wb") as dst:
|
| 205 |
dst.write(src.read())
|
| 206 |
|
| 207 |
+
# Parse user input into dictionary
|
| 208 |
fields = {}
|
|
|
|
| 209 |
|
| 210 |
for line in user_text.split("\n"):
|
| 211 |
line = line.strip()
|
|
|
|
| 216 |
if len(parts) == 2:
|
| 217 |
key = parts[0].strip()
|
| 218 |
value = parts[1].strip()
|
|
|
|
|
|
|
|
|
|
| 219 |
fields[key] = value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
|
| 221 |
if not fields:
|
| 222 |
return "β οΈ No fields parsed. Use format:\nField Name: Value", None
|
| 223 |
|
| 224 |
+
# Run async function
|
| 225 |
result = asyncio.run(fill_form(dest_template, fields))
|
| 226 |
|
| 227 |
if isinstance(result, dict):
|
|
|
|
| 231 |
total = result.get('total_fields', 0)
|
| 232 |
debug_info = result.get('debug_info', [])
|
| 233 |
|
| 234 |
+
status_msg = f"β
Form filled successfully!\n\n"
|
| 235 |
+
status_msg += f"π Fields filled: {total}\n"
|
| 236 |
+
|
| 237 |
+
if fields_filled:
|
| 238 |
+
status_msg += f"β {', '.join(set(fields_filled))}\n\n"
|
| 239 |
+
|
| 240 |
+
if debug_info:
|
| 241 |
+
status_msg += f"Debug info:\n" + "\n".join([f" β’ {info}" for info in debug_info[:10]])
|
| 242 |
+
|
| 243 |
+
status_msg += f"\n\nπ₯ Download the filled form below"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
|
| 245 |
return status_msg, output_path
|
| 246 |
else:
|
|
|
|
| 333 |
with gr.Tab("π Form Filler"):
|
| 334 |
with gr.Group():
|
| 335 |
gr.Markdown("""
|
| 336 |
+
### β¨ Auto Form Filler
|
| 337 |
+
|
| 338 |
+
**Instructions:**
|
| 339 |
+
1. Upload your form template (.docx or .xlsx)
|
| 340 |
+
2. Enter field values using the format below
|
| 341 |
+
3. Click "Fill Form" and download the result
|
| 342 |
|
| 343 |
+
**Format (one field per line):**
|
| 344 |
+
```
|
| 345 |
+
Field Label: Value
|
| 346 |
+
```
|
| 347 |
|
| 348 |
+
**Example for membership form:**
|
| 349 |
```
|
| 350 |
+
First Name: John
|
| 351 |
+
Last Name: Doe
|
| 352 |
+
Cell Phone: +1-555-1234
|
| 353 |
+
Work Phone: +1-555-5678
|
| 354 |
+
Email: john@example.com
|
| 355 |
+
Membership fee: 1000
|
| 356 |
```
|
| 357 |
""")
|
| 358 |
|
| 359 |
+
template = gr.File(label="π Upload Template (.docx or .xlsx)")
|
| 360 |
form_text = gr.Textbox(
|
| 361 |
lines=10,
|
| 362 |
+
label="π Enter Field Data",
|
| 363 |
+
placeholder="First Name: John\nLast Name: Doe\nCell Phone: +1-555-1234\nWork Phone: +1-555-5678\nEmail: john@example.com\nMembership fee: 1000",
|
| 364 |
value=""
|
| 365 |
)
|
| 366 |
|
| 367 |
+
btn3 = gr.Button("Fill Form", variant="primary", size="lg")
|
| 368 |
+
status2 = gr.Textbox(label="Status", lines=6)
|
| 369 |
+
file2 = gr.File(label="π₯ Download Filled Form")
|
| 370 |
|
| 371 |
btn3.click(fill_form_ui, inputs=[template, form_text], outputs=[status2, file2])
|
| 372 |
|