TimWindecker commited on
Commit
bad05e2
·
verified ·
1 Parent(s): e46e8bc

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +32 -17
src/streamlit_app.py CHANGED
@@ -151,6 +151,10 @@ def validate_tsv_format(uploaded_file):
151
  except Exception as e:
152
  return False, f"Error reading file: {str(e)}"
153
 
 
 
 
 
154
  def create_bar_chart(df, view_type):
155
  """Create interactive bar chart based on view type"""
156
 
@@ -515,26 +519,37 @@ with st.expander("How to Test Your Model", expanded=True):
515
 
516
  if uploaded_file is not None:
517
  if st.button("🧮 Calculate Score", width="stretch"):
518
- with st.spinner("Validating and calculating scores..."):
519
- # Validate format
520
  is_valid, result = validate_tsv_format(uploaded_file)
521
- if is_valid:
522
- # Calculate score using hidden ground-truth
523
- scores = calculate_score(result)
524
- if scores is not None:
525
- st.success(f"✅ Score calculated successfully: **{scores['Total Score']:.1f}**")
526
-
527
- # Store in session state
528
- st.session_state.user_results = {
529
- "model": "Your Model",
530
- **scores
531
- }
532
- st.info("👆 Scroll up to see your model on the leaderboard!")
533
- st.rerun()
534
- else:
535
- st.error(f"❌ Invalid file format: {result}")
536
  else:
537
  st.info("👆 Upload a TSV file to calculate your score")
 
 
 
 
 
 
 
 
 
 
 
 
 
538
 
539
  # Step 4
540
  st.markdown("""
 
151
  except Exception as e:
152
  return False, f"Error reading file: {str(e)}"
153
 
154
+ @st.cache_data
155
+ def convert_df_to_tsv(df):
156
+ return df.to_csv(sep='\t', index=False).encode('utf-8')
157
+
158
  def create_bar_chart(df, view_type):
159
  """Create interactive bar chart based on view type"""
160
 
 
519
 
520
  if uploaded_file is not None:
521
  if st.button("🧮 Calculate Score", width="stretch"):
522
+ # Validate format
523
+ with st.spinner("Validating upload..."):
524
  is_valid, result = validate_tsv_format(uploaded_file)
525
+ if is_valid:
526
+ # Calculate score using hidden ground-truth
527
+ scores = calculate_score(result)
528
+ if scores is not None:
529
+ st.success(f"✅ Score calculated successfully: **{scores['score'].mean():.1f}**")
530
+ # Store in session state
531
+ st.session_state.user_results = {
532
+ "model": "Your Model",
533
+ **scores
534
+ }
535
+ st.rerun()
536
+ else:
537
+ st.error(f"❌ Invalid file format: {result}")
 
 
538
  else:
539
  st.info("👆 Upload a TSV file to calculate your score")
540
+
541
+ # Allow download of results
542
+ if 'user_results' in st.session_state
543
+ user_results = pd.DataFrame([st.session_state.user_results])
544
+ tsv_data = convert_df_to_tsv(user_results)
545
+ st.download_button(
546
+ label="Download scores as TSV",
547
+ data=tsv_data,
548
+ file_name='scores.tsv',
549
+ mime='text/tab-separated-values',
550
+ width="stretch",
551
+ )
552
+ st.info("👆 Scroll up to see your model on the leaderboard!")
553
 
554
  # Step 4
555
  st.markdown("""