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,7 @@ def load_data():
|
|
| 16 |
model_data = load_data()
|
| 17 |
movie_dict = model_data['movie_dict'] if model_data else {}
|
| 18 |
|
| 19 |
-
# 2.
|
| 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,48 +57,28 @@ 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 |
-
# --- RESİM KLASÖRÜ ---
|
| 61 |
-
resim_klasoru = os.path.join(os.getcwd(), "40 resim")
|
| 62 |
-
|
| 63 |
# --- ARAYÜZ AYARLARI ---
|
| 64 |
st.set_page_config(page_title="CastMatch AI", layout="wide")
|
| 65 |
|
| 66 |
-
# SENKRONİZASYON İÇİN STATE
|
| 67 |
-
if "secili_oyuncu" not in st.session_state:
|
| 68 |
-
st.session_state.secili_oyuncu = "Sylvester Stallone"
|
| 69 |
-
|
| 70 |
# --- SOL PANEL (SIDEBAR) ---
|
| 71 |
st.sidebar.title("🔍 Control Panel / Kontrol Paneli")
|
| 72 |
st.sidebar.markdown("---")
|
| 73 |
|
| 74 |
gender_choice = st.sidebar.radio(
|
| 75 |
"1. Select Category / Kategori Seçin:",
|
| 76 |
-
["Male / Erkek", "Female / Kadın"]
|
| 77 |
-
key="gender_radio"
|
| 78 |
)
|
| 79 |
|
| 80 |
-
#
|
|
|
|
| 81 |
filtered_names = [name for name, data in tum_unlu_verileri.items() if data['c'] == gender_choice]
|
| 82 |
|
| 83 |
-
# Kategori değişirse listedeki ilk ismi seç
|
| 84 |
-
if st.session_state.secili_oyuncu not in filtered_names:
|
| 85 |
-
st.session_state.secili_oyuncu = filtered_names[0]
|
| 86 |
-
|
| 87 |
st.sidebar.markdown(f"### 📋 Available Cast / Mevcut Oyuncular")
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
# Sol paneldeki tıklanabilir liste
|
| 94 |
-
st.sidebar.radio(
|
| 95 |
-
"Quick Select / Hızlı Seçim:",
|
| 96 |
-
filtered_names,
|
| 97 |
-
index=filtered_names.index(st.session_state.secili_oyuncu),
|
| 98 |
-
key="sb_radio",
|
| 99 |
-
on_change=sidebar_degisti,
|
| 100 |
-
label_visibility="collapsed"
|
| 101 |
-
)
|
| 102 |
|
| 103 |
# --- ANA EKRAN ---
|
| 104 |
st.title("🎬 CastMatch AI: Talent Matching System / Yetenek Eşleştirme Sistemi")
|
|
@@ -109,40 +89,33 @@ col_actor, col_match = st.columns([1, 2])
|
|
| 109 |
|
| 110 |
with col_actor:
|
| 111 |
st.subheader("👤 Pick an Actor / Oyuncu Seç")
|
|
|
|
| 112 |
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
for f in os.listdir(resim_klasoru):
|
| 131 |
-
if f.lower().startswith(search_target) or search_target_alt in f.lower():
|
| 132 |
-
found_path = os.path.join(resim_klasoru, f)
|
| 133 |
-
break
|
| 134 |
-
|
| 135 |
-
if found_path:
|
| 136 |
-
st.image(found_path, caption=f"Profile: {selected_actor}", use_container_width=True)
|
| 137 |
-
else:
|
| 138 |
-
st.warning(f"Resim bulunamadı / Image not found: {selected_actor}")
|
| 139 |
|
| 140 |
with col_match:
|
| 141 |
st.subheader("🎯 Best Career Matches / En İyi Kariyer Eşleşmeleri")
|
| 142 |
-
st.write("Comparing the star's DNA with movie roles...
|
| 143 |
|
| 144 |
-
if st.button("🚀 Match and Recommend / Eşleştir ve Öner"):
|
| 145 |
if movie_dict:
|
|
|
|
| 146 |
actor_v = tum_unlu_verileri[selected_actor]['v']
|
| 147 |
results = []
|
| 148 |
for i in movie_dict:
|
|
|
|
| 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. 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 |
"Cameron Diaz": {"c": "Female / Kadın", "v": [0.1, 0.2, 0.95, 0.7, 0.1, 0.1]}
|
| 58 |
}
|
| 59 |
|
|
|
|
|
|
|
|
|
|
| 60 |
# --- ARAYÜZ AYARLARI ---
|
| 61 |
st.set_page_config(page_title="CastMatch AI", layout="wide")
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
# --- SOL PANEL (SIDEBAR) ---
|
| 64 |
st.sidebar.title("🔍 Control Panel / Kontrol Paneli")
|
| 65 |
st.sidebar.markdown("---")
|
| 66 |
|
| 67 |
gender_choice = st.sidebar.radio(
|
| 68 |
"1. Select Category / Kategori Seçin:",
|
| 69 |
+
["Male / Erkek", "Female / Kadın"]
|
|
|
|
| 70 |
)
|
| 71 |
|
| 72 |
+
# CRITICAL FIX: Filtrelemeyi klasörden değil, doğrudan ana veritabanından yapıyoruz.
|
| 73 |
+
# Böylece resim klasörü okunmasa bile isimler kaybolmaz.
|
| 74 |
filtered_names = [name for name, data in tum_unlu_verileri.items() if data['c'] == gender_choice]
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
st.sidebar.markdown(f"### 📋 Available Cast / Mevcut Oyuncular")
|
| 77 |
+
if not filtered_names:
|
| 78 |
+
st.sidebar.warning("No players found.")
|
| 79 |
+
else:
|
| 80 |
+
for n in filtered_names:
|
| 81 |
+
st.sidebar.write(f"• {n}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
# --- ANA EKRAN ---
|
| 84 |
st.title("🎬 CastMatch AI: Talent Matching System / Yetenek Eşleştirme Sistemi")
|
|
|
|
| 89 |
|
| 90 |
with col_actor:
|
| 91 |
st.subheader("👤 Pick an Actor / Oyuncu Seç")
|
| 92 |
+
selected_actor = st.selectbox("Select from list / Listeden seçin:", filtered_names if filtered_names else ["Yok"])
|
| 93 |
|
| 94 |
+
if selected_actor != "Yok":
|
| 95 |
+
resim_klasoru = os.path.join(os.getcwd(), "40 resim")
|
| 96 |
+
found_path = None
|
| 97 |
+
|
| 98 |
+
# Resim arama mantığını esnettik
|
| 99 |
+
if os.path.exists(resim_klasoru):
|
| 100 |
+
search_target = selected_actor.replace(" ", "_").lower()
|
| 101 |
+
for f in os.listdir(resim_klasoru):
|
| 102 |
+
if f.lower().startswith(search_target) or selected_actor.lower() in f.lower():
|
| 103 |
+
found_path = os.path.join(resim_klasoru, f)
|
| 104 |
+
break
|
| 105 |
+
|
| 106 |
+
if found_path:
|
| 107 |
+
st.image(found_path, caption=f"Profile: {selected_actor}", use_container_width=True)
|
| 108 |
+
else:
|
| 109 |
+
# Resim yoksa isim kaybolmasın, sadece hata mesajı verilsin
|
| 110 |
+
st.info(f"Resim dosyası '40 resim' klasöründe bulunamadı: {selected_actor}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
with col_match:
|
| 113 |
st.subheader("🎯 Best Career Matches / En İyi Kariyer Eşleşmeleri")
|
| 114 |
+
st.write("Comparing the star's DNA with movie roles...")
|
| 115 |
|
| 116 |
+
if st.button("🚀 Match and Recommend / Eşleştir ve Öner") and selected_actor != "Yok":
|
| 117 |
if movie_dict:
|
| 118 |
+
# Veriyi 'tum_unlu_verileri' üzerinden çekiyoruz (Daha güvenli)
|
| 119 |
actor_v = tum_unlu_verileri[selected_actor]['v']
|
| 120 |
results = []
|
| 121 |
for i in movie_dict:
|