saritha commited on
Commit
919751f
·
verified ·
1 Parent(s): 7c72397

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -4,7 +4,7 @@ from langchain.chains.question_answering import load_qa_chain
4
  from langchain.document_loaders import PyPDFLoader
5
  from langchain_google_genai import ChatGoogleGenerativeAI
6
  import google.generativeai as genai
7
- import gradio as gr
8
 
9
  # Function for initialization
10
  def initialize(file_path, question):
@@ -29,15 +29,18 @@ def initialize(file_path, question):
29
  return "Error: Unable to process the document. Please ensure the PDF file is valid."
30
 
31
  def chatbot(file):
32
- file_path = file.name
33
- question_input = file.read()
 
 
34
  return initialize(file_path, question_input)
35
 
36
  # Create Gradio interface
37
- inputs = gr.inputs.File(label="Upload PDF")
38
  outputs = gr.outputs.Textbox(label="Answer - GeminiPro")
39
 
40
  gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="GeminiPro Q&A Bot", description="Ask questions about the uploaded PDF document.").launch()
41
 
42
 
43
 
 
 
4
  from langchain.document_loaders import PyPDFLoader
5
  from langchain_google_genai import ChatGoogleGenerativeAI
6
  import google.generativeai as genai
7
+ import gradio as gr
8
 
9
  # Function for initialization
10
  def initialize(file_path, question):
 
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
 
46
+