SujathaL commited on
Commit
3a62d0c
·
verified ·
1 Parent(s): ece22cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -18
app.py CHANGED
@@ -1,31 +1,29 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
- import requests
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 download and extract text from PDF
10
- def extract_text_from_huggingface_pdf(url):
11
- response = requests.get(url)
12
- with open("document.pdf", "wb") as f:
13
- f.write(response.content)
14
- pdf_reader = PdfReader("document.pdf")
15
- text = ""
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 Your PDF")
 
 
 
 
 
26
 
27
- # User Question Input
28
- question = st.text_input("Ask a question about the PDF:")
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)