saritha commited on
Commit
6bd6468
·
verified ·
1 Parent(s): 919751f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -12
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(file_path, question):
 
 
 
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
- def chatbot(file):
32
- file_path = "/tmp/uploaded_file.pdf"
33
- with open(file_path, "wb") as f:
34
- f.write(file.read())
35
- question_input = input("Ask about the document: ")
36
- return initialize(file_path, question_input)
37
-
38
- # Create Gradio interface
39
- inputs = gr.inputs.File(label="Upload PDF", type="file")
40
- outputs = gr.outputs.Textbox(label="Answer - GeminiPro")
 
 
 
 
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