Spaces:
Runtime error
Runtime error
File size: 1,246 Bytes
a6c3352 e6dae60 a6c3352 3f33a47 98099bd e6dae60 aa0f37c 3f33a47 5208e5b a6c3352 aa0f37c a6c3352 5208e5b aa0f37c a6c3352 aa0f37c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | 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.")
|