Hebaelsayed commited on
Commit
a02e988
Β·
verified Β·
1 Parent(s): 3fbb8fa

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +20 -18
src/streamlit_app.py CHANGED
@@ -51,6 +51,19 @@ EMBEDDING_MODELS = {
51
  }
52
  }
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  # ============================================================================
55
  # CACHED RESOURCES
56
  # ============================================================================
@@ -256,17 +269,6 @@ def get_vector_count(qdrant):
256
  except:
257
  return 0
258
 
259
- # ============================================================================
260
- # INITIALIZE SESSION STATE
261
- # ============================================================================
262
-
263
- if 'processing_complete' not in st.session_state:
264
- st.session_state.processing_complete = False
265
- if 'last_processed_files' not in st.session_state:
266
- st.session_state.last_processed_files = []
267
- if 'processing_stats' not in st.session_state:
268
- st.session_state.processing_stats = {}
269
-
270
  # ============================================================================
271
  # INITIALIZE
272
  # ============================================================================
@@ -293,7 +295,7 @@ try:
293
 
294
  # Get current embedding model
295
  current_model_key = None
296
- current_model_name = st.session_state.get('embedding_model', EMBEDDING_MODELS["MiniLM-L6 (Fast, 384D)"]["name"])
297
  for key, value in EMBEDDING_MODELS.items():
298
  if value["name"] == current_model_name:
299
  current_model_key = key
@@ -371,7 +373,7 @@ with tab1:
371
  st.subheader("Embedding Model")
372
 
373
  # Get current model
374
- current_model_name = st.session_state.get('embedding_model', EMBEDDING_MODELS["MiniLM-L6 (Fast, 384D)"]["name"])
375
  current_model_key = None
376
  for key, value in EMBEDDING_MODELS.items():
377
  if value["name"] == current_model_name:
@@ -397,7 +399,7 @@ with tab1:
397
  - **Quality:** {model_info['quality']}
398
  """)
399
 
400
- # Update session state
401
  if st.session_state.embedding_model != model_info['name']:
402
  if st.button("πŸ”„ Apply Model Change"):
403
  st.session_state.embedding_model = model_info['name']
@@ -523,7 +525,7 @@ with tab1:
523
  total_est_words = est_words * len(selected_files)
524
 
525
  # Get embedding dimensions
526
- current_model_name = st.session_state.get('embedding_model', EMBEDDING_MODELS["MiniLM-L6 (Fast, 384D)"]["name"])
527
  dimensions = 384 # default
528
  for key, value in EMBEDDING_MODELS.items():
529
  if value["name"] == current_model_name:
@@ -551,7 +553,7 @@ with tab1:
551
  # Process button
552
  if st.button("πŸš€ PROCESS SELECTED FILES", type="primary", key="process_button"):
553
 
554
- current_model_name = st.session_state.get('embedding_model', EMBEDDING_MODELS["MiniLM-L6 (Fast, 384D)"]["name"])
555
  embedder = get_embedding_model(current_model_name)
556
 
557
  context_books = ""
@@ -735,7 +737,7 @@ with tab1:
735
  try:
736
  from datasets import load_dataset
737
 
738
- current_model_name = st.session_state.get('embedding_model', EMBEDDING_MODELS["MiniLM-L6 (Fast, 384D)"]["name"])
739
  embedder = get_embedding_model(current_model_name)
740
 
741
  with st.spinner(f"Loading {dataset_name}..."):
@@ -798,7 +800,7 @@ with tab2:
798
 
799
  if st.button("πŸš€ SOLVE", type="primary", key="solve_button") and problem:
800
 
801
- current_model_name = st.session_state.get('embedding_model', EMBEDDING_MODELS["MiniLM-L6 (Fast, 384D)"]["name"])
802
  embedder = get_embedding_model(current_model_name)
803
 
804
  with st.spinner("Searching knowledge base..."):
 
51
  }
52
  }
53
 
54
+ # ============================================================================
55
+ # INITIALIZE SESSION STATE - MUST BE BEFORE ANY st.session_state ACCESS
56
+ # ============================================================================
57
+
58
+ if 'processing_complete' not in st.session_state:
59
+ st.session_state.processing_complete = False
60
+ if 'last_processed_files' not in st.session_state:
61
+ st.session_state.last_processed_files = []
62
+ if 'processing_stats' not in st.session_state:
63
+ st.session_state.processing_stats = {}
64
+ if 'embedding_model' not in st.session_state:
65
+ st.session_state.embedding_model = EMBEDDING_MODELS["MiniLM-L6 (Fast, 384D)"]["name"]
66
+
67
  # ============================================================================
68
  # CACHED RESOURCES
69
  # ============================================================================
 
269
  except:
270
  return 0
271
 
 
 
 
 
 
 
 
 
 
 
 
272
  # ============================================================================
273
  # INITIALIZE
274
  # ============================================================================
 
295
 
296
  # Get current embedding model
297
  current_model_key = None
298
+ current_model_name = st.session_state.embedding_model
299
  for key, value in EMBEDDING_MODELS.items():
300
  if value["name"] == current_model_name:
301
  current_model_key = key
 
373
  st.subheader("Embedding Model")
374
 
375
  # Get current model
376
+ current_model_name = st.session_state.embedding_model
377
  current_model_key = None
378
  for key, value in EMBEDDING_MODELS.items():
379
  if value["name"] == current_model_name:
 
399
  - **Quality:** {model_info['quality']}
400
  """)
401
 
402
+ # Update session state only if different
403
  if st.session_state.embedding_model != model_info['name']:
404
  if st.button("πŸ”„ Apply Model Change"):
405
  st.session_state.embedding_model = model_info['name']
 
525
  total_est_words = est_words * len(selected_files)
526
 
527
  # Get embedding dimensions
528
+ current_model_name = st.session_state.embedding_model
529
  dimensions = 384 # default
530
  for key, value in EMBEDDING_MODELS.items():
531
  if value["name"] == current_model_name:
 
553
  # Process button
554
  if st.button("πŸš€ PROCESS SELECTED FILES", type="primary", key="process_button"):
555
 
556
+ current_model_name = st.session_state.embedding_model
557
  embedder = get_embedding_model(current_model_name)
558
 
559
  context_books = ""
 
737
  try:
738
  from datasets import load_dataset
739
 
740
+ current_model_name = st.session_state.embedding_model
741
  embedder = get_embedding_model(current_model_name)
742
 
743
  with st.spinner(f"Loading {dataset_name}..."):
 
800
 
801
  if st.button("πŸš€ SOLVE", type="primary", key="solve_button") and problem:
802
 
803
+ current_model_name = st.session_state.embedding_model
804
  embedder = get_embedding_model(current_model_name)
805
 
806
  with st.spinner("Searching knowledge base..."):