Spaces:
Running
Running
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +30 -21
src/streamlit_app.py
CHANGED
|
@@ -8,32 +8,41 @@ from sklearn.model_selection import train_test_split
|
|
| 8 |
from sklearn.preprocessing import StandardScaler
|
| 9 |
from sklearn.metrics import accuracy_score, classification_report, roc_curve, roc_auc_score, confusion_matrix
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
def data():
|
| 12 |
uploaded_data = st.file_uploader('π Upload Data File', type=['csv', 'txt', 'xlsx'])
|
| 13 |
if uploaded_data is not None:
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
df = pd.read_csv(uploaded_data, sep=None, engine='python')
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
return df
|
| 34 |
-
except Exception as e:
|
| 35 |
-
st.error(f"Error loading file: {str(e)}")
|
| 36 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
return None
|
| 38 |
|
| 39 |
@st.cache_data
|
|
|
|
| 8 |
from sklearn.preprocessing import StandardScaler
|
| 9 |
from sklearn.metrics import accuracy_score, classification_report, roc_curve, roc_auc_score, confusion_matrix
|
| 10 |
|
| 11 |
+
os.environ["STREAMLIT_BROWSER_GATHER_USAGE_STATS"] = "false"
|
| 12 |
+
os.environ["STREAMLIT_METRICS_ENABLED"] = "false"
|
| 13 |
+
os.environ["HOME"] = "/tmp"
|
| 14 |
+
os.environ["XDG_CONFIG_HOME"] = "/tmp"
|
| 15 |
+
|
| 16 |
def data():
|
| 17 |
uploaded_data = st.file_uploader('π Upload Data File', type=['csv', 'txt', 'xlsx'])
|
| 18 |
if uploaded_data is not None:
|
| 19 |
+
file_type = uploaded_data.type
|
| 20 |
+
|
| 21 |
+
if file_type == 'text/plain':
|
| 22 |
+
delimiter = st.radio('Select delimiter (separator)', [',', '\t', '|', ' ', 'Auto Detect'])
|
| 23 |
+
if delimiter == 'Auto Detect':
|
| 24 |
+
try:
|
| 25 |
df = pd.read_csv(uploaded_data, sep=None, engine='python')
|
| 26 |
+
except Exception:
|
| 27 |
+
st.error("Could not auto-detect delimiter (separator), try selecting one manually.")
|
| 28 |
+
return None
|
| 29 |
+
else:
|
| 30 |
+
df = pd.read_csv(uploaded_data, sep=delimiter)
|
| 31 |
+
|
| 32 |
+
elif file_type == 'text/csv':
|
| 33 |
+
df = pd.read_csv(uploaded_data)
|
| 34 |
+
|
| 35 |
+
elif file_type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
|
| 36 |
+
df = pd.read_excel(uploaded_data)
|
| 37 |
+
|
| 38 |
+
else:
|
| 39 |
+
st.error("Unsupported file type.")
|
|
|
|
|
|
|
|
|
|
| 40 |
return None
|
| 41 |
+
|
| 42 |
+
st.write('### π Dataset Preview')
|
| 43 |
+
st.dataframe(df.head())
|
| 44 |
+
return df
|
| 45 |
+
|
| 46 |
return None
|
| 47 |
|
| 48 |
@st.cache_data
|