ESMATUGBA commited on
Commit
5eed478
·
verified ·
1 Parent(s): 9dea6af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -19
app.py CHANGED
@@ -1,15 +1,18 @@
1
  import streamlit as st
2
  import pickle
3
  from scipy import spatial
4
- import random
5
  import os
 
6
 
7
  # --- 1. MODELİ YÜKLE ---
8
  @st.cache_resource
9
  def load_data():
10
  try:
11
- with open('movie_model.pkl', 'rb') as f:
12
- return pickle.load(f)
 
 
 
13
  except:
14
  return None
15
 
@@ -54,15 +57,13 @@ tum_unlu_verileri = {
54
  # --- ARAYÜZ AYARLARI ---
55
  st.set_page_config(page_title="CastMatch AI", layout="wide")
56
 
57
- # CSS: Resim alanı sabitleme
58
  st.markdown("""
59
  <style>
60
  [data-testid="stImage"] {
61
  min-height: 400px !important;
62
  max-height: 400px !important;
63
- display: flex;
64
- align-items: center;
65
- justify-content: center;
66
  }
67
  .stImage img {
68
  max-height: 400px !important;
@@ -72,13 +73,12 @@ st.markdown("""
72
  </style>
73
  """, unsafe_allow_html=True)
74
 
75
- # --- SIDEBAR ---
76
  st.sidebar.title("🔍 Control Panel / Kontrol Paneli")
77
  st.sidebar.markdown("---")
78
  gender_choice = st.sidebar.radio("1. Select Category / Kategori Seçin:", ["Male / Erkek", "Female / Kadın"])
79
 
80
- hf_files = os.listdir(".")
81
- filtered_names = [name for name in tum_unlu_verileri.keys() if tum_unlu_verileri[name]['c'] == gender_choice]
82
 
83
  st.sidebar.markdown(f"### 📋 Available Cast / Mevcut Oyuncular")
84
  for n in filtered_names:
@@ -92,19 +92,28 @@ col_actor, col_match = st.columns([1, 2])
92
 
93
  with col_actor:
94
  st.subheader("👤 Pick an Actor / Oyuncu Seç")
95
- # SEÇİM KUTUSU GÜNCELLENDİ
96
  selected_actor = st.selectbox("Select from list / Listeden seçin:", ["Choose... / Seçiniz..."] + filtered_names)
97
 
98
  if selected_actor != "Choose... / Seçiniz...":
 
99
  found_path = None
100
- search_target = selected_actor.lower()
 
 
 
 
 
 
 
 
101
 
102
- for f in hf_files:
103
- if f.lower().endswith(('.jpg', '.png', '.jpeg')):
104
- # Akıllı isim eşleştirme (Boşlukları ve alt tireleri denetler)
105
- if selected_actor.replace(" ", "_").lower() in f.lower() or selected_actor.replace(" ", " ").lower() in f.lower():
106
- found_path = f
107
- break
 
108
 
109
  if found_path:
110
  st.image(found_path, use_container_width=False)
@@ -115,7 +124,6 @@ with col_actor:
115
  st.markdown('<div style="height: 400px; display: flex; align-items: center; justify-content: center; color: #999; font-style: italic;">Select an actor to view profile / Profil görmek için oyuncu seçin</div>', unsafe_allow_html=True)
116
 
117
  with col_match:
118
- # BAŞLIK GÜNCELLENDİ
119
  st.subheader("🎯 Best Career Matches / En İyi Kariyer Eşleşmeleri")
120
 
121
  if st.button("🚀 Match and Recommend / Eşleştir ve Öner") and selected_actor != "Choose... / Seçiniz...":
 
1
  import streamlit as st
2
  import pickle
3
  from scipy import spatial
 
4
  import os
5
+ import glob
6
 
7
  # --- 1. MODELİ YÜKLE ---
8
  @st.cache_resource
9
  def load_data():
10
  try:
11
+ # Model dosyasını kontrol et
12
+ if os.path.exists('movie_model.pkl'):
13
+ with open('movie_model.pkl', 'rb') as f:
14
+ return pickle.load(f)
15
+ return None
16
  except:
17
  return None
18
 
 
57
  # --- ARAYÜZ AYARLARI ---
58
  st.set_page_config(page_title="CastMatch AI", layout="wide")
59
 
60
+ # CSS: Titreme önleme ve resim sabitleme
61
  st.markdown("""
62
  <style>
63
  [data-testid="stImage"] {
64
  min-height: 400px !important;
65
  max-height: 400px !important;
66
+ display: flex; align-items: center; justify-content: center;
 
 
67
  }
68
  .stImage img {
69
  max-height: 400px !important;
 
73
  </style>
74
  """, unsafe_allow_html=True)
75
 
76
+ # --- SIDEBAR (YAN PANEL) ---
77
  st.sidebar.title("🔍 Control Panel / Kontrol Paneli")
78
  st.sidebar.markdown("---")
79
  gender_choice = st.sidebar.radio("1. Select Category / Kategori Seçin:", ["Male / Erkek", "Female / Kadın"])
80
 
81
+ filtered_names = sorted([name for name in tum_unlu_verileri.keys() if tum_unlu_verileri[name]['c'] == gender_choice])
 
82
 
83
  st.sidebar.markdown(f"### 📋 Available Cast / Mevcut Oyuncular")
84
  for n in filtered_names:
 
92
 
93
  with col_actor:
94
  st.subheader("👤 Pick an Actor / Oyuncu Seç")
 
95
  selected_actor = st.selectbox("Select from list / Listeden seçin:", ["Choose... / Seçiniz..."] + filtered_names)
96
 
97
  if selected_actor != "Choose... / Seçiniz...":
98
+ # HEM LOKAL HEM HF İÇİN AKILLI DOSYA ARAMA
99
  found_path = None
100
+ # Oyuncu isminin muhtemel dosya adı varyasyonları
101
+ name_variants = [
102
+ selected_actor.replace(" ", "_").lower(),
103
+ selected_actor.replace(" ", " ").lower(),
104
+ selected_actor.lower()
105
+ ]
106
+
107
+ # Mevcut dizin ve tüm alt dizinlerdeki resimleri tara
108
+ all_images = glob.glob("**/*.*", recursive=True)
109
 
110
+ for img_path in all_images:
111
+ if img_path.lower().endswith(('.jpg', '.png', '.jpeg')):
112
+ for variant in name_variants:
113
+ if variant in img_path.lower():
114
+ found_path = img_path
115
+ break
116
+ if found_path: break
117
 
118
  if found_path:
119
  st.image(found_path, use_container_width=False)
 
124
  st.markdown('<div style="height: 400px; display: flex; align-items: center; justify-content: center; color: #999; font-style: italic;">Select an actor to view profile / Profil görmek için oyuncu seçin</div>', unsafe_allow_html=True)
125
 
126
  with col_match:
 
127
  st.subheader("🎯 Best Career Matches / En İyi Kariyer Eşleşmeleri")
128
 
129
  if st.button("🚀 Match and Recommend / Eşleştir ve Öner") and selected_actor != "Choose... / Seçiniz...":