bluestpanda commited on
Commit
4cb7ccc
Β·
1 Parent(s): a2e1faa

Enhanced file upload debugging and XSRF configuration

Browse files

- Added --server.enableXsrfProtection=false to Dockerfile ENTRYPOINT
- Enhanced file upload debugging with detailed logging
- Added file pointer reset for proper file reading
- Added UTF-8 decoding with error handling
- Added Streamlit version display in sidebar
- Fixed page_config order (must be first Streamlit command)
- Added empty file detection and better error messages

Files changed (2) hide show
  1. Dockerfile +1 -1
  2. src/streamlit_app.py +28 -2
Dockerfile CHANGED
@@ -19,4 +19,4 @@ EXPOSE 8501
19
 
20
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
21
 
22
- ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.maxUploadSize=1024"]
 
19
 
20
  HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
21
 
22
+ ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.maxUploadSize=1024", "--server.enableXsrfProtection=false"]
src/streamlit_app.py CHANGED
@@ -9,14 +9,20 @@ import json
9
  from pathlib import Path
10
  from typing import Dict, Any
11
  import io
 
12
 
13
- # Page configuration
14
  st.set_page_config(
15
  page_title="Field Correlation Analyzer",
16
  page_icon="πŸ€–",
17
  layout="wide"
18
  )
19
 
 
 
 
 
 
20
  # Import our modules
21
  try:
22
  from structure_analysis import (
@@ -178,6 +184,10 @@ def main():
178
  help="Upload a JSON file with structured data (Maximum file size: 1 GB)"
179
  )
180
 
 
 
 
 
181
  if uploaded_file is not None:
182
  # Debug file upload info
183
  st.info(f"πŸ“ File uploaded: {uploaded_file.name} (Size: {uploaded_file.size} bytes)")
@@ -187,15 +197,31 @@ def main():
187
  # Read and parse JSON
188
  try:
189
  st.info("πŸ”„ Reading file content...")
 
 
 
 
 
190
  content = uploaded_file.read()
 
 
191
  st.info(f"πŸ“„ Content length: {len(content)} characters")
192
 
193
  if len(content) == 0:
194
  st.error("❌ File appears to be empty!")
 
 
 
 
 
 
 
 
 
195
  return
196
 
197
  st.info("πŸ”„ Parsing JSON...")
198
- data = json.loads(content)
199
 
200
  st.success("βœ… File loaded successfully!")
201
  st.info(f"πŸ“Š Data structure: {type(data)} with {len(data) if isinstance(data, (dict, list)) else 'unknown'} top-level items")
 
9
  from pathlib import Path
10
  from typing import Dict, Any
11
  import io
12
+ import sys
13
 
14
+ # Page configuration (MUST be first Streamlit command)
15
  st.set_page_config(
16
  page_title="Field Correlation Analyzer",
17
  page_icon="πŸ€–",
18
  layout="wide"
19
  )
20
 
21
+ # Debug: Show Streamlit version and environment info
22
+ with st.sidebar:
23
+ st.info(f"🐍 Python {sys.version}")
24
+ st.info(f"πŸ“¦ Streamlit {st.__version__}")
25
+
26
  # Import our modules
27
  try:
28
  from structure_analysis import (
 
184
  help="Upload a JSON file with structured data (Maximum file size: 1 GB)"
185
  )
186
 
187
+ # Debug upload widget state
188
+ if uploaded_file is None:
189
+ st.info("πŸ“ Waiting for file upload...")
190
+
191
  if uploaded_file is not None:
192
  # Debug file upload info
193
  st.info(f"πŸ“ File uploaded: {uploaded_file.name} (Size: {uploaded_file.size} bytes)")
 
197
  # Read and parse JSON
198
  try:
199
  st.info("πŸ”„ Reading file content...")
200
+
201
+ # Reset file pointer in case it was read before
202
+ uploaded_file.seek(0)
203
+
204
+ # Read the file content
205
  content = uploaded_file.read()
206
+ uploaded_file.seek(0) # Reset for potential re-reading
207
+
208
  st.info(f"πŸ“„ Content length: {len(content)} characters")
209
 
210
  if len(content) == 0:
211
  st.error("❌ File appears to be empty!")
212
+ st.warning("This might be a bug. Please try uploading the file again.")
213
+ return
214
+
215
+ # Try to decode as UTF-8
216
+ try:
217
+ content_str = content.decode('utf-8')
218
+ except UnicodeDecodeError as e:
219
+ st.error(f"❌ File encoding error: {e}")
220
+ st.error("Please ensure your JSON file is UTF-8 encoded")
221
  return
222
 
223
  st.info("πŸ”„ Parsing JSON...")
224
+ data = json.loads(content_str)
225
 
226
  st.success("βœ… File loaded successfully!")
227
  st.info(f"πŸ“Š Data structure: {type(data)} with {len(data) if isinstance(data, (dict, list)) else 'unknown'} top-level items")