egumasa commited on
Commit
89e2764
Β·
1 Parent(s): ca02ec3

debugging mode

Browse files
Files changed (3) hide show
  1. minimal_test_app.py +43 -0
  2. web_app/app.py +19 -1
  3. web_app/debug_utils.py +122 -0
minimal_test_app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from io import StringIO
3
+
4
+ st.title("Minimal File Upload Test")
5
+
6
+ # Test basic file upload
7
+ uploaded_file = st.file_uploader("Choose a file", type=['txt', 'csv'])
8
+
9
+ if uploaded_file is not None:
10
+ # Show file details
11
+ st.write("File details:")
12
+ st.write(f"- Name: {uploaded_file.name}")
13
+ st.write(f"- Type: {uploaded_file.type}")
14
+ st.write(f"- Size: {uploaded_file.size} bytes")
15
+
16
+ # Try to read content
17
+ try:
18
+ # Reset file pointer
19
+ uploaded_file.seek(0)
20
+
21
+ # Read content
22
+ content = uploaded_file.read()
23
+
24
+ # Decode if bytes
25
+ if isinstance(content, bytes):
26
+ text_content = content.decode('utf-8')
27
+ else:
28
+ text_content = content
29
+
30
+ st.write("File content preview (first 500 chars):")
31
+ st.code(text_content[:500])
32
+
33
+ # Test StringIO
34
+ string_io = StringIO(text_content)
35
+ st.write(f"StringIO created successfully: {type(string_io)}")
36
+
37
+ except Exception as e:
38
+ st.error(f"Error reading file: {e}")
39
+ import traceback
40
+ st.code(traceback.format_exc())
41
+
42
+ st.write("---")
43
+ st.write("Session state keys:", list(st.session_state.keys()))
web_app/app.py CHANGED
@@ -65,7 +65,25 @@ def render_sidebar():
65
  UIComponents.render_model_selector()
66
 
67
  # Tool selection
68
- return UIComponents.render_tool_selector()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
 
71
  def render_lexical_sophistication_interface():
 
65
  UIComponents.render_model_selector()
66
 
67
  # Tool selection
68
+ tool_choice = UIComponents.render_tool_selector()
69
+
70
+ # Debug mode toggle
71
+ st.write("---")
72
+ debug_mode = st.checkbox("πŸ› Debug Mode", key="debug_mode", help="Enable debug information for troubleshooting")
73
+
74
+ if debug_mode:
75
+ from web_app.debug_utils import show_environment_info, test_file_operations, debug_file_upload
76
+
77
+ with st.expander("Environment Info", expanded=False):
78
+ show_environment_info()
79
+
80
+ with st.expander("File Operations Test", expanded=False):
81
+ test_file_operations()
82
+
83
+ with st.expander("File Upload Test", expanded=False):
84
+ debug_file_upload()
85
+
86
+ return tool_choice
87
 
88
 
89
  def render_lexical_sophistication_interface():
web_app/debug_utils.py ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Debug utilities for troubleshooting Huggingface Spaces issues."""
2
+
3
+ import streamlit as st
4
+ import os
5
+ import sys
6
+
7
+ def show_environment_info():
8
+ """Display environment information for debugging."""
9
+ st.write("### Environment Information")
10
+
11
+ col1, col2 = st.columns(2)
12
+
13
+ with col1:
14
+ st.write("**System Info:**")
15
+ st.write(f"- Python: {sys.version}")
16
+ st.write(f"- Platform: {sys.platform}")
17
+ st.write(f"- Working Dir: {os.getcwd()}")
18
+ st.write(f"- User: {os.environ.get('USER', 'N/A')}")
19
+ st.write(f"- Home: {os.environ.get('HOME', 'N/A')}")
20
+
21
+ with col2:
22
+ st.write("**Directory Permissions:**")
23
+ dirs_to_check = ['/tmp', '.', './web_app', os.environ.get('HOME', '/')]
24
+ for dir_path in dirs_to_check:
25
+ if os.path.exists(dir_path):
26
+ try:
27
+ # Check if we can write to the directory
28
+ test_file = os.path.join(dir_path, '.write_test')
29
+ with open(test_file, 'w') as f:
30
+ f.write('test')
31
+ os.remove(test_file)
32
+ st.write(f"- {dir_path}: βœ… Writable")
33
+ except:
34
+ st.write(f"- {dir_path}: ❌ Not writable")
35
+ else:
36
+ st.write(f"- {dir_path}: ⚠️ Not found")
37
+
38
+ st.write("**Environment Variables:**")
39
+ important_vars = ['STREAMLIT_SERVER_PORT', 'STREAMLIT_SERVER_ADDRESS',
40
+ 'UV_CACHE_DIR', 'TMPDIR', 'TEMP', 'TMP']
41
+ for var in important_vars:
42
+ value = os.environ.get(var, 'Not set')
43
+ st.write(f"- {var}: {value}")
44
+
45
+ def test_file_operations():
46
+ """Test various file operations to identify issues."""
47
+ st.write("### File Operation Tests")
48
+
49
+ tests = []
50
+
51
+ # Test 1: StringIO
52
+ try:
53
+ from io import StringIO
54
+ sio = StringIO("test content")
55
+ content = sio.read()
56
+ tests.append(("StringIO operations", "βœ… Success", None))
57
+ except Exception as e:
58
+ tests.append(("StringIO operations", "❌ Failed", str(e)))
59
+
60
+ # Test 2: BytesIO
61
+ try:
62
+ from io import BytesIO
63
+ bio = BytesIO(b"test content")
64
+ content = bio.read()
65
+ tests.append(("BytesIO operations", "βœ… Success", None))
66
+ except Exception as e:
67
+ tests.append(("BytesIO operations", "❌ Failed", str(e)))
68
+
69
+ # Test 3: Session state
70
+ try:
71
+ st.session_state.test_key = "test_value"
72
+ _ = st.session_state.test_key
73
+ del st.session_state.test_key
74
+ tests.append(("Session state operations", "βœ… Success", None))
75
+ except Exception as e:
76
+ tests.append(("Session state operations", "❌ Failed", str(e)))
77
+
78
+ # Display results
79
+ for test_name, status, error in tests:
80
+ col1, col2 = st.columns([3, 1])
81
+ with col1:
82
+ st.write(f"**{test_name}**")
83
+ if error:
84
+ st.write(f" Error: {error}")
85
+ with col2:
86
+ st.write(status)
87
+
88
+ def debug_file_upload():
89
+ """Debug file upload functionality."""
90
+ st.write("### File Upload Debug")
91
+
92
+ uploaded_file = st.file_uploader("Test file upload", type=['txt', 'csv'])
93
+
94
+ if uploaded_file:
95
+ st.write("**File Info:**")
96
+ st.write(f"- Name: {uploaded_file.name}")
97
+ st.write(f"- Type: {uploaded_file.type}")
98
+ st.write(f"- Size: {uploaded_file.size} bytes")
99
+
100
+ try:
101
+ # Try different read methods
102
+ uploaded_file.seek(0)
103
+ content = uploaded_file.read()
104
+ st.write(f"- Read method: βœ… Success ({len(content)} bytes)")
105
+
106
+ # Try getvalue if available
107
+ try:
108
+ uploaded_file.seek(0)
109
+ value = uploaded_file.getvalue()
110
+ st.write(f"- GetValue method: βœ… Success ({len(value)} bytes)")
111
+ except:
112
+ st.write("- GetValue method: ⚠️ Not available")
113
+
114
+ # Try decoding
115
+ if isinstance(content, bytes):
116
+ text = content.decode('utf-8')
117
+ st.write(f"- Decode UTF-8: βœ… Success ({len(text)} chars)")
118
+
119
+ except Exception as e:
120
+ st.error(f"Error processing file: {e}")
121
+ import traceback
122
+ st.code(traceback.format_exc())