ESMATUGBA commited on
Commit
ee88717
·
verified ·
1 Parent(s): c1bc065

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -27
app.py CHANGED
@@ -4,7 +4,7 @@ from scipy import spatial
4
  import random
5
  import os
6
 
7
- # --- TİTREMEYİ ÖNLEYİCİ CSS ---
8
  st.set_page_config(page_title="CastMatch AI", layout="wide")
9
  st.markdown("""
10
  <style>
@@ -12,13 +12,11 @@ st.markdown("""
12
  max-height: 400px;
13
  object-fit: contain;
14
  }
15
- /* Sidebar butonlarını daha belirgin ve geniş yapalım */
16
  div.stButton > button:first-child {
17
  width: 100%;
18
  text-align: left;
19
  border: 1px solid #f0f2f6;
20
  padding: 5px 10px;
21
- transition: all 0.3s;
22
  }
23
  div.stButton > button:first-child:hover {
24
  border-color: #ff4b4b;
@@ -96,7 +94,7 @@ def klasordeki_unluleri_getir():
96
 
97
  unlu_verileri = klasordeki_unluleri_getir()
98
 
99
- # --- SESSION STATE ---
100
  if 'selected_actor' not in st.session_state:
101
  st.session_state.selected_actor = None
102
 
@@ -104,7 +102,6 @@ if 'selected_actor' not in st.session_state:
104
  st.sidebar.title("🔍 Control Panel / Kontrol Paneli")
105
  st.sidebar.markdown("---")
106
 
107
- # Kategori değişince seçimi sıfırla
108
  gender_choice = st.sidebar.radio(
109
  "1. Select Category / Kategori Seçin:",
110
  ["Male / Erkek", "Female / Kadın"],
@@ -114,17 +111,16 @@ gender_choice = st.sidebar.radio(
114
  filtered_names = [name for name, data in unlu_verileri.items() if data['c'] == gender_choice]
115
 
116
  st.sidebar.markdown(f"### 📋 Available Cast / Mevcut Oyuncular")
117
- st.sidebar.caption("Click name to display / Görmek için isme basın")
118
 
119
- # İSİMLERE BASINCA ÇALIŞMASI İÇİN BURASI DÜZELTİLDİ:
120
  for n in filtered_names:
121
- if st.sidebar.button(f"👤 {n}", key=f"sidebar_btn_{n}"):
122
  st.session_state.selected_actor = n
123
- st.rerun() # Sayfayı hemen yenileyerek resmi getirir
124
 
125
  # --- ANA EKRAN ---
126
- st.title("🎬 CastMatch AI: Talent Matching System")
127
- st.markdown("#### Discover the perfect roles for global stars!")
128
  st.markdown("---")
129
 
130
  col_actor, col_match = st.columns([1, 2])
@@ -132,24 +128,28 @@ col_actor, col_match = st.columns([1, 2])
132
  with col_actor:
133
  st.subheader("👤 Pick an Actor / Oyuncu Seç")
134
 
135
- # Selectbox state ile bağlantılı
136
- # Eğer sidebar butonu basıldıysa o isim burada otomatik seçilir
137
- selected_from_box = st.selectbox(
 
 
 
 
 
138
  "Select from list / Listeden seçin:",
139
  filtered_names,
140
- index=filtered_names.index(st.session_state.selected_actor) if st.session_state.selected_actor in filtered_names else None,
141
  placeholder="Choose an actor... / Bir oyuncu seçin...",
142
  key="main_selectbox"
143
  )
144
 
145
- # Selectbox'tan manuel seçim yapılırsa state'i güncelle
146
- if selected_from_box != st.session_state.selected_actor:
147
- st.session_state.selected_actor = selected_from_box
148
- # Eğer None değilse hemen rerun yap ki resim gelsin
149
- if selected_from_box:
150
  st.rerun()
151
 
152
- # RESİM GÖSTERME
153
  if st.session_state.selected_actor:
154
  actor = st.session_state.selected_actor
155
  found_path = None
@@ -160,20 +160,20 @@ with col_actor:
160
  break
161
 
162
  if found_path:
163
- st.image(found_path, caption=f"Profile: {actor}", use_container_width=True)
164
  else:
165
  st.error("Image not found. / Resim bulunamadı.")
166
  else:
167
  st.info("Please select an actor. / Lütfen bir oyuncu seçin.")
168
 
169
  with col_match:
170
- st.subheader("🎯 Best Career Matches")
171
 
172
  if st.session_state.selected_actor:
173
  actor = st.session_state.selected_actor
174
- st.write(f"Comparing {actor}'s DNA...")
175
 
176
- if st.button("🚀 Match and Recommend", key="match_btn"):
177
  if movie_dict:
178
  actor_v = unlu_verileri[actor]['v']
179
  results = []
@@ -185,10 +185,11 @@ with col_match:
185
  top_matches = sorted(results, key=lambda x: x[1])[:5]
186
  for i, (film, score) in enumerate(top_matches, 1):
187
  pct = round((1 - score) * 100, 1)
188
- st.success(f"**{i}. {film}** (%{pct})")
 
189
  st.progress(pct / 100)
190
  else:
191
  st.write("Waiting for selection... / Seçim bekleniyor...")
192
 
193
  st.markdown("---")
194
- st.info("💡 **How it works?**: Based on available image assets.")
 
4
  import random
5
  import os
6
 
7
+ # --- TİTREMEYİ ÖNLEYİCİ VE TASARIM CSS ---
8
  st.set_page_config(page_title="CastMatch AI", layout="wide")
9
  st.markdown("""
10
  <style>
 
12
  max-height: 400px;
13
  object-fit: contain;
14
  }
 
15
  div.stButton > button:first-child {
16
  width: 100%;
17
  text-align: left;
18
  border: 1px solid #f0f2f6;
19
  padding: 5px 10px;
 
20
  }
21
  div.stButton > button:first-child:hover {
22
  border-color: #ff4b4b;
 
94
 
95
  unlu_verileri = klasordeki_unluleri_getir()
96
 
97
+ # --- SESSION STATE (Seçimi Takip Etmek İçin) ---
98
  if 'selected_actor' not in st.session_state:
99
  st.session_state.selected_actor = None
100
 
 
102
  st.sidebar.title("🔍 Control Panel / Kontrol Paneli")
103
  st.sidebar.markdown("---")
104
 
 
105
  gender_choice = st.sidebar.radio(
106
  "1. Select Category / Kategori Seçin:",
107
  ["Male / Erkek", "Female / Kadın"],
 
111
  filtered_names = [name for name, data in unlu_verileri.items() if data['c'] == gender_choice]
112
 
113
  st.sidebar.markdown(f"### 📋 Available Cast / Mevcut Oyuncular")
 
114
 
115
+ # SOL PANEL BUTONLARI
116
  for n in filtered_names:
117
+ if st.sidebar.button(f"👤 {n}", key=f"sb_btn_{n}"):
118
  st.session_state.selected_actor = n
119
+ st.rerun()
120
 
121
  # --- ANA EKRAN ---
122
+ st.title("🎬 CastMatch AI: Talent Matching System / Yetenek Eşleştirme Sistemi")
123
+ st.markdown("#### Discover the perfect roles for global stars! / Dünya yıldızları için en ideal rolleri keşfedin!")
124
  st.markdown("---")
125
 
126
  col_actor, col_match = st.columns([1, 2])
 
128
  with col_actor:
129
  st.subheader("👤 Pick an Actor / Oyuncu Seç")
130
 
131
+ # KUTU OTOMATİK DOLSUN DİYE INDEX AYARLANDI:
132
+ # Eğer sidebar'dan seçilen isim filtered_names içindeyse onun sırasını bulup Selectbox'a veriyoruz.
133
+ try:
134
+ current_index = filtered_names.index(st.session_state.selected_actor) if st.session_state.selected_actor in filtered_names else None
135
+ except ValueError:
136
+ current_index = None
137
+
138
+ selected_actor_box = st.selectbox(
139
  "Select from list / Listeden seçin:",
140
  filtered_names,
141
+ index=current_index,
142
  placeholder="Choose an actor... / Bir oyuncu seçin...",
143
  key="main_selectbox"
144
  )
145
 
146
+ # Eğer kutudan manuel seçim yapılırsa state'i güncelle
147
+ if selected_actor_box != st.session_state.selected_actor:
148
+ st.session_state.selected_actor = selected_actor_box
149
+ if selected_actor_box:
 
150
  st.rerun()
151
 
152
+ # RESİM GÖSTERİMİ
153
  if st.session_state.selected_actor:
154
  actor = st.session_state.selected_actor
155
  found_path = None
 
160
  break
161
 
162
  if found_path:
163
+ st.image(found_path, caption=f"Profile / Profil: {actor}", use_container_width=True)
164
  else:
165
  st.error("Image not found. / Resim bulunamadı.")
166
  else:
167
  st.info("Please select an actor. / Lütfen bir oyuncu seçin.")
168
 
169
  with col_match:
170
+ st.subheader("🎯 Best Career Matches / En İyi Kariyer Eşleşmeleri")
171
 
172
  if st.session_state.selected_actor:
173
  actor = st.session_state.selected_actor
174
+ st.write(f"Comparing {actor}'s DNA... / {actor} kariyer DNA'sı karşılaştırılıyor...")
175
 
176
+ if st.button("🚀 Match and Recommend / Eşleştir ve Öner", key="match_btn"):
177
  if movie_dict:
178
  actor_v = unlu_verileri[actor]['v']
179
  results = []
 
185
  top_matches = sorted(results, key=lambda x: x[1])[:5]
186
  for i, (film, score) in enumerate(top_matches, 1):
187
  pct = round((1 - score) * 100, 1)
188
+ st.success(f"**{i}. {film}**")
189
+ st.write(f"Match Score / Uyum Skoru: **%{pct}**")
190
  st.progress(pct / 100)
191
  else:
192
  st.write("Waiting for selection... / Seçim bekleniyor...")
193
 
194
  st.markdown("---")
195
+ st.info("💡 **How it works? / Nasıl çalışır?**: Based on available image assets. / Mevcut resim dosyalarına dayanarak çalışır.")