Spaces:
Running
Running
File size: 2,030 Bytes
38b3cc5 |
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 65 66 67 68 69 70 71 72 73 74 75 |
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() |