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

Fix file upload issues on Hugging Face Spaces

Browse files

- Added enableXsrfProtection = false to .streamlit/config.toml
- Enhanced debugging with file type, ID, and empty file detection
- Added detailed error handling with stack traces
- This should resolve XSRF protection issues preventing uploads on HF Spaces

Files changed (2) hide show
  1. .streamlit/config.toml +1 -0
  2. src/streamlit_app.py +9 -0
.streamlit/config.toml CHANGED
@@ -1,2 +1,3 @@
1
  [server]
2
  maxUploadSize = 1024 # 1 GB in MB
 
 
1
  [server]
2
  maxUploadSize = 1024 # 1 GB in MB
3
+ enableXsrfProtection = false # Disable XSRF protection for Hugging Face Spaces
src/streamlit_app.py CHANGED
@@ -181,6 +181,8 @@ def main():
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)")
 
 
184
 
185
  # Read and parse JSON
186
  try:
@@ -188,6 +190,10 @@ def main():
188
  content = uploaded_file.read()
189
  st.info(f"πŸ“„ Content length: {len(content)} characters")
190
 
 
 
 
 
191
  st.info("πŸ”„ Parsing JSON...")
192
  data = json.loads(content)
193
 
@@ -357,6 +363,9 @@ def main():
357
  st.error(f"❌ Invalid JSON file: {e}")
358
  except Exception as e:
359
  st.error(f"❌ Error processing file: {e}")
 
 
 
360
 
361
  else:
362
  # Show example when no file uploaded
 
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)")
184
+ st.info(f"πŸ” File type: {uploaded_file.type}")
185
+ st.info(f"πŸ” File ID: {uploaded_file.file_id}")
186
 
187
  # Read and parse JSON
188
  try:
 
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
 
 
363
  st.error(f"❌ Invalid JSON file: {e}")
364
  except Exception as e:
365
  st.error(f"❌ Error processing file: {e}")
366
+ st.error(f"Error type: {type(e).__name__}")
367
+ import traceback
368
+ st.code(traceback.format_exc())
369
 
370
  else:
371
  # Show example when no file uploaded