Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,10 @@ import google.generativeai as genai
|
|
7 |
import gradio as gr
|
8 |
|
9 |
# Function for initialization
|
10 |
-
def initialize(
|
|
|
|
|
|
|
11 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
12 |
model = genai.GenerativeModel('gemini-pro')
|
13 |
model = ChatGoogleGenerativeAI(model="gemini-pro", temperature=0.3)
|
@@ -28,18 +31,21 @@ def initialize(file_path, question):
|
|
28 |
else:
|
29 |
return "Error: Unable to process the document. Please ensure the PDF file is valid."
|
30 |
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
41 |
|
42 |
-
gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="GeminiPro Q&A Bot", description="Ask questions about the uploaded PDF document.").launch()
|
43 |
|
44 |
|
45 |
|
|
|
7 |
import gradio as gr
|
8 |
|
9 |
# Function for initialization
|
10 |
+
def initialize(pdf_file, question):
|
11 |
+
with open("/tmp/uploaded_file.pdf", "wb") as f:
|
12 |
+
f.write(pdf_file.read())
|
13 |
+
file_path = "/tmp/uploaded_file.pdf"
|
14 |
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
|
15 |
model = genai.GenerativeModel('gemini-pro')
|
16 |
model = ChatGoogleGenerativeAI(model="gemini-pro", temperature=0.3)
|
|
|
31 |
else:
|
32 |
return "Error: Unable to process the document. Please ensure the PDF file is valid."
|
33 |
|
34 |
+
# Create a Gradio interface for file upload and question input
|
35 |
+
iface = gr.Interface(
|
36 |
+
fn=initialize,
|
37 |
+
inputs=[
|
38 |
+
gr.inputs.File(label="Upload PDF", type="file"),
|
39 |
+
gr.inputs.Textbox(label="Question")
|
40 |
+
],
|
41 |
+
outputs="text",
|
42 |
+
title="GeminiPro Q&A Bot",
|
43 |
+
description="Ask questions about the uploaded PDF document.",
|
44 |
+
)
|
45 |
+
|
46 |
+
# Launch the interface
|
47 |
+
iface.launch()
|
48 |
|
|
|
49 |
|
50 |
|
51 |
|