File size: 2,532 Bytes
9e075cc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ef651bf
 
 
 
 
 
9e075cc
 
 
 
 
 
478525f
ef651bf
 
 
 
 
 
 
9e075cc
 
 
 
ef651bf
 
 
9e075cc
ef651bf
 
9e075cc
 
 
 
 
 
 
 
 
 
ef651bf
 
9e075cc
 
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
59
60
61
62
63
64
from functools import partial
from tools import load_llm_model
import gradio as gr
from main import summarize
import subprocess
import os

theme = gr.themes.Soft(
    primary_hue="purple",
    secondary_hue="cyan",
    neutral_hue="slate",
    font=[
        gr.themes.GoogleFont('Syne'), 
        gr.themes.GoogleFont('Poppins'), 
        gr.themes.GoogleFont('Poppins'), 
        gr.themes.GoogleFont('Poppins')
    ],
)

def clear_everything(pdf_file, summary_output, info):
    pdf_file = None
    summary_output = None
    info = None
    return pdf_file, summary_output, info

print("Loading LLM model...")
llm = load_llm_model()
print("Building app...")

summarize_with_llm = partial(summarize, llm)

with gr.Blocks(theme=theme, title="Hybrid Research Paper Summarizer", fill_height=True) as app:
    gr.HTML(
        value ='''
        <h1 style="text-align: center;">Hybrid PDF Summarizer</h1>
        <p style="text-align: center;">This app uses a hybrid approach to summarize PDF documents completely based on CPU.</p>
        <p style="text-align: center;">The app uses traditional methodologies such as TextRank, LSA, Luhn algorithms as well as quantized large language model (LLM) to generate summaries of the PDF document.</p>
        <p style="text-align: center;">The summarization process can take some time depending on the size of the PDF document and the complexity of the content.</p>
        ''')
    with gr.Column():
        with gr.Row():
            pdf_file = gr.File(label="Upload PDF", file_types=['.pdf'])
            with gr.Column():
                with gr.Row():
                    summarize_btn = gr.Button(value="Summarize")
                    clear_btn = gr.Button(value="Clear")
                info = gr.Textbox(label="Summarization Info", placeholder="Details regarding summarization will be shown here", interactive=False)
        summary_output = gr.TextArea(label="PDF Summary", placeholder="The summary will be displayed here", interactive=False, show_copy_button=True)

    summarize_btn.click(
        summarize_with_llm,
        inputs=pdf_file,
        outputs=[summary_output, info],
        concurrency_limit=5,
        scroll_to_output=True,
        api_name="summarize",
        show_progress="full",
        max_batch_size=10,
    )
    clear_btn.click(clear_everything, inputs=[pdf_file, summary_output, info], outputs=[pdf_file, summary_output, info], show_api=False)

print("Build Successful. Launching app...")
app.queue(default_concurrency_limit=5).launch(show_api=True)