ML / app.py
saikumar27's picture
Update app.py
aa0f37c verified
Raw History Blame Contribute Delete
1.25 kB
import streamlit as st
import pandas as pd
# Function to read uploaded file
def load_data(uploaded_file):
file_extension = uploaded_file.name.split(".")[-1].lower()
try:
if file_extension == "csv":
return pd.read_csv(uploaded_file)
elif file_extension in ["xls", "xlsx"]:
return pd.read_excel(uploaded_file, engine="openpyxl")
elif file_extension == "xml":
return pd.read_xml(uploaded_file)
elif file_extension == "txt":
return pd.read_csv(uploaded_file, delimiter="\t", header=None, error_bad_lines=False)
else:
st.error("Unsupported file format!")
return None
except Exception as e:
st.error(f"Error reading file: {e}")
return None
# Streamlit UI
st.title("ML Model File Uploader")
st.write("Upload a dataset in CSV, Excel, XML, or TXT format.")
uploaded_file = st.file_uploader("Upload a dataset", type=["csv", "xls", "xlsx", "xml", "txt"])
if uploaded_file is not None:
df = load_data(uploaded_file)
if df is not None and not df.empty:
st.write("### Data Preview")
st.dataframe(df.head())
else:
st.warning("The uploaded file is empty or could not be read.")