Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from functions import extract_text_from_pdf, format_content, split_into_snippets, build_prompts
|
| 3 |
+
|
| 4 |
+
def process_inputs(pdf_file, model_choice, output_format, oauth_token: gr.OAuthToken | None = None):
|
| 5 |
+
"""Process PDF and generate summary"""
|
| 6 |
+
if oauth_token is None:
|
| 7 |
+
return "### Please log in to use this service"
|
| 8 |
+
|
| 9 |
+
if not pdf_file:
|
| 10 |
+
return "### Please upload a PDF file"
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
text = extract_text_from_pdf(pdf_file.name)
|
| 14 |
+
return f"### Processing successful with {model_choice}!"
|
| 15 |
+
except Exception as e:
|
| 16 |
+
return f"### Error: {str(e)}"
|
| 17 |
+
|
| 18 |
+
# Define core interface components
|
| 19 |
+
iface = gr.Interface(
|
| 20 |
+
fn=process_inputs,
|
| 21 |
+
inputs=[
|
| 22 |
+
gr.File(
|
| 23 |
+
label="Upload PDF",
|
| 24 |
+
file_types=[".pdf"]
|
| 25 |
+
),
|
| 26 |
+
gr.Dropdown(
|
| 27 |
+
choices=[
|
| 28 |
+
"GPT-3.5",
|
| 29 |
+
"GPT-4",
|
| 30 |
+
"Claude-3",
|
| 31 |
+
"Mistral"
|
| 32 |
+
],
|
| 33 |
+
label="Model",
|
| 34 |
+
value="GPT-3.5"
|
| 35 |
+
),
|
| 36 |
+
gr.Radio(
|
| 37 |
+
choices=["TXT", "MD", "HTML"],
|
| 38 |
+
label="Format",
|
| 39 |
+
value="TXT"
|
| 40 |
+
)
|
| 41 |
+
],
|
| 42 |
+
outputs=gr.Markdown(
|
| 43 |
+
label="Output",
|
| 44 |
+
value="### Upload your PDF to begin"
|
| 45 |
+
),
|
| 46 |
+
flagging_mode="never",
|
| 47 |
+
css="""
|
| 48 |
+
.gradio-container {
|
| 49 |
+
max-width: 800px !important;
|
| 50 |
+
margin: 0 auto !important;
|
| 51 |
+
}
|
| 52 |
+
.container {
|
| 53 |
+
max-width: 800px !important;
|
| 54 |
+
margin: 0 auto !important;
|
| 55 |
+
padding: 2rem !important;
|
| 56 |
+
}
|
| 57 |
+
"""
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
# Create main app
|
| 61 |
+
with gr.Blocks(theme=gr.themes.Default()) as demo:
|
| 62 |
+
gr.Markdown("## π PDF to LLM Summarizer")
|
| 63 |
+
|
| 64 |
+
with gr.Row():
|
| 65 |
+
with gr.Column():
|
| 66 |
+
gr.Markdown("π Extract and summarize text from PDFs using state-of-the-art language models")
|
| 67 |
+
with gr.Column():
|
| 68 |
+
gr.LoginButton(min_width=200)
|
| 69 |
+
|
| 70 |
+
iface.render()
|
| 71 |
+
|
| 72 |
+
gr.Markdown("Made with Gradio")
|
| 73 |
+
|
| 74 |
+
if __name__ == "__main__":
|
| 75 |
+
demo.launch()
|