Environmental_assessment_report / utils /file_processing.py
engrrifatullah's picture
Create utils/file_processing.py
d513e5c verified
raw
history blame contribute delete
753 Bytes
import pandas as pd
import PyPDF2
import streamlit as st
def process_uploaded_file(uploaded_file):
if uploaded_file.name.endswith('.csv'):
data = pd.read_csv(uploaded_file)
elif uploaded_file.name.endswith(('.xls', '.xlsx')):
data = pd.read_excel(uploaded_file)
elif uploaded_file.name.endswith('.pdf'):
reader = PyPDF2.PdfReader(uploaded_file)
text = "\n".join(page.extract_text() for page in reader.pages)
st.info("Extracted text from PDF. Please ensure it follows the expected format.")
st.text_area("Extracted Text", text, height=200)
return None
else:
st.error("Unsupported file format. Please upload a CSV, Excel, or PDF file.")
return None
return data