| import streamlit as st |
| import subprocess |
|
|
| |
| 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 |
|
|
| |
| st.title("PDF Text Extractor") |
|
|
| |
| uploaded_file = st.file_uploader("Upload a PDF", type=["pdf"]) |
|
|
| |
| if uploaded_file is not None: |
| |
| try: |
| extracted_text = extract_from_pdf(uploaded_file) |
| |
| 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) |