Update app.py
Browse files
app.py
CHANGED
|
@@ -16,8 +16,7 @@ def load_data():
|
|
| 16 |
model_data = load_data()
|
| 17 |
movie_dict = model_data['movie_dict'] if model_data else {}
|
| 18 |
|
| 19 |
-
# --- 2. OYUNCU DNA VERİTABANI ---
|
| 20 |
-
# Sylvester Stallone 1. sırada, liste sırası korunur.
|
| 21 |
tum_unlu_verileri = {
|
| 22 |
"Sylvester Stallone": {"c": "Male / Erkek", "v": [0.9, 0.2, 0.1, 0.1, 0.1, 0.8]},
|
| 23 |
"Robert De Niro": {"c": "Male / Erkek", "v": [0.2, 0.1, 0.1, 0.9, 0.1, 0.8]},
|
|
@@ -61,24 +60,14 @@ tum_unlu_verileri = {
|
|
| 61 |
# --- ARAYÜZ AYARLARI ---
|
| 62 |
st.set_page_config(page_title="CastMatch AI", layout="wide")
|
| 63 |
|
| 64 |
-
# --- 3. DİNAMİK FİLTRELEME (Resim Klasörü
|
|
|
|
| 65 |
resim_klasoru = "40 resim"
|
| 66 |
|
| 67 |
-
def
|
| 68 |
-
|
| 69 |
-
return tum_unlu_verileri
|
| 70 |
-
dosyalar = [f.lower() for f in os.listdir(resim_klasoru)]
|
| 71 |
-
mevcut = {}
|
| 72 |
-
for isim, veri in tum_unlu_verileri.items():
|
| 73 |
-
# Dosya ismi kontrolü
|
| 74 |
-
clean_name = isim.lower().replace(" ", "_")
|
| 75 |
-
if any(clean_name in d or isim.lower() in d for d in dosyalar):
|
| 76 |
-
mevcut[isim] = veri
|
| 77 |
-
return mevcut if mevcut else tum_unlu_verileri
|
| 78 |
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
# --- SOL PANEL (SIDEBAR) ---
|
| 82 |
st.sidebar.title("🔍 Control Panel / Kontrol Paneli")
|
| 83 |
st.sidebar.markdown("---")
|
| 84 |
|
|
@@ -87,54 +76,60 @@ gender_choice = st.sidebar.radio(
|
|
| 87 |
["Male / Erkek", "Female / Kadın"]
|
| 88 |
)
|
| 89 |
|
| 90 |
-
#
|
| 91 |
-
filtered_names =
|
| 92 |
-
|
| 93 |
st.sidebar.markdown(f"### 📋 Available Cast / Mevcut Oyuncular")
|
| 94 |
for n in filtered_names:
|
| 95 |
st.sidebar.write(f"• {n}")
|
| 96 |
|
| 97 |
# --- ANA EKRAN ---
|
| 98 |
st.title("🎬 CastMatch AI: Talent Matching System / Yetenek Eşleştirme Sistemi")
|
| 99 |
-
st.markdown("#### Discover the perfect roles for global stars!")
|
| 100 |
st.markdown("---")
|
| 101 |
|
| 102 |
col_actor, col_match = st.columns([1, 2])
|
| 103 |
|
| 104 |
with col_actor:
|
| 105 |
st.subheader("👤 Pick an Actor / Oyuncu Seç")
|
| 106 |
-
selected_actor = st.selectbox(
|
|
|
|
|
|
|
|
|
|
| 107 |
|
| 108 |
-
#
|
| 109 |
-
|
| 110 |
|
| 111 |
if selected_actor != "Choose... / Seçiniz...":
|
| 112 |
found_path = None
|
| 113 |
-
|
| 114 |
if os.path.exists(resim_klasoru):
|
|
|
|
| 115 |
for f in os.listdir(resim_klasoru):
|
| 116 |
-
if
|
| 117 |
found_path = os.path.join(resim_klasoru, f)
|
| 118 |
break
|
| 119 |
|
| 120 |
if found_path:
|
| 121 |
-
|
| 122 |
else:
|
| 123 |
-
|
|
|
|
| 124 |
else:
|
| 125 |
-
|
| 126 |
|
| 127 |
with col_match:
|
| 128 |
st.subheader("🎯 Best Career Matches / En İyi Kariyer Eşleşmeleri")
|
| 129 |
|
| 130 |
if st.button("🚀 Match and Recommend / Eşleştir ve Öner") and selected_actor != "Choose... / Seçiniz...":
|
| 131 |
if movie_dict:
|
| 132 |
-
actor_v =
|
| 133 |
results = []
|
|
|
|
| 134 |
for i in movie_dict:
|
| 135 |
-
#
|
| 136 |
dist = spatial.distance.cosine(actor_v, movie_dict[i][1][:6])
|
| 137 |
-
dist = max(0, min(1, dist))
|
|
|
|
| 138 |
results.append((movie_dict[i][0], dist))
|
| 139 |
|
| 140 |
top_matches = sorted(results, key=lambda x: x[1])[:5]
|
|
@@ -142,7 +137,7 @@ with col_match:
|
|
| 142 |
for i, (film, score) in enumerate(top_matches, 1):
|
| 143 |
# Skoru % olarak hesapla
|
| 144 |
pct = round((1 - score) * 100, 1)
|
| 145 |
-
pct = max(0, min(100, pct))
|
| 146 |
|
| 147 |
st.success(f"**{i}. {film}**")
|
| 148 |
st.write(f"Match Score / Uyum Skoru: **%{pct}**")
|
|
|
|
| 16 |
model_data = load_data()
|
| 17 |
movie_dict = model_data['movie_dict'] if model_data else {}
|
| 18 |
|
| 19 |
+
# --- 2. OYUNCU DNA VERİTABANI (Stallone 1. sırada) ---
|
|
|
|
| 20 |
tum_unlu_verileri = {
|
| 21 |
"Sylvester Stallone": {"c": "Male / Erkek", "v": [0.9, 0.2, 0.1, 0.1, 0.1, 0.8]},
|
| 22 |
"Robert De Niro": {"c": "Male / Erkek", "v": [0.2, 0.1, 0.1, 0.9, 0.1, 0.8]},
|
|
|
|
| 60 |
# --- ARAYÜZ AYARLARI ---
|
| 61 |
st.set_page_config(page_title="CastMatch AI", layout="wide")
|
| 62 |
|
| 63 |
+
# --- 3. DİNAMİK FİLTRELEME (40 Resim Klasörü) ---
|
| 64 |
+
# Klasörün adını tam buraya yazıyoruz.
|
| 65 |
resim_klasoru = "40 resim"
|
| 66 |
|
| 67 |
+
def get_filtered_names(gender):
|
| 68 |
+
return [name for name in tum_unlu_verileri.keys() if tum_unlu_verileri[name]['c'] == gender]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
+
# --- SOL PANEL (Burası düzeltildi) ---
|
|
|
|
|
|
|
| 71 |
st.sidebar.title("🔍 Control Panel / Kontrol Paneli")
|
| 72 |
st.sidebar.markdown("---")
|
| 73 |
|
|
|
|
| 76 |
["Male / Erkek", "Female / Kadın"]
|
| 77 |
)
|
| 78 |
|
| 79 |
+
# Sidebar'da oyuncu listesini göster
|
| 80 |
+
filtered_names = get_filtered_names(gender_choice)
|
|
|
|
| 81 |
st.sidebar.markdown(f"### 📋 Available Cast / Mevcut Oyuncular")
|
| 82 |
for n in filtered_names:
|
| 83 |
st.sidebar.write(f"• {n}")
|
| 84 |
|
| 85 |
# --- ANA EKRAN ---
|
| 86 |
st.title("🎬 CastMatch AI: Talent Matching System / Yetenek Eşleştirme Sistemi")
|
| 87 |
+
st.markdown("#### Discover the perfect roles for global stars! / Dünya yıldızları için en ideal rolleri keşfedin!")
|
| 88 |
st.markdown("---")
|
| 89 |
|
| 90 |
col_actor, col_match = st.columns([1, 2])
|
| 91 |
|
| 92 |
with col_actor:
|
| 93 |
st.subheader("👤 Pick an Actor / Oyuncu Seç")
|
| 94 |
+
selected_actor = st.selectbox(
|
| 95 |
+
"Select from list / Listeden seçin:",
|
| 96 |
+
["Choose... / Seçiniz..."] + filtered_names
|
| 97 |
+
)
|
| 98 |
|
| 99 |
+
# Titremeyi engelleyen sabit alan
|
| 100 |
+
image_placeholder = st.empty()
|
| 101 |
|
| 102 |
if selected_actor != "Choose... / Seçiniz...":
|
| 103 |
found_path = None
|
| 104 |
+
# Klasör içindeki resimleri tara
|
| 105 |
if os.path.exists(resim_klasoru):
|
| 106 |
+
search_name = selected_actor.lower().replace(" ", "_")
|
| 107 |
for f in os.listdir(resim_klasoru):
|
| 108 |
+
if search_name in f.lower() or selected_actor.lower() in f.lower():
|
| 109 |
found_path = os.path.join(resim_klasoru, f)
|
| 110 |
break
|
| 111 |
|
| 112 |
if found_path:
|
| 113 |
+
image_placeholder.image(found_path, use_container_width=True)
|
| 114 |
else:
|
| 115 |
+
# Burası senin hata aldığın kısım, İngilizce/Türkçe eklendi
|
| 116 |
+
image_placeholder.error(f"Image not found in '{resim_klasoru}' folder / '{resim_klasoru}' klasöründe resim bulunamadı.")
|
| 117 |
else:
|
| 118 |
+
image_placeholder.info("Please select an actor / Lütfen bir oyuncu seçin.")
|
| 119 |
|
| 120 |
with col_match:
|
| 121 |
st.subheader("🎯 Best Career Matches / En İyi Kariyer Eşleşmeleri")
|
| 122 |
|
| 123 |
if st.button("🚀 Match and Recommend / Eşleştir ve Öner") and selected_actor != "Choose... / Seçiniz...":
|
| 124 |
if movie_dict:
|
| 125 |
+
actor_v = tum_unlu_verileri[selected_actor]['v']
|
| 126 |
results = []
|
| 127 |
+
|
| 128 |
for i in movie_dict:
|
| 129 |
+
# SKOR HATASI ÇÖZÜMÜ: 0 ile 1 arasına kilitleme
|
| 130 |
dist = spatial.distance.cosine(actor_v, movie_dict[i][1][:6])
|
| 131 |
+
dist = max(0, min(1, dist))
|
| 132 |
+
|
| 133 |
results.append((movie_dict[i][0], dist))
|
| 134 |
|
| 135 |
top_matches = sorted(results, key=lambda x: x[1])[:5]
|
|
|
|
| 137 |
for i, (film, score) in enumerate(top_matches, 1):
|
| 138 |
# Skoru % olarak hesapla
|
| 139 |
pct = round((1 - score) * 100, 1)
|
| 140 |
+
pct = max(0, min(100, pct)) # Negatif veya 100 üstü olmasın
|
| 141 |
|
| 142 |
st.success(f"**{i}. {film}**")
|
| 143 |
st.write(f"Match Score / Uyum Skoru: **%{pct}**")
|