mtoft20 commited on
Commit
110654f
·
verified ·
1 Parent(s): 927aefb

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +5 -5
src/streamlit_app.py CHANGED
@@ -252,10 +252,10 @@ def extract_unique_names(content_list, field):
252
  return sorted(list(unique_names))
253
 
254
  @st.cache_data(ttl=3600) # Cache feature vectors for 1 hour
255
- def prepare_content_features():
256
  """Prepare and cache content features for similarity matching"""
257
  # Convert to DataFrame for easier processing
258
- df = pd.DataFrame(all_content)
259
 
260
  # Create TF-IDF vectorizer for text features
261
  tfidf = TfidfVectorizer(
@@ -319,11 +319,11 @@ def get_content_clusters(features, n_clusters=50):
319
  kmeans = get_kmeans_model(n_clusters)
320
  return kmeans.fit_predict(features)
321
 
322
- def find_similar_content(content, n_clusters=50, n_recommendations=5):
323
  """Find similar content using optimized k-means clustering"""
324
  try:
325
  # Get cached features and cluster assignments
326
- features, df = prepare_content_features()
327
  cluster_labels = get_content_clusters(features, n_clusters)
328
 
329
  # Find the index of the selected content
@@ -630,7 +630,7 @@ def main():
630
  similar_button = st.button(f"🔍 Find Similar Content", key=f"similar_{i}")
631
  if similar_button:
632
  with st.spinner("Finding similar content..."):
633
- similar_content = find_similar_content(content)
634
 
635
  if similar_content:
636
  # Create tabs for different aspects of recommendations
 
252
  return sorted(list(unique_names))
253
 
254
  @st.cache_data(ttl=3600) # Cache feature vectors for 1 hour
255
+ def prepare_content_features(content_list):
256
  """Prepare and cache content features for similarity matching"""
257
  # Convert to DataFrame for easier processing
258
+ df = pd.DataFrame(content_list)
259
 
260
  # Create TF-IDF vectorizer for text features
261
  tfidf = TfidfVectorizer(
 
319
  kmeans = get_kmeans_model(n_clusters)
320
  return kmeans.fit_predict(features)
321
 
322
+ def find_similar_content(content, all_content_list, n_clusters=50, n_recommendations=5):
323
  """Find similar content using optimized k-means clustering"""
324
  try:
325
  # Get cached features and cluster assignments
326
+ features, df = prepare_content_features(all_content_list)
327
  cluster_labels = get_content_clusters(features, n_clusters)
328
 
329
  # Find the index of the selected content
 
630
  similar_button = st.button(f"🔍 Find Similar Content", key=f"similar_{i}")
631
  if similar_button:
632
  with st.spinner("Finding similar content..."):
633
+ similar_content = find_similar_content(content, all_content)
634
 
635
  if similar_content:
636
  # Create tabs for different aspects of recommendations