Ahmedik95316 commited on
Commit
8df371b
·
verified ·
1 Parent(s): fd32d34

Update app/streamlit_app.py

Browse files
Files changed (1) hide show
  1. app/streamlit_app.py +62 -8
app/streamlit_app.py CHANGED
@@ -666,11 +666,6 @@ st.markdown(f"""
666
  grid-template-columns: 1fr;
667
  }}
668
  }}
669
-
670
- /* Nuclear option - if containers still persist */
671
- div[class*="css-"], div[data-baseweb] {{
672
- background-color: transparent !important;
673
- }}
674
  </style>
675
  """, unsafe_allow_html=True)
676
 
@@ -895,17 +890,19 @@ def main():
895
  with tab1:
896
  st.markdown('<h2 class="section-header">🎯 Single Text Analysis</h2>', unsafe_allow_html=True)
897
 
898
- # Input methods with professional styling
899
  col1, col2 = st.columns([3, 1])
900
  with col1:
901
  st.markdown('<h3 class="subsection-header">Input Method</h3>', unsafe_allow_html=True)
902
  with col2:
 
903
  input_method = st.radio(
904
  "Choose input method:",
905
  ["Type Text", "Upload File"],
906
  horizontal=True,
907
  label_visibility="collapsed"
908
  )
 
909
 
910
  user_text = ""
911
 
@@ -1961,7 +1958,7 @@ def render_system_status_tab():
1961
  st.markdown("---")
1962
  render_validation_quality_report()
1963
 
1964
- # Model information
1965
  st.markdown("---")
1966
  st.markdown('<h3 class="subsection-header">🎯 Model Information</h3>', unsafe_allow_html=True)
1967
 
@@ -1972,7 +1969,47 @@ def render_system_status_tab():
1972
  col1, col2 = st.columns(2)
1973
 
1974
  with col1:
1975
- key_metrics = ['model_version', 'test_accuracy', 'test_f1', 'model_type']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1976
  for key in key_metrics:
1977
  if key in metadata:
1978
  display_key = key.replace('_', ' ').title()
@@ -1981,6 +2018,9 @@ def render_system_status_tab():
1981
  st.metric(display_key, f"{value:.4f}")
1982
  else:
1983
  st.metric(display_key, str(value))
 
 
 
1984
 
1985
  with col2:
1986
  info_fields = ['train_size', 'timestamp', 'environment']
@@ -1995,6 +2035,20 @@ def render_system_status_tab():
1995
  except:
1996
  pass
1997
  st.write(f"**{display_key}:** {value}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1998
  else:
1999
  st.markdown(f"""
2000
  <div class="warning-message">
 
666
  grid-template-columns: 1fr;
667
  }}
668
  }}
 
 
 
 
 
669
  </style>
670
  """, unsafe_allow_html=True)
671
 
 
890
  with tab1:
891
  st.markdown('<h2 class="section-header">🎯 Single Text Analysis</h2>', unsafe_allow_html=True)
892
 
893
+ # Input methods with custom styling wrapper
894
  col1, col2 = st.columns([3, 1])
895
  with col1:
896
  st.markdown('<h3 class="subsection-header">Input Method</h3>', unsafe_allow_html=True)
897
  with col2:
898
+ st.markdown('<div style="background: transparent; padding: 0;">', unsafe_allow_html=True)
899
  input_method = st.radio(
900
  "Choose input method:",
901
  ["Type Text", "Upload File"],
902
  horizontal=True,
903
  label_visibility="collapsed"
904
  )
905
+ st.markdown('</div>', unsafe_allow_html=True)
906
 
907
  user_text = ""
908
 
 
1958
  st.markdown("---")
1959
  render_validation_quality_report()
1960
 
1961
+ # Model information with enhanced detection
1962
  st.markdown("---")
1963
  st.markdown('<h3 class="subsection-header">🎯 Model Information</h3>', unsafe_allow_html=True)
1964
 
 
1969
  col1, col2 = st.columns(2)
1970
 
1971
  with col1:
1972
+ # Enhanced model type detection
1973
+ model_type = metadata.get('model_type', 'Unknown')
1974
+
1975
+ # Check if it's actually an ensemble by looking at the training method or other indicators
1976
+ training_method = metadata.get('training_method', '')
1977
+ model_version = metadata.get('model_version', '')
1978
+
1979
+ # Try to detect ensemble from metadata or check actual model files
1980
+ if 'ensemble' in training_method.lower() or 'ensemble' in model_version.lower():
1981
+ display_model_type = 'Ensemble Model'
1982
+ elif model_type == 'logistic_regression_pipeline':
1983
+ # Try to load and inspect the actual model to see if it's an ensemble
1984
+ try:
1985
+ import joblib
1986
+ pipeline_path = path_manager.get_pipeline_path()
1987
+ if pipeline_path.exists():
1988
+ pipeline = joblib.load(pipeline_path)
1989
+ # Check if the model component is an ensemble
1990
+ if hasattr(pipeline, 'named_steps') and 'model' in pipeline.named_steps:
1991
+ model_component = pipeline.named_steps['model']
1992
+ model_class_name = model_component.__class__.__name__
1993
+
1994
+ # Check for ensemble indicators
1995
+ if 'voting' in model_class_name.lower() or 'ensemble' in model_class_name.lower():
1996
+ display_model_type = f'Ensemble ({model_class_name})'
1997
+ elif hasattr(model_component, 'estimators_'):
1998
+ # Has multiple estimators - likely ensemble
1999
+ estimator_types = [est.__class__.__name__ for est in model_component.estimators_]
2000
+ display_model_type = f'Ensemble ({", ".join(set(estimator_types))})'
2001
+ else:
2002
+ display_model_type = f'Single Model ({model_class_name})'
2003
+ else:
2004
+ display_model_type = model_type
2005
+ else:
2006
+ display_model_type = model_type
2007
+ except Exception as e:
2008
+ display_model_type = f'{model_type} (inspection failed)'
2009
+ else:
2010
+ display_model_type = model_type
2011
+
2012
+ key_metrics = ['model_version', 'test_accuracy', 'test_f1']
2013
  for key in key_metrics:
2014
  if key in metadata:
2015
  display_key = key.replace('_', ' ').title()
 
2018
  st.metric(display_key, f"{value:.4f}")
2019
  else:
2020
  st.metric(display_key, str(value))
2021
+
2022
+ # Display the enhanced model type
2023
+ st.metric("Model Type", display_model_type)
2024
 
2025
  with col2:
2026
  info_fields = ['train_size', 'timestamp', 'environment']
 
2035
  except:
2036
  pass
2037
  st.write(f"**{display_key}:** {value}")
2038
+
2039
+ # Add ensemble composition if detected
2040
+ if 'Ensemble' in display_model_type and 'inspection failed' not in display_model_type:
2041
+ try:
2042
+ pipeline_path = path_manager.get_pipeline_path()
2043
+ if pipeline_path.exists():
2044
+ import joblib
2045
+ pipeline = joblib.load(pipeline_path)
2046
+ if hasattr(pipeline, 'named_steps') and 'model' in pipeline.named_steps:
2047
+ model_component = pipeline.named_steps['model']
2048
+ if hasattr(model_component, 'estimators_'):
2049
+ st.write(f"**Ensemble Size:** {len(model_component.estimators_)} models")
2050
+ except:
2051
+ pass
2052
  else:
2053
  st.markdown(f"""
2054
  <div class="warning-message">