File size: 1,405 Bytes
cc82b37
82c6cf9
cc82b37
82c6cf9
cc82b37
020ff2f
cc82b37
c0559fe
6bd6468
82c6cf9
9751da0
 
 
 
 
 
 
 
 
 
 
82c6cf9
9751da0
 
82c6cf9
 
 
 
020ff2f
6bd6468
 
82c6cf9
27f2b4b
6bd6468
 
 
 
 
 
 
82c6cf9
cc82b37
 
 
919751f
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
import os
from langchain_core.prompts import PromptTemplate
from langchain.chains.question_answering import load_qa_chain
from langchain_community.document_loaders import PyPDFLoader
import google.generativeai as genai
import gradio as gr

# Function for initialization
def initialize(pdf_file, question):
    try:
        # Access the uploaded file information from Gradio
        file_info = pdf_file

        # Check if a file was uploaded
        if file_info is not None:
            # Construct potential file path based on temporary directory and filename
            file_path = os.path.join("/tmp", file_info.name)  # Adjust temporary directory if needed
            if os.path.exists(file_path):
                # ... rest of your code for processing the PDF using the file path
            else:
                return "Error: The uploaded file could not be found."
        else:
            return "Error: No PDF file was uploaded."

    except Exception as e:
        return f"An error occurred: {e}"  # Generic error handling

# Create a Gradio interface
interface = gr.Interface(
    fn=initialize,
    inputs=[
        gr.File(label="Upload PDF"),  # No need for 'type' argument
        gr.Textbox(label="Question")
    ],
    outputs="text",
    title="GeminiPro Q&A Bot",
    description="Ask questions about the uploaded PDF document.",
)

# Launch the interface
interface.launch()