PDF-Summarizer / app.py
cstr's picture
Create app.py
38b3cc5 verified
raw
history blame
2.03 kB
import gradio as gr
from functions import extract_text_from_pdf, format_content, split_into_snippets, build_prompts
def process_inputs(pdf_file, model_choice, output_format, oauth_token: gr.OAuthToken | None = None):
"""Process PDF and generate summary"""
if oauth_token is None:
return "### Please log in to use this service"
if not pdf_file:
return "### Please upload a PDF file"
try:
text = extract_text_from_pdf(pdf_file.name)
return f"### Processing successful with {model_choice}!"
except Exception as e:
return f"### Error: {str(e)}"
# Define core interface components
iface = gr.Interface(
fn=process_inputs,
inputs=[
gr.File(
label="Upload PDF",
file_types=[".pdf"]
),
gr.Dropdown(
choices=[
"GPT-3.5",
"GPT-4",
"Claude-3",
"Mistral"
],
label="Model",
value="GPT-3.5"
),
gr.Radio(
choices=["TXT", "MD", "HTML"],
label="Format",
value="TXT"
)
],
outputs=gr.Markdown(
label="Output",
value="### Upload your PDF to begin"
),
flagging_mode="never",
css="""
.gradio-container {
max-width: 800px !important;
margin: 0 auto !important;
}
.container {
max-width: 800px !important;
margin: 0 auto !important;
padding: 2rem !important;
}
"""
)
# Create main app
with gr.Blocks(theme=gr.themes.Default()) as demo:
gr.Markdown("## πŸš€ PDF to LLM Summarizer")
with gr.Row():
with gr.Column():
gr.Markdown("πŸ“„ Extract and summarize text from PDFs using state-of-the-art language models")
with gr.Column():
gr.LoginButton(min_width=200)
iface.render()
gr.Markdown("Made with Gradio")
if __name__ == "__main__":
demo.launch()