Spaces:
Runtime error
Runtime error
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() | |