newspace / app.py
rboglia's picture
Update app.py
3dcd274 verified
import streamlit as st
import subprocess
# Ensure PyMuPDF is installed
try:
import fitz
except ImportError:
subprocess.run(['pip', 'install', 'PyMuPDF'])
import fitz
def extract_from_pdf(file):
doc = fitz.open(stream=file.read(), filetype="pdf")
text = ""
for page in doc:
text += page.get_text()
return text
# Streamlit interface
st.title("PDF Text Extractor")
# File uploader
uploaded_file = st.file_uploader("Upload a PDF", type=["pdf"])
# Check if a file is uploaded
if uploaded_file is not None:
# Extract text from the uploaded PDF
try:
extracted_text = extract_from_pdf(uploaded_file)
# Display the extracted text in a text area
st.text_area("Extracted Text", extracted_text, height=300)
except Exception as e:
st.error(f"An error occurred while extracting text: {e}")
else:
st.info("Please upload a PDF file.")
col1, col2 = st.columns(2)
with col1:
x = st.slider('Select a value')
st.write(x, 'squared is', x * x)
with col2:
if uploaded_file is not None:
st.write(extracted_text)