Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2334,165 +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 |
-
|
2338 |
-
|
2339 |
-
|
2340 |
-
|
2341 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2342 |
</div>
|
2343 |
"""
|
2344 |
-
|
2345 |
-
|
2346 |
-
|
2347 |
-
|
2348 |
-
|
2349 |
-
|
2350 |
-
|
2351 |
-
|
2352 |
-
|
2353 |
-
|
2354 |
-
|
2355 |
-
|
2356 |
-
|
2357 |
-
|
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 |
-
|
2376 |
-
|
2377 |
-
|
2378 |
-
|
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 |
-
|
2392 |
-
|
2393 |
-
|
2394 |
-
|
2395 |
-
|
2396 |
-
|
2397 |
-
|
2398 |
-
|
2399 |
-
|
2400 |
-
|
2401 |
-
|
2402 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2403 |
</div>
|
2404 |
</div>
|
2405 |
-
|
2406 |
-
|
2407 |
-
|
2408 |
-
|
2409 |
-
|
2410 |
-
|
2411 |
-
|
2412 |
-
|
2413 |
-
|
2414 |
-
|
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 |
-
|
2430 |
-
|
2431 |
-
|
2432 |
-
|
2433 |
-
|
2434 |
-
|
2435 |
-
|
2436 |
-
|
2437 |
-
|
2438 |
-
|
2439 |
-
|
2440 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2441 |
</div>
|
2442 |
|
2443 |
-
<div class="
|
2444 |
-
<div class="text-
|
2445 |
-
|
2446 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
2447 |
</div>
|
|
|
|
|
|
|
2448 |
</div>
|
2449 |
-
|
2450 |
-
{examples_html}
|
2451 |
-
{issues_html_section}
|
2452 |
</div>
|
2453 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2454 |
"""
|
2455 |
-
|
2456 |
-
|
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(
|
|
|
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(
|