Ahmad-Moiz's picture
Create app.py
f127a74
import streamlit as st
from transformers import pipeline
import PyPDF2
# Function to extract text from PDF
def extract_text_from_pdf(pdf_file):
text = ""
pdf_reader = PyPDF2.PdfReader(pdf_file)
for page_num in range(len(pdf_reader.pages)):
page = pdf_reader.getPage(page_num)
text += page.extractText()
return text
# Streamlit app
def main():
st.title('PDF Text Extraction')
uploaded_file = st.file_uploader("Upload a PDF file", type="pdf")
if uploaded_file is not None:
st.write("File uploaded successfully!")
# Extract text when file is uploaded
text = extract_text_from_pdf(uploaded_file)
st.write("### Extracted Text:")
st.write(text)
# Use Hugging Face's pipeline for further NLP tasks
st.write("### NLP Analysis:")
nlp_task = st.selectbox("Select NLP Task", ["Named Entity Recognition", "Sentiment Analysis"])
if nlp_task == "Named Entity Recognition":
ner = pipeline("ner")
entities = ner(text)
st.write(entities)
if nlp_task == "Sentiment Analysis":
sentiment_analysis = pipeline("sentiment-analysis")
sentiment = sentiment_analysis(text)
st.write(sentiment)
if __name__ == "__main__":
main()