Fix: Add Streamlit config and improve file upload methods
Browse files- .streamlit/config.toml +11 -0
- app.py +39 -19
.streamlit/config.toml
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[server]
|
| 2 |
+
enableCORS = false
|
| 3 |
+
enableXsrfProtection = false
|
| 4 |
+
maxUploadSize = 200
|
| 5 |
+
fileWatcherType = "none"
|
| 6 |
+
|
| 7 |
+
[browser]
|
| 8 |
+
gatherUsageStats = false
|
| 9 |
+
|
| 10 |
+
[global]
|
| 11 |
+
dataFrameSerialization = "legacy"
|
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import numpy as np
|
|
| 5 |
import jellyfish # For quick string similarity (Levenshtein, Jaro, etc.)
|
| 6 |
import io
|
| 7 |
import uuid
|
|
|
|
| 8 |
|
| 9 |
from st_link_analysis import st_link_analysis, NodeStyle, EdgeStyle
|
| 10 |
|
|
@@ -39,8 +40,7 @@ uploaded_file = st.sidebar.file_uploader(
|
|
| 39 |
type=["csv"],
|
| 40 |
help="Drag and drop your CSV file here or click to browse",
|
| 41 |
accept_multiple_files=False,
|
| 42 |
-
key="csv_uploader"
|
| 43 |
-
label_visibility="visible"
|
| 44 |
)
|
| 45 |
|
| 46 |
# File upload status info
|
|
@@ -57,23 +57,43 @@ if 'last_uploaded_file' not in st.session_state:
|
|
| 57 |
|
| 58 |
# Enhanced file upload processing
|
| 59 |
if uploaded_file is not None:
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
# Manual processing button as backup
|
| 79 |
if uploaded_file is not None and st.session_state.uploaded_data_df is None:
|
|
|
|
| 5 |
import jellyfish # For quick string similarity (Levenshtein, Jaro, etc.)
|
| 6 |
import io
|
| 7 |
import uuid
|
| 8 |
+
from io import BytesIO
|
| 9 |
|
| 10 |
from st_link_analysis import st_link_analysis, NodeStyle, EdgeStyle
|
| 11 |
|
|
|
|
| 40 |
type=["csv"],
|
| 41 |
help="Drag and drop your CSV file here or click to browse",
|
| 42 |
accept_multiple_files=False,
|
| 43 |
+
key="csv_uploader"
|
|
|
|
| 44 |
)
|
| 45 |
|
| 46 |
# File upload status info
|
|
|
|
| 57 |
|
| 58 |
# Enhanced file upload processing
|
| 59 |
if uploaded_file is not None:
|
| 60 |
+
# Check if this is a new file
|
| 61 |
+
file_id = f"{uploaded_file.name}_{uploaded_file.size}"
|
| 62 |
+
|
| 63 |
+
if 'current_file_id' not in st.session_state:
|
| 64 |
+
st.session_state.current_file_id = None
|
| 65 |
+
|
| 66 |
+
# Only process if it's a new file
|
| 67 |
+
if st.session_state.current_file_id != file_id:
|
| 68 |
+
try:
|
| 69 |
+
st.sidebar.info("π Processing uploaded file...")
|
| 70 |
+
|
| 71 |
+
# Try reading the file with different methods
|
| 72 |
+
try:
|
| 73 |
+
# Method 1: Direct read
|
| 74 |
+
df = pd.read_csv(uploaded_file)
|
| 75 |
+
except:
|
| 76 |
+
# Method 2: Read as bytes then convert
|
| 77 |
+
bytes_data = uploaded_file.getvalue()
|
| 78 |
+
df = pd.read_csv(io.BytesIO(bytes_data))
|
| 79 |
+
|
| 80 |
+
# Store in session state
|
| 81 |
+
st.session_state.uploaded_data_df = df
|
| 82 |
+
st.session_state.last_uploaded_file = uploaded_file.name
|
| 83 |
+
st.session_state.current_file_id = file_id
|
| 84 |
+
|
| 85 |
+
st.sidebar.success(f"β
**File loaded successfully!**")
|
| 86 |
+
st.sidebar.success(f"π **{uploaded_file.name}** ({len(df)} rows, {len(df.columns)} columns)")
|
| 87 |
+
|
| 88 |
+
except Exception as e:
|
| 89 |
+
st.sidebar.error(f"β **Error reading file:** {str(e)}")
|
| 90 |
+
st.sidebar.info("π‘ Try the 'Process Uploaded File' button below")
|
| 91 |
+
st.session_state.uploaded_data_df = None
|
| 92 |
+
else:
|
| 93 |
+
# File already processed
|
| 94 |
+
if st.session_state.uploaded_data_df is not None:
|
| 95 |
+
st.sidebar.success(f"β
**File already loaded:** {uploaded_file.name}")
|
| 96 |
+
st.sidebar.info(f"π {len(st.session_state.uploaded_data_df)} rows, {len(st.session_state.uploaded_data_df.columns)} columns")
|
| 97 |
|
| 98 |
# Manual processing button as backup
|
| 99 |
if uploaded_file is not None and st.session_state.uploaded_data_df is None:
|