Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,55 @@
|
|
1 |
import google.generativeai as genai
|
2 |
import gradio as gr
|
3 |
-
|
4 |
-
import PIL.Image
|
5 |
|
6 |
-
|
7 |
|
8 |
-
|
9 |
|
10 |
-
|
11 |
-
model = genai.GenerativeModel("gemini-1.5-flash")
|
12 |
|
13 |
-
|
14 |
-
if isinstance(image, np.ndarray):
|
15 |
|
16 |
-
|
17 |
-
else:
|
18 |
-
img = PIL.Image.open(image)
|
19 |
|
20 |
-
|
21 |
|
22 |
-
|
|
|
23 |
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
outputs = gr.Text(label = "Story"),
|
28 |
-
examples = ["rubiks cube.jpg","giraffe.jpg","street.jpg"],
|
29 |
-
title = "Image-To-Story",
|
30 |
-
theme = "patrickosornio/my_theme1")
|
31 |
|
|
|
|
|
32 |
|
33 |
-
|
|
|
|
|
|
|
34 |
|
|
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import google.generativeai as genai
|
2 |
import gradio as gr
|
3 |
+
from pypdf import PdfReader
|
|
|
4 |
|
5 |
+
def pdfSummarizer(gemini_api_key, pdf_file, kind):
|
6 |
|
7 |
+
gemini_api_key = gemini_api_key
|
8 |
|
9 |
+
genai.configure(api_key = gemini_api_key)
|
|
|
10 |
|
11 |
+
model = genai.GenerativeModel("gemini-1.5-pro")
|
|
|
12 |
|
13 |
+
pdf_file = PdfReader(pdf_file)
|
|
|
|
|
14 |
|
15 |
+
pdf_text = ""
|
16 |
|
17 |
+
for page in pdf_file.pages:
|
18 |
+
pdf_text += page.extract_text()
|
19 |
|
20 |
+
if kind == "5 Bullet Points":
|
21 |
+
response = model.generate_content([pdf_text, "can you summarize this document in 5 bullet points? Use bullet points and not asterisks"])
|
22 |
|
23 |
+
elif kind == "10 Bullet Points":
|
24 |
+
response = model.generate_content([pdf_text, "can you summarize this document in 10 bullet points? Use bullet points and not asterisks"])
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
elif kind == "Paragraph":
|
27 |
+
response = model.generate_content([pdf_text, "can you summarize this document as a paragraph?"])
|
28 |
|
29 |
+
elif kind == "Sentence":
|
30 |
+
response = model.generate_content([pdf_text, "can you summarize this document in one sentence?"])
|
31 |
+
|
32 |
+
return response.text
|
33 |
|
34 |
+
import gradio as gr
|
35 |
|
36 |
+
with gr.Blocks(
|
37 |
+
theme="gstaff/whiteboard",
|
38 |
+
title="PDF Summarizer",
|
39 |
+
analytics_enabled=True,
|
40 |
+
fill_height=True
|
41 |
+
) as app:
|
42 |
+
gr.Markdown("<center><h2>PDF Summarizer</h2></center>")
|
43 |
+
with gr.Row():
|
44 |
+
inp = [
|
45 |
+
gr.Text(label="Gemini API Key", placeholder="Enter your Google Gemini API key here"),
|
46 |
+
gr.File(file_types=[".pdf"]),
|
47 |
+
gr.Radio(["5 Bullet Points","10 Bullet Points", "Paragraph", "Sentence"], label="Select Summary Kind")
|
48 |
+
]
|
49 |
+
btn = gr.Button("Summarize")
|
50 |
+
with gr.Column():
|
51 |
+
out = gr.Text(label="Response")
|
52 |
+
|
53 |
+
btn.click(fn=pdfSummarizer, inputs=inp, outputs=out)
|
54 |
+
|
55 |
+
app.launch()
|