File size: 931 Bytes
77e952c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from transformers import pipeline

# Load the Hugging Face model for question answering
qa_model = pipeline("question-answering")

# Function to handle PDF input and return chatbot responses
def chatbot_function(pdf_file):
    # Your PDF processing logic here
    # For simplicity, let's assume you convert the PDF to text
    with open(pdf_file, "r", encoding="utf-8") as file:
        pdf_text = file.read()

    # Use the question answering model to get responses
    question = "What is your question?"
    answer = qa_model(question=question, context=pdf_text)

    return answer["answer"]

# Gradio Interface
iface = gr.Interface(
    fn=chatbot_function,
    inputs=gr.File(type="file", label="Upload PDF File"),
    outputs="text",
    live=True,
    title="Chatbot for PDF Documents",
    description="Upload a PDF document and ask questions to the chatbot.",
)

# Launch the Gradio app
iface.launch()