Spaces:
Running
Running
| import google.generativeai as genai | |
| import gradio as gr | |
| from pypdf import PdfReader | |
| def pdfSummarizer(gemini_api_key, pdf_file, kind): | |
| gemini_api_key = gemini_api_key | |
| genai.configure(api_key = gemini_api_key) | |
| model = genai.GenerativeModel("gemini-1.5-pro") | |
| pdf_file = PdfReader(pdf_file) | |
| pdf_text = "" | |
| for page in pdf_file.pages: | |
| pdf_text += page.extract_text() | |
| if kind == "5 Bullet Points": | |
| response = model.generate_content([pdf_text, "can you summarize this document in 5 bullet points? Use bullet points and not asterisks"]) | |
| elif kind == "10 Bullet Points": | |
| response = model.generate_content([pdf_text, "can you summarize this document in 10 bullet points? Use bullet points and not asterisks"]) | |
| elif kind == "Paragraph": | |
| response = model.generate_content([pdf_text, "can you summarize this document as a paragraph?"]) | |
| elif kind == "Sentence": | |
| response = model.generate_content([pdf_text, "can you summarize this document in one sentence?"]) | |
| return response.text | |
| import gradio as gr | |
| with gr.Blocks( | |
| theme="gstaff/whiteboard", | |
| title="PDF Summarizer", | |
| analytics_enabled=True, | |
| fill_height=True | |
| ) as app: | |
| gr.Markdown("<center><h2>PDF Summarizer</h2></center>") | |
| with gr.Row(): | |
| inp = [ | |
| gr.Text(label="Gemini API Key", placeholder="Enter your Google Gemini API key here"), | |
| gr.File(file_types=[".pdf"]), | |
| gr.Radio(["5 Bullet Points","10 Bullet Points", "Paragraph", "Sentence"], label="Select Summary Kind") | |
| ] | |
| btn = gr.Button("Summarize") | |
| with gr.Column(): | |
| out = gr.Text(label="Response") | |
| btn.click(fn=pdfSummarizer, inputs=inp, outputs=out) | |
| app.launch() | |