SujathaL's picture
Update app.py
9e5a092 verified
raw
history blame
1.08 kB
import streamlit as st
from transformers import pipeline
import requests
from PyPDF2 import PdfReader
# Load Hugging Face Question Answering model
qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad")
# Function to download and extract text from PDF
def extract_text_from_huggingface_pdf(url):
response = requests.get(url)
with open("document.pdf", "wb") as f:
f.write(response.content)
pdf_reader = PdfReader("document.pdf")
text = ""
for page in pdf_reader.pages:
text += page.extract_text() + "\n"
return text
# Hugging Face URL
PDF_URL = "https://huggingface.co/spaces/SujathaL/AWS_Restart_Program_Chatbot/blob/main/AWS%20restart%20program%20information.docx.pdf"
pdf_text = extract_text_from_huggingface_pdf(PDF_URL)
# Streamlit UI
st.title("Chat with Your PDF")
# User Question Input
question = st.text_input("Ask a question about the PDF:")
if st.button("Get Answer") and question:
response = qa_pipeline(question=question, context=pdf_text)
st.write("Answer:", response['answer'])