raannakasturi's picture
Update app.py
478525f verified
raw
history blame
2.53 kB
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)