File size: 753 Bytes
d513e5c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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