Update app.py
Browse files
app.py
CHANGED
|
@@ -17,6 +17,7 @@ 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,15 +58,15 @@ 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 |
-
# --- ARAYÜZ
|
| 61 |
st.set_page_config(page_title="CastMatch AI", layout="wide")
|
| 62 |
|
| 63 |
-
# RESİM CACHE
|
| 64 |
@st.cache_data
|
| 65 |
def get_image_path(actor_name):
|
| 66 |
if not actor_name or actor_name == "Choose... / Seçiniz...":
|
| 67 |
return None
|
| 68 |
ana_dizin = os.getcwd()
|
|
|
|
| 69 |
search_term = actor_name.lower().replace(" ", "_")
|
| 70 |
search_term_plain = actor_name.lower()
|
| 71 |
for f in os.listdir(ana_dizin):
|
|
@@ -75,22 +76,12 @@ def get_image_path(actor_name):
|
|
| 75 |
return os.path.join(ana_dizin, f)
|
| 76 |
return None
|
| 77 |
|
| 78 |
-
# --- SOL PANEL ---
|
| 79 |
st.sidebar.title("🔍 Control Panel / Kontrol Paneli")
|
| 80 |
st.sidebar.markdown("---")
|
|
|
|
| 81 |
|
| 82 |
-
|
| 83 |
-
"1. Select Category / Kategori Seçin:",
|
| 84 |
-
["Male / Erkek", "Female / Kadın"]
|
| 85 |
-
)
|
| 86 |
|
| 87 |
-
# Sidebar'daki oyuncu listesi (Bilgilendirme amaçlı)
|
| 88 |
-
filtered_names = [name for name, data in tum_unlu_verileri.items() if data['c'] == gender_choice]
|
| 89 |
-
st.sidebar.markdown(f"### 📋 Available Cast / Mevcut Oyuncular")
|
| 90 |
-
for n in filtered_names:
|
| 91 |
-
st.sidebar.write(f"• {n}")
|
| 92 |
-
|
| 93 |
-
# --- ANA EKRAN ---
|
| 94 |
st.title("🎬 CastMatch AI: Talent Matching System / Yetenek Eşleştirme Sistemi")
|
| 95 |
st.markdown("#### Discover the perfect roles for global stars! / Dünya yıldızları için en ideal rolleri keşfedin!")
|
| 96 |
st.markdown("---")
|
|
@@ -99,29 +90,23 @@ col_actor, col_match = st.columns([1, 2])
|
|
| 99 |
|
| 100 |
with col_actor:
|
| 101 |
st.subheader("👤 Pick an Actor / Oyuncu Seç")
|
| 102 |
-
|
| 103 |
-
# Seçeneklerin en başına boş bir seçenek ekliyoruz (index=0 varsayılan olur)
|
| 104 |
options = ["Choose... / Seçiniz..."] + filtered_names
|
| 105 |
selected_actor = st.selectbox("Select from list / Listeden seçin:", options)
|
| 106 |
|
| 107 |
image_placeholder = st.empty()
|
| 108 |
-
|
| 109 |
-
# Eğer bir oyuncu seçilmişse (Seçiniz... değilse)
|
| 110 |
if selected_actor != "Choose... / Seçiniz...":
|
| 111 |
-
|
| 112 |
-
if
|
| 113 |
-
image_placeholder.image(
|
| 114 |
else:
|
| 115 |
image_placeholder.warning(f"⚠️ Resim bulunamadı: {selected_actor}")
|
| 116 |
else:
|
| 117 |
-
|
| 118 |
-
image_placeholder.info("Please select an actor to see the profile. / Profili görmek için bir oyuncu seçin.")
|
| 119 |
|
| 120 |
with col_match:
|
| 121 |
st.subheader("🎯 Best Career Matches / En İyi Kariyer Eşleşmeleri")
|
| 122 |
st.write("Comparing the star's DNA with movie roles... / Yıldızın DNA'sı film rolleriyle karşılaştırılıyor...")
|
| 123 |
|
| 124 |
-
# Sadece seçim yapıldığında buton çalışsın
|
| 125 |
if st.button("🚀 Match and Recommend / Eşleştir ve Öner"):
|
| 126 |
if selected_actor == "Choose... / Seçiniz...":
|
| 127 |
st.warning("Please pick an actor first! / Lütfen önce bir oyuncu seçin!")
|
|
@@ -129,13 +114,21 @@ with col_match:
|
|
| 129 |
actor_v = tum_unlu_verileri[selected_actor]['v']
|
| 130 |
results = []
|
| 131 |
for i in movie_dict:
|
| 132 |
-
|
| 133 |
-
dist = spatial.distance.cosine(actor_v, movie_dict[i][1][:6])
|
| 134 |
-
|
|
|
|
|
|
|
| 135 |
|
|
|
|
| 136 |
top_matches = sorted(results, key=lambda x: x[1])[:5]
|
|
|
|
| 137 |
for i, (film, score) in enumerate(top_matches, 1):
|
|
|
|
| 138 |
pct = round((1 - score) * 100, 1)
|
|
|
|
|
|
|
|
|
|
| 139 |
st.success(f"**{i}. {film}**")
|
| 140 |
st.write(f"Match Score / Uyum Skoru: **%{pct}**")
|
| 141 |
st.progress(pct / 100)
|
|
@@ -143,4 +136,4 @@ with col_match:
|
|
| 143 |
st.error("Model dosyası eksik!")
|
| 144 |
|
| 145 |
st.markdown("---")
|
| 146 |
-
st.info("💡 **How it works?
|
|
|
|
| 17 |
movie_dict = model_data['movie_dict'] if model_data else {}
|
| 18 |
|
| 19 |
# --- 2. OYUNCU DNA VERİTABANI ---
|
| 20 |
+
# Buradaki değerler tüm oyuncular için genel karakteri belirler.
|
| 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 ---
|
| 62 |
st.set_page_config(page_title="CastMatch AI", layout="wide")
|
| 63 |
|
|
|
|
| 64 |
@st.cache_data
|
| 65 |
def get_image_path(actor_name):
|
| 66 |
if not actor_name or actor_name == "Choose... / Seçiniz...":
|
| 67 |
return None
|
| 68 |
ana_dizin = os.getcwd()
|
| 69 |
+
# Hem boşluklu hem alt tireli aramayı destekler
|
| 70 |
search_term = actor_name.lower().replace(" ", "_")
|
| 71 |
search_term_plain = actor_name.lower()
|
| 72 |
for f in os.listdir(ana_dizin):
|
|
|
|
| 76 |
return os.path.join(ana_dizin, f)
|
| 77 |
return None
|
| 78 |
|
|
|
|
| 79 |
st.sidebar.title("🔍 Control Panel / Kontrol Paneli")
|
| 80 |
st.sidebar.markdown("---")
|
| 81 |
+
gender_choice = st.sidebar.radio("1. Select Category / Kategori Seçin:", ["Male / Erkek", "Female / Kadın"])
|
| 82 |
|
| 83 |
+
filtered_names = sorted([name for name, data in tum_unlu_verileri.items() if data['c'] == gender_choice])
|
|
|
|
|
|
|
|
|
|
| 84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
st.title("🎬 CastMatch AI: Talent Matching System / Yetenek Eşleştirme Sistemi")
|
| 86 |
st.markdown("#### Discover the perfect roles for global stars! / Dünya yıldızları için en ideal rolleri keşfedin!")
|
| 87 |
st.markdown("---")
|
|
|
|
| 90 |
|
| 91 |
with col_actor:
|
| 92 |
st.subheader("👤 Pick an Actor / Oyuncu Seç")
|
|
|
|
|
|
|
| 93 |
options = ["Choose... / Seçiniz..."] + filtered_names
|
| 94 |
selected_actor = st.selectbox("Select from list / Listeden seçin:", options)
|
| 95 |
|
| 96 |
image_placeholder = st.empty()
|
|
|
|
|
|
|
| 97 |
if selected_actor != "Choose... / Seçiniz...":
|
| 98 |
+
path = get_image_path(selected_actor)
|
| 99 |
+
if path:
|
| 100 |
+
image_placeholder.image(path, caption=f"Profile: {selected_actor}", use_container_width=True)
|
| 101 |
else:
|
| 102 |
image_placeholder.warning(f"⚠️ Resim bulunamadı: {selected_actor}")
|
| 103 |
else:
|
| 104 |
+
image_placeholder.info("Please select an actor. / Bir oyuncu seçin.")
|
|
|
|
| 105 |
|
| 106 |
with col_match:
|
| 107 |
st.subheader("🎯 Best Career Matches / En İyi Kariyer Eşleşmeleri")
|
| 108 |
st.write("Comparing the star's DNA with movie roles... / Yıldızın DNA'sı film rolleriyle karşılaştırılıyor...")
|
| 109 |
|
|
|
|
| 110 |
if st.button("🚀 Match and Recommend / Eşleştir ve Öner"):
|
| 111 |
if selected_actor == "Choose... / Seçiniz...":
|
| 112 |
st.warning("Please pick an actor first! / Lütfen önce bir oyuncu seçin!")
|
|
|
|
| 114 |
actor_v = tum_unlu_verileri[selected_actor]['v']
|
| 115 |
results = []
|
| 116 |
for i in movie_dict:
|
| 117 |
+
# Saf matematik: Mesafe ne kadar küçükse uyum o kadar yüksek
|
| 118 |
+
dist = spatial.distance.cosine(actor_v, movie_dict[i][1][:6])
|
| 119 |
+
# Titremeyi önlemek ve sıralamayı stabilize etmek için çok küçük bir rastlantısallık
|
| 120 |
+
noise = random.uniform(0, 0.00001)
|
| 121 |
+
results.append((movie_dict[i][0], dist + noise))
|
| 122 |
|
| 123 |
+
# Küçükten büyüğe sırala (en yakın olan en üstte)
|
| 124 |
top_matches = sorted(results, key=lambda x: x[1])[:5]
|
| 125 |
+
|
| 126 |
for i, (film, score) in enumerate(top_matches, 1):
|
| 127 |
+
# Skor % hesabını 1 - mesafe üzerinden yapıyoruz
|
| 128 |
pct = round((1 - score) * 100, 1)
|
| 129 |
+
# %0 ile %100 arasında kalmasını garanti et
|
| 130 |
+
pct = max(0, min(100, pct))
|
| 131 |
+
|
| 132 |
st.success(f"**{i}. {film}**")
|
| 133 |
st.write(f"Match Score / Uyum Skoru: **%{pct}**")
|
| 134 |
st.progress(pct / 100)
|
|
|
|
| 136 |
st.error("Model dosyası eksik!")
|
| 137 |
|
| 138 |
st.markdown("---")
|
| 139 |
+
st.info("💡 **How it works?**: This AI uses Cosine Similarity to compare talent vectors with movie genres.")
|