File size: 2,123 Bytes
bef155a
3dc74fc
08fcc8d
bef155a
08fcc8d
bef155a
08fcc8d
bef155a
08fcc8d
bef155a
08fcc8d
bef155a
08fcc8d
bef155a
08fcc8d
bef155a
08fcc8d
 
bef155a
08fcc8d
 
bef155a
08fcc8d
 
bef155a
08fcc8d
 
3dc74fc
08fcc8d
 
 
 
bef155a
08fcc8d
 
 
 
 
 
 
 
3ab6b75
 
71a8fd3
72d3fc8
3ab6b75
fc096d1
0afaeca
08fcc8d
71a8fd3
1751b9e
08fcc8d
ca41126
57c8d80
08fcc8d
71a8fd3
 
08fcc8d
 
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
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

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():
        
        api_key = gr.Text(label="Gemini API Key", placeholder="Enter your Google Gemini API key here"),
        pdf_input = gr.File(file_types=[".pdf"]),
        summary_type = gr.Radio(["5 Bullet Points","10 Bullet Points", "Paragraph", "Sentence"],value = "5 Bullet Points", label="Select Summary Kind")
        
    with gr.Column():
      with gr.Row():
        btn = gr.Button("Summarize")
        clear_btn = gr.ClearButton(value="Clear",components=[api_key, pdf_input, summary_type])

    with gr.Column():
        gr.Markdown("<center><h2>Summary Output</h2></center>")
        out = gr.Markdown()

    btn.click(fn=pdfSummarizer, inputs=[api_key, pdf_input, summary_type], outputs=out)
    # clear_btn.click(lambda: [None,None,"5 Bullet Points",""],inputs=None,outputs=[api_key, pdf_input, summary_type, out],queue=False)

app.launch()