ScientryAPI / app.py
raannakasturi's picture
Refactor summary generation functions to remove unused parameters and simplify the API
770226f
import gradio as gr
from main import main
import json
import subprocess
def installChrome():
subprocess.run(['apt-get', 'update'])
subprocess.run(['apt-get', 'install', '-y', 'wget', 'unzip'])
subprocess.run(['wget', 'https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb'])
subprocess.run(['apt-get', 'install', '-y', './google-chrome-stable_current_amd64.deb'])
subprocess.run(['rm', 'google-chrome-stable_current_amd64.deb'])
subprocess.run(['apt-get', 'clean'])
def rexplore_summarizer(url, id, access_key):
response = json.loads(main(url, id, access_key))
data = json.dumps(response, ensure_ascii=False, indent=4)
if response["mindmap_status"] != "success":
mindmap = "error"
else:
mindmap = response["mindmap"]
if response["summary_status"] != "success":
summary = "error"
else:
summary = response["summary"]
return data, summary, mindmap
def clear_everything(url, id, access_key, raw_data, summary, mindmap):
return None, None, None, None, None, None
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")
],
)
with gr.Blocks(theme=theme, title="ReXplore Summarizer", fill_height=True) as app:
gr.HTML(
value ="""
<h1 style="text-align: center;">ReXplore Summarizer <p style="text-align: center;">Designed and Developed by <a href="https://raannakasturi.eu.org" target="_blank" rel="nofollow noreferrer external">Nayan Kasturi</a></p> </h1>
<p style="text-align: center;">This app uses a hybrid approach to summarize PDF documents based on CPU as well as GPU.</p>
<p style="text-align: center;">The app uses traditional methodologies such as TextRank, LSA, Luhn algorithms as well as large language model (LLM) to generate summaries as well as mindmaps.</p>
<p style="text-align: center;">The summarization process can take some time depending on the size of the text corpus and the complexity of the content.</p>
""")
with gr.Row():
with gr.Column():
url = gr.Textbox(label="PDF URL", placeholder="Paste the PDF URL here")
id = gr.Textbox(label="DOI/arXiv ID", placeholder="Enter the DOI or arXiv ID of the Research Paper")
access_key = gr.Textbox(label="Access Key", placeholder="Enter the Access Key", type="password")
with gr.Row():
clear_btn = gr.Button(value="Clear", variant="stop")
summarize_btn = gr.Button(value="Summarize", variant="primary")
raw_data = gr.TextArea(label="Raw Data", placeholder="The generated raw data will be displayed here", lines=7, interactive=False, show_copy_button=True)
with gr.Row():
summary = gr.TextArea(label="Summary", placeholder="The generated summary will be displayed here", lines=7, interactive=False, show_copy_button=True)
mindmap = gr.TextArea(label="Mindmap", placeholder="The generated mindmap will be displayed here", lines=7, interactive=False, show_copy_button=True)
summarize_btn.click(
rexplore_summarizer,
inputs=[url, id, access_key],
outputs=[raw_data, summary, mindmap],
concurrency_limit=25,
scroll_to_output=True,
show_api=True,
api_name="rexplore_summarizer",
show_progress="full",
)
clear_btn.click(clear_everything, inputs=[url, id, raw_data, summary, mindmap, access_key], outputs=[url, id, raw_data, summary, mindmap, access_key], show_api=False)
installChrome()
app.queue(default_concurrency_limit=25).launch(show_api=True, ssr_mode=False)