Hoctar77 commited on
Commit
3e7c878
Β·
verified Β·
1 Parent(s): 7b8b97c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +138 -123
app.py CHANGED
@@ -2334,150 +2334,165 @@ def create_interface():
2334
  template_types = ["Short AC template AC", "Long AC template AC"]
2335
 
2336
  def format_results_as_html(text_results):
2337
- """Convert the text results into styled HTML."""
2338
- if not text_results:
2339
- return """
2340
- <div class="p-4 text-gray-600">
2341
- Results will appear here after processing...
2342
- </div>
2343
- """
2344
-
2345
- # Split into sections
2346
- sections = text_results.split('β– ')
2347
- header = sections[0]
2348
- issues = sections[1:]
2349
-
2350
- # Format header
2351
- header_html = f"""
2352
- <div class="max-w-4xl mx-auto p-4 bg-white rounded-lg shadow-sm mb-6">
2353
- <h1 class="text-2xl font-bold text-gray-800 mb-4">Document Check Results Summary</h1>
2354
- <div class="text-lg {'text-green-600' if 'All checks passed' in header else 'text-amber-600'}">
2355
- {header.strip()}
2356
- </div>
2357
  </div>
2358
  """
2359
-
2360
- # Format each issue section
2361
- issues_html = ""
2362
- for section in issues:
2363
- if not section.strip():
2364
- continue
2365
-
2366
- lines = section.strip().split('\n')
2367
- title = lines[0]
2368
- content = '\n'.join(lines[1:])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2369
 
2370
- # Split content into description, how to fix, and examples
2371
- parts = content.split('Example Fix:')
2372
- description = parts[0]
2373
- examples = parts[1] if len(parts) > 1 else ""
2374
 
2375
- issues_html += f"""
2376
- <div class="bg-white rounded-lg shadow-sm mb-6 overflow-hidden">
2377
- <div class="bg-gray-50 px-6 py-4 border-b">
2378
- <h2 class="text-lg font-semibold text-gray-800">{title.strip()}</h2>
2379
- </div>
2380
-
2381
- <div class="px-6 py-4">
2382
- <div class="text-gray-600 mb-4">
2383
- {description.strip()}
2384
- </div>
2385
-
2386
- <div class="bg-green-50 rounded p-4 mb-4">
2387
- <div class="text-green-800">
2388
- <span class="font-medium">How to fix:</span>
2389
- {description.split('How to fix:')[1].strip() if 'How to fix:' in description else ''}
2390
- </div>
2391
- </div>
2392
- """
2393
 
2394
- if examples:
2395
- examples_lines = examples.strip().split('\n')
2396
- issues_html += """
2397
  <div class="mb-4">
2398
  <h3 class="font-medium text-gray-800 mb-2">Examples:</h3>
2399
  <div class="space-y-2 ml-4">
2400
- """
2401
-
2402
- for line in examples_lines:
2403
- line = line.strip()
2404
- if line.startswith('❌'):
2405
- issues_html += f"""
2406
  <div class="text-red-600">
2407
  <span class="inline-block w-4">❌</span>
2408
- {line.replace('❌ Incorrect:', '').strip()}
2409
  </div>
2410
- """
2411
- elif line.startswith('βœ“'):
2412
- issues_html += f"""
2413
  <div class="text-green-600">
2414
  <span class="inline-block w-4">βœ“</span>
2415
- {line.replace('βœ“ Correct :', '').strip()}
2416
- </div>
2417
- """
2418
- elif line.startswith('β€’'):
2419
- issues_html += f"""
2420
- <div class="text-gray-600 ml-4">
2421
- β€’ {line.replace('β€’', '').strip()}
2422
  </div>
2423
- """
2424
- elif 'more similar issues' in line:
2425
- issues_html += f"""
2426
- <div class="text-gray-500 italic mt-2">
2427
- {line.strip()}
2428
- </div>
2429
- """
2430
-
2431
- issues_html += """
2432
  </div>
2433
  </div>
2434
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2435
 
2436
- issues_html += """
 
 
2437
  </div>
 
 
 
 
 
 
 
 
 
 
2438
  </div>
2439
- """
2440
-
2441
- # Combine all HTML
2442
- full_html = f"""
2443
- <div class="mx-auto p-4" style="font-family: system-ui, -apple-system, sans-serif;">
2444
- <style>
2445
- .text-2xl {{ font-size: 1.5rem; }}
2446
- .text-lg {{ font-size: 1.125rem; }}
2447
- .font-bold {{ font-weight: 700; }}
2448
- .font-semibold {{ font-weight: 600; }}
2449
- .font-medium {{ font-weight: 500; }}
2450
- .text-gray-800 {{ color: #1f2937; }}
2451
- .text-gray-600 {{ color: #4b5563; }}
2452
- .text-gray-500 {{ color: #6b7280; }}
2453
- .text-green-600 {{ color: #059669; }}
2454
- .text-green-800 {{ color: #065f46; }}
2455
- .text-red-600 {{ color: #dc2626; }}
2456
- .text-amber-600 {{ color: #d97706; }}
2457
- .bg-white {{ background-color: #ffffff; }}
2458
- .bg-gray-50 {{ background-color: #f9fafb; }}
2459
- .bg-green-50 {{ background-color: #ecfdf5; }}
2460
- .rounded-lg {{ border-radius: 0.5rem; }}
2461
- .shadow-sm {{ box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05); }}
2462
- .mb-6 {{ margin-bottom: 1.5rem; }}
2463
- .mb-4 {{ margin-bottom: 1rem; }}
2464
- .mb-2 {{ margin-bottom: 0.5rem; }}
2465
- .ml-4 {{ margin-left: 1rem; }}
2466
- .mt-2 {{ margin-top: 0.5rem; }}
2467
- .p-4 {{ padding: 1rem; }}
2468
- .px-6 {{ padding-left: 1.5rem; padding-right: 1.5rem; }}
2469
- .py-4 {{ padding-top: 1rem; padding-bottom: 1rem; }}
2470
- .space-y-2 > * + * {{ margin-top: 0.5rem; }}
2471
- .italic {{ font-style: italic; }}
2472
- .border-b {{ border-bottom: 1px solid #e5e7eb; }}
2473
- .overflow-hidden {{ overflow: hidden; }}
2474
- </style>
2475
- {header_html}
2476
- {issues_html}
2477
- </div>
2478
  """
2479
-
2480
- return full_html
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2481
 
2482
  with gr.Blocks() as demo:
2483
  gr.Markdown(
 
2334
  template_types = ["Short AC template AC", "Long AC template AC"]
2335
 
2336
  def format_results_as_html(text_results):
2337
+ """Convert the text results into styled HTML."""
2338
+ if not text_results:
2339
+ return """
2340
+ <div class="p-4 text-gray-600">
2341
+ Results will appear here after processing...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2342
  </div>
2343
  """
2344
+
2345
+ # Remove ANSI color codes
2346
+ ansi_escape = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
2347
+ text_results = ansi_escape.sub('', text_results)
2348
+
2349
+ # Split into sections while preserving the header
2350
+ sections = text_results.split('β– ')
2351
+ header = sections[0].strip()
2352
+ issues = sections[1:]
2353
+
2354
+ # Format header
2355
+ header_html = f"""
2356
+ <div class="max-w-4xl mx-auto p-4 bg-white rounded-lg shadow-sm mb-6">
2357
+ <h1 class="text-2xl font-bold text-gray-800 mb-4">Document Check Results Summary</h1>
2358
+ <div class="text-lg {'text-green-600' if 'All checks passed' in header else 'text-amber-600'}">
2359
+ {header.strip()}
2360
+ </div>
2361
+ </div>
2362
+ """
2363
+
2364
+ # Format each issue section
2365
+ issues_html = ""
2366
+ for section in issues:
2367
+ if not section.strip():
2368
+ continue
2369
 
2370
+ # Split the section into title and content
2371
+ parts = section.strip().split('\n', 1)
2372
+ if len(parts) < 2:
2373
+ continue
2374
 
2375
+ title = parts[0].strip()
2376
+ content = parts[1].strip()
2377
+
2378
+ # Extract description and solution
2379
+ description_parts = content.split('How to fix:', 1)
2380
+ description = description_parts[0].strip()
2381
+ solution = description_parts[1].split('Examples:', 1)[0].strip() if len(description_parts) > 1 else ""
2382
+
2383
+ # Extract examples and issues
2384
+ examples_match = re.search(r'Examples:\s*\n\s*❌[^βœ“]+βœ“[^β€’]+', content, re.MULTILINE | re.DOTALL)
2385
+ examples_html = ""
2386
+ if examples_match:
2387
+ examples_text = examples_match.group(0)
2388
+ incorrect = re.search(r'❌\s*([^βœ“]+)', examples_text)
2389
+ correct = re.search(r'βœ“\s*([^β€’\n]+)', examples_text)
 
 
 
2390
 
2391
+ if incorrect and correct:
2392
+ examples_html = f"""
 
2393
  <div class="mb-4">
2394
  <h3 class="font-medium text-gray-800 mb-2">Examples:</h3>
2395
  <div class="space-y-2 ml-4">
 
 
 
 
 
 
2396
  <div class="text-red-600">
2397
  <span class="inline-block w-4">❌</span>
2398
+ {incorrect.group(1).strip()}
2399
  </div>
 
 
 
2400
  <div class="text-green-600">
2401
  <span class="inline-block w-4">βœ“</span>
2402
+ {correct.group(1).strip()}
 
 
 
 
 
 
2403
  </div>
 
 
 
 
 
 
 
 
 
2404
  </div>
2405
  </div>
2406
  """
2407
+
2408
+ # Extract issues
2409
+ issues_match = re.findall(r'β€’\s*([^β€’\n]+)', content)
2410
+ issues_html_section = ""
2411
+ if issues_match:
2412
+ issues_html_section = """
2413
+ <div class="mt-4">
2414
+ <h3 class="font-medium text-gray-800 mb-2">Issues found in your document:</h3>
2415
+ <div class="space-y-2">
2416
+ """
2417
+ for i, issue in enumerate(issues_match[:3]):
2418
+ issues_html_section += f"""
2419
+ <div class="text-gray-600 ml-4">
2420
+ β€’ {issue.strip()}
2421
+ </div>
2422
+ """
2423
+ if len(issues_match) > 3:
2424
+ issues_html_section += f"""
2425
+ <div class="text-gray-500 italic ml-4">
2426
+ ...and {len(issues_match) - 3} more similar issues
2427
+ </div>
2428
+ """
2429
+ issues_html_section += "</div></div>"
2430
+
2431
+ # Combine the section
2432
+ issues_html += f"""
2433
+ <div class="bg-white rounded-lg shadow-sm mb-6 overflow-hidden">
2434
+ <div class="bg-gray-50 px-6 py-4 border-b">
2435
+ <h2 class="text-lg font-semibold text-gray-800">{title}</h2>
2436
+ </div>
2437
 
2438
+ <div class="px-6 py-4">
2439
+ <div class="text-gray-600 mb-4">
2440
+ {description}
2441
  </div>
2442
+
2443
+ <div class="bg-green-50 rounded p-4 mb-4">
2444
+ <div class="text-green-800">
2445
+ <span class="font-medium">How to fix: </span>
2446
+ {solution}
2447
+ </div>
2448
+ </div>
2449
+
2450
+ {examples_html}
2451
+ {issues_html_section}
2452
  </div>
2453
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2454
  """
2455
+
2456
+ # Final HTML with styling
2457
+ full_html = f"""
2458
+ <div class="mx-auto p-4" style="font-family: system-ui, -apple-system, sans-serif;">
2459
+ <style>
2460
+ .text-2xl {{ font-size: 1.5rem; }}
2461
+ .text-lg {{ font-size: 1.125rem; }}
2462
+ .font-bold {{ font-weight: 700; }}
2463
+ .font-semibold {{ font-weight: 600; }}
2464
+ .font-medium {{ font-weight: 500; }}
2465
+ .text-gray-800 {{ color: #1f2937; }}
2466
+ .text-gray-600 {{ color: #4b5563; }}
2467
+ .text-gray-500 {{ color: #6b7280; }}
2468
+ .text-green-600 {{ color: #059669; }}
2469
+ .text-green-800 {{ color: #065f46; }}
2470
+ .text-red-600 {{ color: #dc2626; }}
2471
+ .text-amber-600 {{ color: #d97706; }}
2472
+ .bg-white {{ background-color: #ffffff; }}
2473
+ .bg-gray-50 {{ background-color: #f9fafb; }}
2474
+ .bg-green-50 {{ background-color: #ecfdf5; }}
2475
+ .rounded-lg {{ border-radius: 0.5rem; }}
2476
+ .shadow-sm {{ box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05); }}
2477
+ .mb-6 {{ margin-bottom: 1.5rem; }}
2478
+ .mb-4 {{ margin-bottom: 1rem; }}
2479
+ .mb-2 {{ margin-bottom: 0.5rem; }}
2480
+ .ml-4 {{ margin-left: 1rem; }}
2481
+ .mt-2 {{ margin-top: 0.5rem; }}
2482
+ .p-4 {{ padding: 1rem; }}
2483
+ .px-6 {{ padding-left: 1.5rem; padding-right: 1.5rem; }}
2484
+ .py-4 {{ padding-top: 1rem; padding-bottom: 1rem; }}
2485
+ .space-y-2 > * + * {{ margin-top: 0.5rem; }}
2486
+ .italic {{ font-style: italic; }}
2487
+ .border-b {{ border-bottom: 1px solid #e5e7eb; }}
2488
+ .overflow-hidden {{ overflow: hidden; }}
2489
+ </style>
2490
+ {header_html}
2491
+ {issues_html}
2492
+ </div>
2493
+ """
2494
+
2495
+ return full_html
2496
 
2497
  with gr.Blocks() as demo:
2498
  gr.Markdown(