Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,29 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
-
import
|
| 4 |
-
from PyPDF2 import PdfReader
|
| 5 |
|
| 6 |
# Load Hugging Face Question Answering model
|
| 7 |
qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad")
|
| 8 |
|
| 9 |
-
# Function to
|
| 10 |
-
def
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
for page in pdf_reader.pages:
|
| 17 |
-
text += page.extract_text() + "\n"
|
| 18 |
return text
|
| 19 |
|
| 20 |
-
# Hugging Face URL
|
| 21 |
-
PDF_URL = "https://huggingface.co/spaces/SujathaL/AWS_Restart_Program_Chatbot/blob/main/AWS%20restart%20program%20information.docx.pdf"
|
| 22 |
-
pdf_text = extract_text_from_huggingface_pdf(PDF_URL)
|
| 23 |
-
|
| 24 |
# Streamlit UI
|
| 25 |
-
st.title("Chat with
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
# User
|
| 28 |
-
question = st.text_input("Ask a question about
|
| 29 |
|
| 30 |
if st.button("Get Answer") and question:
|
| 31 |
response = qa_pipeline(question=question, context=pdf_text)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from transformers import pipeline
|
| 3 |
+
import PyPDF2
|
|
|
|
| 4 |
|
| 5 |
# Load Hugging Face Question Answering model
|
| 6 |
qa_pipeline = pipeline("question-answering", model="distilbert-base-cased-distilled-squad")
|
| 7 |
|
| 8 |
+
# Function to extract text from PDF
|
| 9 |
+
def extract_text_from_pdf(pdf_path):
|
| 10 |
+
with open(pdf_path, "rb") as f:
|
| 11 |
+
pdf_reader = PyPDF2.PdfReader(f)
|
| 12 |
+
text = ""
|
| 13 |
+
for page in pdf_reader.pages:
|
| 14 |
+
text += page.extract_text() + "\n"
|
|
|
|
|
|
|
| 15 |
return text
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
# Streamlit UI
|
| 18 |
+
st.title("Chat with AWS Restart PDF")
|
| 19 |
+
|
| 20 |
+
# Use the uploaded PDF file
|
| 21 |
+
pdf_path = "AWS restart program information.docx.pdf" # Update with your file name
|
| 22 |
+
pdf_text = extract_text_from_pdf(pdf_path)
|
| 23 |
+
st.write("✅ PDF Loaded Successfully!")
|
| 24 |
|
| 25 |
+
# User Input
|
| 26 |
+
question = st.text_input("Ask a question about AWS Restart program:")
|
| 27 |
|
| 28 |
if st.button("Get Answer") and question:
|
| 29 |
response = qa_pipeline(question=question, context=pdf_text)
|