Spaces:
Running
Running
fix pb with reading csv
Browse files
app.py
CHANGED
|
@@ -459,8 +459,21 @@ else:
|
|
| 459 |
"After upload, you’ll be able to choose which text column to analyse."
|
| 460 |
)
|
| 461 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 462 |
if up is not None:
|
| 463 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 464 |
if tmp_df.empty:
|
| 465 |
st.error("Uploaded CSV is empty.")
|
| 466 |
st.stop()
|
|
|
|
| 459 |
"After upload, you’ll be able to choose which text column to analyse."
|
| 460 |
)
|
| 461 |
|
| 462 |
+
# if up is not None:
|
| 463 |
+
# tmp_df = pd.read_csv(up)
|
| 464 |
+
# if tmp_df.empty:
|
| 465 |
+
# st.error("Uploaded CSV is empty.")
|
| 466 |
+
# st.stop()
|
| 467 |
+
|
| 468 |
if up is not None:
|
| 469 |
+
try:
|
| 470 |
+
# Try loading as standard UTF-8
|
| 471 |
+
tmp_df = pd.read_csv(up)
|
| 472 |
+
except UnicodeDecodeError:
|
| 473 |
+
# If that fails (e.g., Excel/Windows CSV), try ISO-8859-1 (Latin-1)
|
| 474 |
+
up.seek(0) # Reset file pointer to the beginning
|
| 475 |
+
tmp_df = pd.read_csv(up, encoding='ISO-8859-1')
|
| 476 |
+
|
| 477 |
if tmp_df.empty:
|
| 478 |
st.error("Uploaded CSV is empty.")
|
| 479 |
st.stop()
|