CoolFace
Apppublic

Eastridge-Analytics/entity-resolution-network-analysis

sourceHugging Facemitupdated 1y agoView on Hugging Face
1likes
debug_upload.py94 linesDownload Raw Back to root
1import streamlit as st2import pandas as pd3import io4import traceback5 6st.set_page_config(page_title="Upload Debug Tool", layout="wide")7st.title("๐Ÿ”ง File Upload Debug Tool")8 9st.markdown("""10This tool will help us diagnose the exact upload issue.11""")12 13# Initialize session state14if 'debug_info' not in st.session_state:15    st.session_state.debug_info = []16 17def log_debug(message):18    st.session_state.debug_info.append(message)19    st.write(f"DEBUG: {message}")20 21st.sidebar.header("Upload Test")22 23# Simple file uploader24uploaded_file = st.sidebar.file_uploader(25    "Test File Upload",26    type=["csv"],27    key="debug_uploader"28)29 30if uploaded_file is not None:31    log_debug(f"File detected: {uploaded_file.name}")32    log_debug(f"File size: {uploaded_file.size} bytes")33    log_debug(f"File type: {uploaded_file.type}")34    35    try:36        # Test method 1: Direct read37        log_debug("Attempting Method 1: Direct pd.read_csv()")38        df1 = pd.read_csv(uploaded_file)39        log_debug(f"SUCCESS Method 1: {len(df1)} rows, {len(df1.columns)} columns")40        st.success("โœ… Method 1 (Direct read) WORKED!")41        st.dataframe(df1.head())42        43    except Exception as e:44        log_debug(f"FAILED Method 1: {str(e)}")45        st.error(f"โŒ Method 1 failed: {str(e)}")46        47        try:48            # Test method 2: Reset and read as bytes49            log_debug("Attempting Method 2: Read as bytes")50            uploaded_file.seek(0)  # Reset file pointer51            bytes_data = uploaded_file.getvalue()52            log_debug(f"Bytes data length: {len(bytes_data)}")53            df2 = pd.read_csv(io.BytesIO(bytes_data))54            log_debug(f"SUCCESS Method 2: {len(df2)} rows, {len(df2.columns)} columns")55            st.success("โœ… Method 2 (Bytes read) WORKED!")56            st.dataframe(df2.head())57            58        except Exception as e2:59            log_debug(f"FAILED Method 2: {str(e2)}")60            st.error(f"โŒ Method 2 failed: {str(e2)}")61            62            try:63                # Test method 3: Read as string64                log_debug("Attempting Method 3: Read as string")65                uploaded_file.seek(0)66                string_data = uploaded_file.getvalue().decode("utf-8")67                log_debug(f"String data length: {len(string_data)}")68                df3 = pd.read_csv(io.StringIO(string_data))69                log_debug(f"SUCCESS Method 3: {len(df3)} rows, {len(df3.columns)} columns")70                st.success("โœ… Method 3 (String read) WORKED!")71                st.dataframe(df3.head())72                73            except Exception as e3:74                log_debug(f"FAILED Method 3: {str(e3)}")75                st.error(f"โŒ Method 3 failed: {str(e3)}")76                st.error("โŒ ALL METHODS FAILED!")77                78                # Show full traceback79                st.code(traceback.format_exc())80 81else:82    st.info("๐Ÿ‘† Upload a CSV file to test different reading methods")83 84# Show debug log85if st.session_state.debug_info:86    st.markdown("### Debug Log")87    for i, msg in enumerate(st.session_state.debug_info):88        st.text(f"{i+1}. {msg}")89 90# Clear debug log91if st.button("Clear Debug Log"):92    st.session_state.debug_info = []93    st.rerun()94