Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ 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:
|
|
@@ -16,7 +16,8 @@ def load_data():
|
|
| 16 |
model_data = load_data()
|
| 17 |
movie_dict = model_data['movie_dict'] if model_data else {}
|
| 18 |
|
| 19 |
-
# 2. TÜM OYUNCU DNA VERİTABANI
|
|
|
|
| 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]},
|
|
@@ -57,88 +58,90 @@ tum_unlu_verileri = {
|
|
| 57 |
"Cameron Diaz": {"c": "Female / Kadın", "v": [0.1, 0.2, 0.95, 0.7, 0.1, 0.1]}
|
| 58 |
}
|
| 59 |
|
| 60 |
-
# --- DİNAMİK FİLTRELEME (
|
| 61 |
-
resim_klasoru =
|
| 62 |
|
| 63 |
def klasordeki_unluleri_getir():
|
| 64 |
mevcut_unlular = {}
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
unlu_verileri = klasordeki_unluleri_getir()
|
| 75 |
|
| 76 |
# --- ARAYÜZ AYARLARI ---
|
| 77 |
st.set_page_config(page_title="CastMatch AI", layout="wide")
|
| 78 |
|
| 79 |
-
# --- SOL PANEL
|
| 80 |
st.sidebar.title("🔍 Control Panel / Kontrol Paneli")
|
| 81 |
st.sidebar.markdown("---")
|
| 82 |
|
| 83 |
-
gender_choice = st.sidebar.radio(
|
| 84 |
-
"1. Select Category / Kategori Seçin:",
|
| 85 |
-
["Male / Erkek", "Female / Kadın"]
|
| 86 |
-
)
|
| 87 |
|
| 88 |
-
|
|
|
|
| 89 |
|
| 90 |
st.sidebar.markdown(f"### 📋 Available Cast / Mevcut Oyuncular")
|
| 91 |
-
if not filtered_names:
|
| 92 |
-
st.sidebar.warning("Bu kategoride resim bulunamadı. / No images in this category.")
|
| 93 |
for n in filtered_names:
|
| 94 |
st.sidebar.write(f"• {n}")
|
| 95 |
|
| 96 |
# --- ANA EKRAN ---
|
| 97 |
-
st.title("🎬 CastMatch AI: Talent Matching System
|
| 98 |
-
st.markdown("#### Discover the perfect roles for global stars!
|
| 99 |
st.markdown("---")
|
| 100 |
|
| 101 |
col_actor, col_match = st.columns([1, 2])
|
| 102 |
|
| 103 |
with col_actor:
|
| 104 |
st.subheader("👤 Pick an Actor / Oyuncu Seç")
|
| 105 |
-
selected_actor = st.selectbox("Select from list / Listeden seçin:",
|
| 106 |
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
| 108 |
found_path = None
|
| 109 |
search_target = selected_actor.replace(" ", "_").lower()
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
| 114 |
|
| 115 |
if found_path:
|
| 116 |
-
|
| 117 |
else:
|
| 118 |
-
|
|
|
|
|
|
|
| 119 |
|
| 120 |
with col_match:
|
| 121 |
-
st.subheader("🎯 Best Career Matches
|
| 122 |
-
st.
|
| 123 |
-
|
| 124 |
-
if st.button("🚀 Match and Recommend / Eşleştir ve Öner") and selected_actor != "Yok":
|
| 125 |
if movie_dict:
|
| 126 |
actor_v = unlu_verileri[selected_actor]['v']
|
| 127 |
results = []
|
| 128 |
for i in movie_dict:
|
| 129 |
-
|
| 130 |
-
dist = spatial.distance.cosine(actor_v, movie_dict[i][1][:6])
|
|
|
|
| 131 |
results.append((movie_dict[i][0], dist))
|
| 132 |
|
| 133 |
top_matches = sorted(results, key=lambda x: x[1])[:5]
|
| 134 |
for i, (film, score) in enumerate(top_matches, 1):
|
| 135 |
-
pct = round((1 - score) * 100, 1)
|
| 136 |
st.success(f"**{i}. {film}**")
|
| 137 |
-
st.write(f"Match Score
|
| 138 |
-
st.progress(pct / 100)
|
| 139 |
-
else:
|
| 140 |
-
st.error("Model dosyası eksik! / Model file missing!")
|
| 141 |
-
|
| 142 |
-
st.markdown("---")
|
| 143 |
-
# EN ALT BİLGİ NOTU DÜZELTİLDİ:
|
| 144 |
-
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.")
|
|
|
|
| 4 |
import random
|
| 5 |
import os
|
| 6 |
|
| 7 |
+
# --- 1. MODELİ YÜKLE ---
|
| 8 |
@st.cache_resource
|
| 9 |
def load_data():
|
| 10 |
try:
|
|
|
|
| 16 |
model_data = load_data()
|
| 17 |
movie_dict = model_data['movie_dict'] if model_data else {}
|
| 18 |
|
| 19 |
+
# --- 2. TÜM OYUNCU DNA VERİTABANI ---
|
| 20 |
+
# Stallone 1. sırada, format korundu.
|
| 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 |
+
# --- 3. DİNAMİK FİLTRELEME (Klasör Kontrolü) ---
|
| 62 |
+
resim_klasoru = "40 resim" # Klasör adı
|
| 63 |
|
| 64 |
def klasordeki_unluleri_getir():
|
| 65 |
mevcut_unlular = {}
|
| 66 |
+
# Eğer klasör yoksa, boş liste dönmesin diye tüm listeyi gösteriyoruz (Hata önleyici)
|
| 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 |
+
search_pattern1 = isim.lower().replace(" ", "_")
|
| 73 |
+
search_pattern2 = isim.lower()
|
| 74 |
+
# Klasörde isimle eşleşen dosya var mı?
|
| 75 |
+
if any(search_pattern1 in d or search_pattern2 in d for d in dosyalar):
|
| 76 |
+
mevcut_unlular[isim] = veri
|
| 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 |
# --- ARAYÜZ AYARLARI ---
|
| 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("1. Select Category / Kategori Seçin:", ["Male / Erkek", "Female / Kadın"])
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
+
# Seçilen cinsiyete göre oyuncular (Stallone sırası bozulmaz)
|
| 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")
|
|
|
|
|
|
|
| 96 |
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 |
|
| 104 |
col_actor, col_match = st.columns([1, 2])
|
| 105 |
|
| 106 |
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 |
+
# Titreme önleyici placeholder
|
| 111 |
+
image_placeholder = st.empty()
|
| 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().startswith(search_target) or selected_actor.lower() in f.lower():
|
| 120 |
+
found_path = os.path.join(resim_klasoru, f)
|
| 121 |
+
break
|
| 122 |
|
| 123 |
if found_path:
|
| 124 |
+
image_placeholder.image(found_path, use_container_width=True)
|
| 125 |
else:
|
| 126 |
+
image_placeholder.warning("Resim klasörde bulunamadı.")
|
| 127 |
+
else:
|
| 128 |
+
image_placeholder.info("Lütfen bir oyuncu seçin.")
|
| 129 |
|
| 130 |
with col_match:
|
| 131 |
+
st.subheader("🎯 Best Career Matches")
|
| 132 |
+
if st.button("🚀 Match and Recommend") and selected_actor != "Choose... / Seçiniz...":
|
|
|
|
|
|
|
| 133 |
if movie_dict:
|
| 134 |
actor_v = unlu_verileri[selected_actor]['v']
|
| 135 |
results = []
|
| 136 |
for i in movie_dict:
|
| 137 |
+
# 11.5 gibi hataları önleyen temiz matematik
|
| 138 |
+
dist = spatial.distance.cosine(actor_v, movie_dict[i][1][:6])
|
| 139 |
+
dist = max(0, min(1, dist)) # Skoru 0-1 arasında tut
|
| 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 |
+
pct = max(0, min(100, round((1 - score) * 100, 1)))
|
| 145 |
st.success(f"**{i}. {film}**")
|
| 146 |
+
st.write(f"Match Score: **%{pct}**")
|
| 147 |
+
st.progress(pct / 100)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|