Update app.py
Browse files
app.py
CHANGED
|
@@ -16,8 +16,8 @@ def load_data():
|
|
| 16 |
model_data = load_data()
|
| 17 |
movie_dict = model_data['movie_dict'] if model_data else {}
|
| 18 |
|
| 19 |
-
# --- 2.
|
| 20 |
-
# Stallone 1. sırada,
|
| 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]},
|
|
@@ -58,38 +58,36 @@ tum_unlu_verileri = {
|
|
| 58 |
"Cameron Diaz": {"c": "Female / Kadın", "v": [0.1, 0.2, 0.95, 0.7, 0.1, 0.1]}
|
| 59 |
}
|
| 60 |
|
| 61 |
-
# ---
|
| 62 |
-
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
| 67 |
if not os.path.exists(resim_klasoru):
|
| 68 |
-
return tum_unlu_verileri
|
| 69 |
-
|
| 70 |
dosyalar = [f.lower() for f in os.listdir(resim_klasoru)]
|
|
|
|
| 71 |
for isim, veri in tum_unlu_verileri.items():
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
# Eğer klasör var ama içi boşsa veya eşleşme yoksa yine tüm listeyi döndür
|
| 79 |
-
return mevcut_unlular if mevcut_unlular else tum_unlu_verileri
|
| 80 |
-
|
| 81 |
-
unlu_verileri = klasordeki_unluleri_getir()
|
| 82 |
|
| 83 |
-
|
| 84 |
-
st.set_page_config(page_title="CastMatch AI", layout="wide")
|
| 85 |
|
| 86 |
-
# --- SOL PANEL ---
|
| 87 |
st.sidebar.title("🔍 Control Panel / Kontrol Paneli")
|
| 88 |
st.sidebar.markdown("---")
|
| 89 |
|
| 90 |
-
gender_choice = st.sidebar.radio(
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
-
#
|
| 93 |
filtered_names = [name for name in unlu_verileri.keys() if unlu_verileri[name]['c'] == gender_choice]
|
| 94 |
|
| 95 |
st.sidebar.markdown(f"### 📋 Available Cast / Mevcut Oyuncular")
|
|
@@ -97,7 +95,7 @@ for n in filtered_names:
|
|
| 97 |
st.sidebar.write(f"• {n}")
|
| 98 |
|
| 99 |
# --- ANA EKRAN ---
|
| 100 |
-
st.title("🎬 CastMatch AI: Talent Matching System")
|
| 101 |
st.markdown("#### Discover the perfect roles for global stars!")
|
| 102 |
st.markdown("---")
|
| 103 |
|
|
@@ -107,41 +105,50 @@ with col_actor:
|
|
| 107 |
st.subheader("👤 Pick an Actor / Oyuncu Seç")
|
| 108 |
selected_actor = st.selectbox("Select from list / Listeden seçin:", ["Choose... / Seçiniz..."] + filtered_names)
|
| 109 |
|
| 110 |
-
#
|
| 111 |
-
|
| 112 |
|
| 113 |
if selected_actor != "Choose... / Seçiniz...":
|
| 114 |
found_path = None
|
| 115 |
search_target = selected_actor.replace(" ", "_").lower()
|
| 116 |
-
|
| 117 |
if os.path.exists(resim_klasoru):
|
| 118 |
for f in os.listdir(resim_klasoru):
|
| 119 |
-
if f.lower()
|
| 120 |
found_path = os.path.join(resim_klasoru, f)
|
| 121 |
break
|
| 122 |
|
| 123 |
if found_path:
|
| 124 |
-
|
| 125 |
else:
|
| 126 |
-
|
| 127 |
else:
|
| 128 |
-
|
| 129 |
|
| 130 |
with col_match:
|
| 131 |
-
st.subheader("🎯 Best Career Matches")
|
| 132 |
-
|
|
|
|
| 133 |
if movie_dict:
|
| 134 |
actor_v = unlu_verileri[selected_actor]['v']
|
| 135 |
results = []
|
| 136 |
for i in movie_dict:
|
| 137 |
-
# 11.5 gibi
|
| 138 |
dist = spatial.distance.cosine(actor_v, movie_dict[i][1][:6])
|
| 139 |
-
dist = max(0, min(1, dist)) #
|
| 140 |
results.append((movie_dict[i][0], dist))
|
| 141 |
|
| 142 |
top_matches = sorted(results, key=lambda x: x[1])[:5]
|
|
|
|
| 143 |
for i, (film, score) in enumerate(top_matches, 1):
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
| 145 |
st.success(f"**{i}. {film}**")
|
| 146 |
-
st.write(f"Match Score: **%{pct}**")
|
| 147 |
-
st.progress(pct / 100)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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]},
|
|
|
|
| 58 |
"Cameron Diaz": {"c": "Female / Kadın", "v": [0.1, 0.2, 0.95, 0.7, 0.1, 0.1]}
|
| 59 |
}
|
| 60 |
|
| 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ü Kontrolü) ---
|
| 65 |
+
resim_klasoru = "40 resim"
|
| 66 |
+
|
| 67 |
+
def get_available_actors():
|
| 68 |
if not os.path.exists(resim_klasoru):
|
| 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 |
+
unlu_verileri = get_available_actors()
|
|
|
|
| 80 |
|
| 81 |
+
# --- SOL PANEL (SIDEBAR) ---
|
| 82 |
st.sidebar.title("🔍 Control Panel / Kontrol Paneli")
|
| 83 |
st.sidebar.markdown("---")
|
| 84 |
|
| 85 |
+
gender_choice = st.sidebar.radio(
|
| 86 |
+
"1. Select Category / Kategori Seçin:",
|
| 87 |
+
["Male / Erkek", "Female / Kadın"]
|
| 88 |
+
)
|
| 89 |
|
| 90 |
+
# Cinsiyete göre filtrele (Sıralama bozulmadan)
|
| 91 |
filtered_names = [name for name in unlu_verileri.keys() if unlu_verileri[name]['c'] == gender_choice]
|
| 92 |
|
| 93 |
st.sidebar.markdown(f"### 📋 Available Cast / Mevcut Oyuncular")
|
|
|
|
| 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 |
|
|
|
|
| 105 |
st.subheader("👤 Pick an Actor / Oyuncu Seç")
|
| 106 |
selected_actor = st.selectbox("Select from list / Listeden seçin:", ["Choose... / Seçiniz..."] + filtered_names)
|
| 107 |
|
| 108 |
+
# TITREME ÖNLEYİCİ: Resim alanı için sabit bir container
|
| 109 |
+
image_area = st.container()
|
| 110 |
|
| 111 |
if selected_actor != "Choose... / Seçiniz...":
|
| 112 |
found_path = None
|
| 113 |
search_target = selected_actor.replace(" ", "_").lower()
|
|
|
|
| 114 |
if os.path.exists(resim_klasoru):
|
| 115 |
for f in os.listdir(resim_klasoru):
|
| 116 |
+
if search_target in f.lower() or selected_actor.lower() in f.lower():
|
| 117 |
found_path = os.path.join(resim_klasoru, f)
|
| 118 |
break
|
| 119 |
|
| 120 |
if found_path:
|
| 121 |
+
image_area.image(found_path, use_container_width=True)
|
| 122 |
else:
|
| 123 |
+
image_area.warning("Image not found in folder / Resim klasörde bulunamadı.")
|
| 124 |
else:
|
| 125 |
+
image_area.info("Please select an actor / Lütfen oyuncu seçin.")
|
| 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 = unlu_verileri[selected_actor]['v']
|
| 133 |
results = []
|
| 134 |
for i in movie_dict:
|
| 135 |
+
# 11.5 gibi hatalı skorları engellemek için Cosine Distance sabitleme
|
| 136 |
dist = spatial.distance.cosine(actor_v, movie_dict[i][1][:6])
|
| 137 |
+
dist = max(0, min(1, dist)) # 0 ile 1 arasına kilitle
|
| 138 |
results.append((movie_dict[i][0], dist))
|
| 139 |
|
| 140 |
top_matches = sorted(results, key=lambda x: x[1])[:5]
|
| 141 |
+
|
| 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}**")
|
| 149 |
+
st.progress(pct / 100)
|
| 150 |
+
else:
|
| 151 |
+
st.error("Model file missing / Model dosyası eksik!")
|
| 152 |
+
|
| 153 |
+
st.markdown("---")
|
| 154 |
+
st.info("💡 **How it works? / Nasıl çalışır?**: This AI analyzes career vectors based on assets in '40 resim' folder.")
|