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

Add comprehensive debug tab for troubleshooting file uploads

Browse files

- Added Debug Log tab showing file upload details, session state, and configuration
- Added expandable debug section after file upload
- Displays file metadata (name, size, type, ID)
- Shows server configuration and Python/Streamlit versions
- Shows session state and analysis metadata
- Added refresh button for debug information
- This will help diagnose file upload issues on Hugging Face Spaces

Files changed (1) hide show
  1. src/streamlit_app.py +82 -2
src/streamlit_app.py CHANGED
@@ -226,6 +226,25 @@ def main():
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")
228
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
  # Sidebar for settings
230
  with st.sidebar:
231
  st.header("βš™οΈ Settings")
@@ -270,11 +289,12 @@ def main():
270
  st.markdown("---")
271
 
272
  # Create tabs
273
- tab1, tab2, tab3, tab4 = st.tabs([
274
  "πŸ“Š Structure Analysis",
275
  "🎯 Field Recommendations",
276
  "πŸ“ Generated Patterns",
277
- "πŸ“„ Raw Data"
 
278
  ])
279
 
280
  with tab1:
@@ -384,6 +404,66 @@ def main():
384
  file_name="raw_data.json",
385
  mime="application/json"
386
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
387
 
388
  except json.JSONDecodeError as e:
389
  st.error(f"❌ Invalid JSON file: {e}")
 
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")
228
 
229
+ # Debug tab for troubleshooting
230
+ st.markdown("---")
231
+ with st.expander("πŸ› Debug Information (Click to expand)", expanded=False):
232
+ col1, col2 = st.columns(2)
233
+
234
+ with col1:
235
+ st.markdown("#### Upload Details")
236
+ st.text(f"File Name: {uploaded_file.name}")
237
+ st.text(f"File Size: {uploaded_file.size} bytes ({uploaded_file.size / 1024:.2f} KB)")
238
+ st.text(f"File Type: {uploaded_file.type}")
239
+ st.text(f"File ID: {uploaded_file.file_id}")
240
+
241
+ with col2:
242
+ st.markdown("#### Data Details")
243
+ st.text(f"Content Length: {len(content)} bytes")
244
+ st.text(f"Data Type: {type(data).__name__}")
245
+ st.text(f"Top-level Keys: {list(data.keys())[:5] if isinstance(data, dict) else 'N/A'}")
246
+ st.text(f"Encoding: UTF-8")
247
+
248
  # Sidebar for settings
249
  with st.sidebar:
250
  st.header("βš™οΈ Settings")
 
289
  st.markdown("---")
290
 
291
  # Create tabs
292
+ tab1, tab2, tab3, tab4, tab5 = st.tabs([
293
  "πŸ“Š Structure Analysis",
294
  "🎯 Field Recommendations",
295
  "πŸ“ Generated Patterns",
296
+ "πŸ“„ Raw Data",
297
+ "πŸ› Debug Log"
298
  ])
299
 
300
  with tab1:
 
404
  file_name="raw_data.json",
405
  mime="application/json"
406
  )
407
+
408
+ with tab5:
409
+ st.subheader("πŸ› Debug Information")
410
+
411
+ col1, col2 = st.columns(2)
412
+
413
+ with col1:
414
+ st.markdown("#### File Upload Details")
415
+ debug_info = {
416
+ "File Name": uploaded_file.name if uploaded_file else "None",
417
+ "File Size (bytes)": uploaded_file.size if uploaded_file else 0,
418
+ "File Type": uploaded_file.type if uploaded_file else "None",
419
+ "File ID": str(uploaded_file.file_id) if uploaded_file else "None",
420
+ }
421
+
422
+ for key, value in debug_info.items():
423
+ st.text(f"{key}: {value}")
424
+
425
+ # Server configuration
426
+ st.markdown("#### Server Configuration")
427
+ config_info = {
428
+ "Python Version": sys.version.split('\n')[0],
429
+ "Streamlit Version": st.__version__,
430
+ "Upload Size Limit": "1024 MB (1 GB)",
431
+ "XSRF Protection": "Disabled",
432
+ }
433
+
434
+ for key, value in config_info.items():
435
+ st.text(f"{key}: {value}")
436
+
437
+ with col2:
438
+ st.markdown("#### Session State")
439
+ session_keys = list(st.session_state.keys())
440
+
441
+ if session_keys:
442
+ for key in session_keys:
443
+ value = st.session_state[key]
444
+ if isinstance(value, (dict, list)):
445
+ st.text(f"{key}: {type(value).__name__} ({len(value)} items)")
446
+ else:
447
+ st.text(f"{key}: {str(value)[:50]}...")
448
+ else:
449
+ st.info("No session state data")
450
+
451
+ st.markdown("#### Analysis Metadata")
452
+ if st.session_state.get('analysis_result'):
453
+ analysis = st.session_state.analysis_result
454
+ st.text(f"Summary Fields: {len(analysis.get('summary_fields_detected', []))}")
455
+ st.text(f"Total Objects: {analysis.get('total_objects', 0)}")
456
+ st.text(f"Recommended Fields: {len(analysis.get('recommended_fields', []))}")
457
+ else:
458
+ st.info("No analysis data yet")
459
+
460
+ # Debug console output
461
+ st.markdown("#### Backend Console Output")
462
+ st.info("Check your browser console (F12) and Streamlit terminal for detailed backend logs")
463
+
464
+ # Refresh button
465
+ if st.button("πŸ”„ Refresh Debug Info"):
466
+ st.rerun()
467
 
468
  except json.JSONDecodeError as e:
469
  st.error(f"❌ Invalid JSON file: {e}")