File size: 2,032 Bytes
12d2529
706a020
12d2529
706a020
 
12d2529
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import gradio as gr
from annotations import analyze_pdf
import base64
import io

def process_pdf(file):
    if file is None:
        return {"error": "No file uploaded."}, None

    # Analyze the PDF
    issues, annotated_pdf = analyze_pdf(file)

    if "error" in issues:
        return issues, None

    # Prepare issues for display
    issues_display = f"Total Issues Found: {issues['total_issues']}\n\n"
    for idx, issue in enumerate(issues['issues'], start=1):
        issues_display += f"Issue {idx}:\n"
        issues_display += f"Message: {issue['message']}\n"
        issues_display += f"Context: {issue['context']}\n"
        issues_display += f"Suggestions: {', '.join(issue['suggestions']) if issue['suggestions'] else 'None'}\n"
        issues_display += f"Category: {issue['category']}\n"
        issues_display += f"Rule ID: {issue['rule_id']}\n"
        issues_display += f"Offset: {issue['offset']}\n"
        issues_display += f"Length: {issue['length']}\n\n"

    # Prepare annotated PDF for download
    if annotated_pdf:
        annotated_pdf_base64 = base64.b64encode(annotated_pdf).decode('utf-8')
        annotated_pdf_link = f"data:application/pdf;base64,{annotated_pdf_base64}"
    else:
        annotated_pdf_link = None

    return issues_display, annotated_pdf_link

def download_annotated_pdf(annotated_pdf_link):
    return annotated_pdf_link

with gr.Blocks() as demo:
    gr.Markdown("# PDF Language Issue Analyzer")
    gr.Markdown("Upload a PDF to analyze language issues and receive an annotated PDF.")

    with gr.Row():
        with gr.Column():
            pdf_input = gr.File(label="Upload PDF", type="file")
            analyze_button = gr.Button("Analyze PDF")
        with gr.Column():
            issues_output = gr.Textbox(label="Language Issues", lines=20)
            annotated_pdf_output = gr.File(label="Download Annotated PDF")

    analyze_button.click(
        fn=process_pdf,
        inputs=pdf_input,
        outputs=[issues_output, annotated_pdf_output]
    )

demo.launch()