| | import streamlit as st |
| | import pandas as pd |
| | import io |
| | import traceback |
| |
|
| | st.set_page_config(page_title="Upload Debug Tool", layout="wide") |
| | st.title("π§ File Upload Debug Tool") |
| |
|
| | st.markdown(""" |
| | This tool will help us diagnose the exact upload issue. |
| | """) |
| |
|
| | |
| | if 'debug_info' not in st.session_state: |
| | st.session_state.debug_info = [] |
| |
|
| | def log_debug(message): |
| | st.session_state.debug_info.append(message) |
| | st.write(f"DEBUG: {message}") |
| |
|
| | st.sidebar.header("Upload Test") |
| |
|
| | |
| | uploaded_file = st.sidebar.file_uploader( |
| | "Test File Upload", |
| | type=["csv"], |
| | key="debug_uploader" |
| | ) |
| |
|
| | if uploaded_file is not None: |
| | log_debug(f"File detected: {uploaded_file.name}") |
| | log_debug(f"File size: {uploaded_file.size} bytes") |
| | log_debug(f"File type: {uploaded_file.type}") |
| | |
| | try: |
| | |
| | log_debug("Attempting Method 1: Direct pd.read_csv()") |
| | df1 = pd.read_csv(uploaded_file) |
| | log_debug(f"SUCCESS Method 1: {len(df1)} rows, {len(df1.columns)} columns") |
| | st.success("β
Method 1 (Direct read) WORKED!") |
| | st.dataframe(df1.head()) |
| | |
| | except Exception as e: |
| | log_debug(f"FAILED Method 1: {str(e)}") |
| | st.error(f"β Method 1 failed: {str(e)}") |
| | |
| | try: |
| | |
| | log_debug("Attempting Method 2: Read as bytes") |
| | uploaded_file.seek(0) |
| | bytes_data = uploaded_file.getvalue() |
| | log_debug(f"Bytes data length: {len(bytes_data)}") |
| | df2 = pd.read_csv(io.BytesIO(bytes_data)) |
| | log_debug(f"SUCCESS Method 2: {len(df2)} rows, {len(df2.columns)} columns") |
| | st.success("β
Method 2 (Bytes read) WORKED!") |
| | st.dataframe(df2.head()) |
| | |
| | except Exception as e2: |
| | log_debug(f"FAILED Method 2: {str(e2)}") |
| | st.error(f"β Method 2 failed: {str(e2)}") |
| | |
| | try: |
| | |
| | log_debug("Attempting Method 3: Read as string") |
| | uploaded_file.seek(0) |
| | string_data = uploaded_file.getvalue().decode("utf-8") |
| | log_debug(f"String data length: {len(string_data)}") |
| | df3 = pd.read_csv(io.StringIO(string_data)) |
| | log_debug(f"SUCCESS Method 3: {len(df3)} rows, {len(df3.columns)} columns") |
| | st.success("β
Method 3 (String read) WORKED!") |
| | st.dataframe(df3.head()) |
| | |
| | except Exception as e3: |
| | log_debug(f"FAILED Method 3: {str(e3)}") |
| | st.error(f"β Method 3 failed: {str(e3)}") |
| | st.error("β ALL METHODS FAILED!") |
| | |
| | |
| | st.code(traceback.format_exc()) |
| |
|
| | else: |
| | st.info("π Upload a CSV file to test different reading methods") |
| |
|
| | |
| | if st.session_state.debug_info: |
| | st.markdown("### Debug Log") |
| | for i, msg in enumerate(st.session_state.debug_info): |
| | st.text(f"{i+1}. {msg}") |
| |
|
| | |
| | if st.button("Clear Debug Log"): |
| | st.session_state.debug_info = [] |
| | st.rerun() |
| |
|