Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +6 -1
src/streamlit_app.py
CHANGED
|
@@ -41,15 +41,20 @@ def read_file(uploaded_file):
|
|
| 41 |
name = uploaded_file.name.lower()
|
| 42 |
try:
|
| 43 |
if name.endswith(('.csv', '.txt')):
|
| 44 |
-
|
|
|
|
| 45 |
elif name.endswith(('.xls', '.xlsx')):
|
| 46 |
return pd.read_excel(uploaded_file)
|
| 47 |
else:
|
| 48 |
raise ValueError("Unsupported file type. Please upload CSV or Excel.")
|
|
|
|
|
|
|
|
|
|
| 49 |
except Exception as e:
|
| 50 |
st.error(f"❌ File reading failed: {e}")
|
| 51 |
raise
|
| 52 |
|
|
|
|
| 53 |
def clean_column_name(col: str) -> str:
|
| 54 |
col = str(col).strip().lower().replace("\n", " ").replace("\t", " ")
|
| 55 |
col = "_".join(col.split())
|
|
|
|
| 41 |
name = uploaded_file.name.lower()
|
| 42 |
try:
|
| 43 |
if name.endswith(('.csv', '.txt')):
|
| 44 |
+
# ✅ FIX: Remove 'errors' argument
|
| 45 |
+
return pd.read_csv(uploaded_file, encoding="utf-8")
|
| 46 |
elif name.endswith(('.xls', '.xlsx')):
|
| 47 |
return pd.read_excel(uploaded_file)
|
| 48 |
else:
|
| 49 |
raise ValueError("Unsupported file type. Please upload CSV or Excel.")
|
| 50 |
+
except UnicodeDecodeError:
|
| 51 |
+
# fallback encoding if utf-8 fails
|
| 52 |
+
return pd.read_csv(uploaded_file, encoding="latin1")
|
| 53 |
except Exception as e:
|
| 54 |
st.error(f"❌ File reading failed: {e}")
|
| 55 |
raise
|
| 56 |
|
| 57 |
+
|
| 58 |
def clean_column_name(col: str) -> str:
|
| 59 |
col = str(col).strip().lower().replace("\n", " ").replace("\t", " ")
|
| 60 |
col = "_".join(col.split())
|