ESMATUGBA commited on
Commit
5d92bae
·
verified ·
1 Parent(s): 6cbfd2e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -36
app.py CHANGED
@@ -4,11 +4,10 @@ from scipy import spatial
4
  import random
5
  import os
6
 
7
- # --- TİTREMEYİ ÖNLEYİCİ CSS (Arayüz yapını bozmaz, sadece sabitler) ---
8
  st.set_page_config(page_title="CastMatch AI", layout="wide")
9
  st.markdown("""
10
  <style>
11
- /* Resim kutusunun boyutunu sabitleyerek sayfanın zıplamasını engeller */
12
  [data-testid="stImage"] img {
13
  max-height: 400px;
14
  object-fit: contain;
@@ -16,7 +15,7 @@ st.markdown("""
16
  </style>
17
  """, unsafe_allow_html=True)
18
 
19
- # 1. MODELİ YÜKLE (Cache eklendi: Dosyayı her saniye okumasını engeller)
20
  @st.cache_resource
21
  def load_data():
22
  try:
@@ -28,7 +27,7 @@ def load_data():
28
  model_data = load_data()
29
  movie_dict = model_data['movie_dict'] if model_data else {}
30
 
31
- # 2. TÜM OYUNCU DNA VERİTABANI (Senin orijinal verilerin)
32
  tum_unlu_verileri = {
33
  "Sylvester Stallone": {"c": "Male / Erkek", "v": [0.9, 0.2, 0.1, 0.1, 0.1, 0.8]},
34
  "Robert De Niro": {"c": "Male / Erkek", "v": [0.2, 0.1, 0.1, 0.9, 0.1, 0.8]},
@@ -70,9 +69,9 @@ tum_unlu_verileri = {
70
  }
71
 
72
  # --- DİNAMİK FİLTRELEME ---
73
- resim_klasoru = os.getcwd() # Hugging Face için ana dizine ayarlandı
74
 
75
- @st.cache_data # Dosya sistemini sürekli taramasını engeller
76
  def klasordeki_unluleri_getir():
77
  mevcut_unlular = {}
78
  dosyalar = [f.lower() for f in os.listdir(resim_klasoru)]
@@ -92,31 +91,37 @@ st.sidebar.markdown("---")
92
  gender_choice = st.sidebar.radio(
93
  "1. Select Category / Kategori Seçin:",
94
  ["Male / Erkek", "Female / Kadın"],
95
- key="gender_radio" # Sabit key titremeyi azaltır
96
  )
97
 
98
  filtered_names = [name for name, data in unlu_verileri.items() if data['c'] == gender_choice]
99
 
100
  st.sidebar.markdown(f"### 📋 Available Cast / Mevcut Oyuncular")
101
  if not filtered_names:
102
- st.sidebar.warning("Bu kategoride resim bulunamadı.")
103
  for n in filtered_names:
104
  st.sidebar.write(f"• {n}")
105
 
106
  # --- ANA EKRAN ---
107
- st.title("🎬 CastMatch AI: Talent Matching System")
108
- st.markdown("#### Discover the perfect roles for global stars!")
109
  st.markdown("---")
110
 
111
  col_actor, col_match = st.columns([1, 2])
112
 
113
  with col_actor:
114
  st.subheader("👤 Pick an Actor / Oyuncu Seç")
115
- selected_actor = st.selectbox("Select from list:", filtered_names if filtered_names else ["Yok"], key="actor_select")
 
 
 
 
 
 
 
116
 
117
- # Resim kutusu (boşluk titremesini engellemek için container içine alındı)
118
  with st.container():
119
- if selected_actor != "Yok":
120
  found_path = None
121
  search_target = selected_actor.replace(" ", "_").lower()
122
  for f in os.listdir(resim_klasoru):
@@ -125,32 +130,37 @@ with col_actor:
125
  break
126
 
127
  if found_path:
128
- st.image(found_path, caption=f"Profile: {selected_actor}", use_container_width=True)
129
  else:
130
- st.error("Resim yüklenemedi.")
 
 
131
 
132
  with col_match:
133
- st.subheader("🎯 Best Career Matches")
134
- st.write("Comparing the star's DNA with movie roles...")
135
 
136
- # Buton ve sonuçlar
137
- if st.button("🚀 Match and Recommend", key="match_button") and selected_actor != "Yok":
138
- if movie_dict:
139
- actor_v = unlu_verileri[selected_actor]['v']
140
- results = []
141
- for i in movie_dict:
142
- noise = random.uniform(0, 0.0001)
143
- dist = spatial.distance.cosine(actor_v, movie_dict[i][1][:6]) + noise
144
- results.append((movie_dict[i][0], dist))
145
-
146
- top_matches = sorted(results, key=lambda x: x[1])[:5]
147
- for i, (film, score) in enumerate(top_matches, 1):
148
- pct = round((1 - score) * 100, 1)
149
- st.success(f"**{i}. {film}**")
150
- st.write(f"Match Score: **%{pct}**")
151
- st.progress(pct / 100)
152
- else:
153
- st.error("Model dosyası eksik!")
 
 
 
 
154
 
155
  st.markdown("---")
156
- st.info("💡 **How it works?**: This AI analyzes career vectors based on available local assets.")
 
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>
 
11
  [data-testid="stImage"] img {
12
  max-height: 400px;
13
  object-fit: contain;
 
15
  </style>
16
  """, unsafe_allow_html=True)
17
 
18
+ # 1. MODELİ YÜKLE
19
  @st.cache_resource
20
  def load_data():
21
  try:
 
27
  model_data = load_data()
28
  movie_dict = model_data['movie_dict'] if model_data else {}
29
 
30
+ # 2. TÜM OYUNCU DNA VERİTABANI
31
  tum_unlu_verileri = {
32
  "Sylvester Stallone": {"c": "Male / Erkek", "v": [0.9, 0.2, 0.1, 0.1, 0.1, 0.8]},
33
  "Robert De Niro": {"c": "Male / Erkek", "v": [0.2, 0.1, 0.1, 0.9, 0.1, 0.8]},
 
69
  }
70
 
71
  # --- DİNAMİK FİLTRELEME ---
72
+ resim_klasoru = os.getcwd()
73
 
74
+ @st.cache_data
75
  def klasordeki_unluleri_getir():
76
  mevcut_unlular = {}
77
  dosyalar = [f.lower() for f in os.listdir(resim_klasoru)]
 
91
  gender_choice = st.sidebar.radio(
92
  "1. Select Category / Kategori Seçin:",
93
  ["Male / Erkek", "Female / Kadın"],
94
+ key="gender_radio"
95
  )
96
 
97
  filtered_names = [name for name, data in unlu_verileri.items() if data['c'] == gender_choice]
98
 
99
  st.sidebar.markdown(f"### 📋 Available Cast / Mevcut Oyuncular")
100
  if not filtered_names:
101
+ st.sidebar.warning("No images found. / Resim bulunamadı.")
102
  for n in filtered_names:
103
  st.sidebar.write(f"• {n}")
104
 
105
  # --- ANA EKRAN ---
106
+ st.title("🎬 CastMatch AI: Talent Matching System / Yetenek Eşleştirme Sistemi")
107
+ st.markdown("#### Discover the perfect roles for global stars! / Dünya yıldızları için en ideal rolleri keşfedin!")
108
  st.markdown("---")
109
 
110
  col_actor, col_match = st.columns([1, 2])
111
 
112
  with col_actor:
113
  st.subheader("👤 Pick an Actor / Oyuncu Seç")
114
+ # INDEX=None YAPARAK İLK AÇILIŞI BOŞ BIRAKIYORUZ
115
+ selected_actor = st.selectbox(
116
+ "Select from list / Listeden seçin:",
117
+ filtered_names if filtered_names else [],
118
+ index=None,
119
+ placeholder="Choose an actor... / Bir oyuncu seçin...",
120
+ key="actor_select"
121
+ )
122
 
 
123
  with st.container():
124
+ if selected_actor: # Eğer bir oyuncu seçildiyse (None değilse)
125
  found_path = None
126
  search_target = selected_actor.replace(" ", "_").lower()
127
  for f in os.listdir(resim_klasoru):
 
130
  break
131
 
132
  if found_path:
133
+ st.image(found_path, caption=f"Profile / Profil: {selected_actor}", use_container_width=True)
134
  else:
135
+ st.error("Image could not be loaded. / Resim yüklenemedi.")
136
+ else:
137
+ st.info("Please select an actor to start. / Başlamak için lütfen bir oyuncu seçin.")
138
 
139
  with col_match:
140
+ st.subheader("🎯 Best Career Matches / En İyi Kariyer Eşleşmeleri")
 
141
 
142
+ if selected_actor: # Seçim varsa karşılaştırma göster
143
+ st.write(f"Comparing {selected_actor}'s DNA with roles... / {selected_actor} için DNA rolleriyle karşılaştırılıyor...")
144
+
145
+ if st.button("🚀 Match and Recommend / Eşleştir ve Öner", key="match_button"):
146
+ if movie_dict:
147
+ actor_v = unlu_verileri[selected_actor]['v']
148
+ results = []
149
+ for i in movie_dict:
150
+ noise = random.uniform(0, 0.0001)
151
+ dist = spatial.distance.cosine(actor_v, movie_dict[i][1][:6]) + noise
152
+ results.append((movie_dict[i][0], dist))
153
+
154
+ top_matches = sorted(results, key=lambda x: x[1])[:5]
155
+ for i, (film, score) in enumerate(top_matches, 1):
156
+ pct = round((1 - score) * 100, 1)
157
+ st.success(f"**{i}. {film}**")
158
+ st.write(f"Match Score / Uyum Skoru: **%{pct}**")
159
+ st.progress(pct / 100)
160
+ else:
161
+ st.error("Model file missing! / Model dosyası eksik!")
162
+ else:
163
+ st.write("Waiting for selection... / Seçim yapılması bekleniyor...")
164
 
165
  st.markdown("---")
166
+ st.info("💡 **How it works? / Nasıl çalışır?**: This AI analyzes career vectors based on available local assets. / Bu yapay zeka, mevcut yerel varlıklara (resimlere) dayanarak kariyer vektörlerini analiz eder.")