Update app.py
Browse files
app.py
CHANGED
|
@@ -12,13 +12,17 @@ st.markdown("""
|
|
| 12 |
max-height: 400px;
|
| 13 |
object-fit: contain;
|
| 14 |
}
|
| 15 |
-
/* Sidebar butonlarını daha
|
| 16 |
-
.stButton button {
|
| 17 |
width: 100%;
|
| 18 |
text-align: left;
|
| 19 |
-
border:
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
}
|
| 23 |
</style>
|
| 24 |
""", unsafe_allow_html=True)
|
|
@@ -92,7 +96,7 @@ def klasordeki_unluleri_getir():
|
|
| 92 |
|
| 93 |
unlu_verileri = klasordeki_unluleri_getir()
|
| 94 |
|
| 95 |
-
# --- SESSION STATE
|
| 96 |
if 'selected_actor' not in st.session_state:
|
| 97 |
st.session_state.selected_actor = None
|
| 98 |
|
|
@@ -100,6 +104,7 @@ if 'selected_actor' not in st.session_state:
|
|
| 100 |
st.sidebar.title("🔍 Control Panel / Kontrol Paneli")
|
| 101 |
st.sidebar.markdown("---")
|
| 102 |
|
|
|
|
| 103 |
gender_choice = st.sidebar.radio(
|
| 104 |
"1. Select Category / Kategori Seçin:",
|
| 105 |
["Male / Erkek", "Female / Kadın"],
|
|
@@ -109,16 +114,17 @@ gender_choice = st.sidebar.radio(
|
|
| 109 |
filtered_names = [name for name, data in unlu_verileri.items() if data['c'] == gender_choice]
|
| 110 |
|
| 111 |
st.sidebar.markdown(f"### 📋 Available Cast / Mevcut Oyuncular")
|
| 112 |
-
st.sidebar.caption("Click
|
| 113 |
|
| 114 |
-
#
|
| 115 |
for n in filtered_names:
|
| 116 |
-
if st.sidebar.button(f"👤 {n}", key=f"
|
| 117 |
st.session_state.selected_actor = n
|
|
|
|
| 118 |
|
| 119 |
# --- ANA EKRAN ---
|
| 120 |
-
st.title("🎬 CastMatch AI: Talent Matching System
|
| 121 |
-
st.markdown("#### Discover the perfect roles for global stars!
|
| 122 |
st.markdown("---")
|
| 123 |
|
| 124 |
col_actor, col_match = st.columns([1, 2])
|
|
@@ -126,47 +132,50 @@ col_actor, col_match = st.columns([1, 2])
|
|
| 126 |
with col_actor:
|
| 127 |
st.subheader("👤 Pick an Actor / Oyuncu Seç")
|
| 128 |
|
| 129 |
-
#
|
| 130 |
-
# Eğer sidebar
|
| 131 |
-
|
| 132 |
"Select from list / Listeden seçin:",
|
| 133 |
-
filtered_names
|
| 134 |
index=filtered_names.index(st.session_state.selected_actor) if st.session_state.selected_actor in filtered_names else None,
|
| 135 |
placeholder="Choose an actor... / Bir oyuncu seçin...",
|
| 136 |
-
key="
|
| 137 |
)
|
| 138 |
|
| 139 |
-
#
|
| 140 |
-
if
|
| 141 |
-
st.session_state.selected_actor =
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
|
|
|
| 157 |
else:
|
| 158 |
-
st.
|
|
|
|
|
|
|
| 159 |
|
| 160 |
with col_match:
|
| 161 |
-
st.subheader("🎯 Best Career Matches
|
| 162 |
|
| 163 |
if st.session_state.selected_actor:
|
| 164 |
-
|
| 165 |
-
st.write(f"Comparing {
|
| 166 |
|
| 167 |
-
if st.button("🚀 Match and Recommend
|
| 168 |
if movie_dict:
|
| 169 |
-
actor_v = unlu_verileri[
|
| 170 |
results = []
|
| 171 |
for i in movie_dict:
|
| 172 |
noise = random.uniform(0, 0.0001)
|
|
@@ -176,13 +185,10 @@ with col_match:
|
|
| 176 |
top_matches = sorted(results, key=lambda x: x[1])[:5]
|
| 177 |
for i, (film, score) in enumerate(top_matches, 1):
|
| 178 |
pct = round((1 - score) * 100, 1)
|
| 179 |
-
st.success(f"**{i}. {film}**")
|
| 180 |
-
st.write(f"Match Score / Uyum Skoru: **%{pct}**")
|
| 181 |
st.progress(pct / 100)
|
| 182 |
-
else:
|
| 183 |
-
st.error("Model file missing! / Model dosyası eksik!")
|
| 184 |
else:
|
| 185 |
-
st.write("Waiting for selection... / Seçim
|
| 186 |
|
| 187 |
st.markdown("---")
|
| 188 |
-
st.info("💡 **How it works?
|
|
|
|
| 12 |
max-height: 400px;
|
| 13 |
object-fit: contain;
|
| 14 |
}
|
| 15 |
+
/* Sidebar butonlarını daha belirgin ve geniş yapalım */
|
| 16 |
+
div.stButton > button:first-child {
|
| 17 |
width: 100%;
|
| 18 |
text-align: left;
|
| 19 |
+
border: 1px solid #f0f2f6;
|
| 20 |
+
padding: 5px 10px;
|
| 21 |
+
transition: all 0.3s;
|
| 22 |
+
}
|
| 23 |
+
div.stButton > button:first-child:hover {
|
| 24 |
+
border-color: #ff4b4b;
|
| 25 |
+
color: #ff4b4b;
|
| 26 |
}
|
| 27 |
</style>
|
| 28 |
""", unsafe_allow_html=True)
|
|
|
|
| 96 |
|
| 97 |
unlu_verileri = klasordeki_unluleri_getir()
|
| 98 |
|
| 99 |
+
# --- SESSION STATE ---
|
| 100 |
if 'selected_actor' not in st.session_state:
|
| 101 |
st.session_state.selected_actor = None
|
| 102 |
|
|
|
|
| 104 |
st.sidebar.title("🔍 Control Panel / Kontrol Paneli")
|
| 105 |
st.sidebar.markdown("---")
|
| 106 |
|
| 107 |
+
# Kategori değişince seçimi sıfırla
|
| 108 |
gender_choice = st.sidebar.radio(
|
| 109 |
"1. Select Category / Kategori Seçin:",
|
| 110 |
["Male / Erkek", "Female / Kadın"],
|
|
|
|
| 114 |
filtered_names = [name for name, data in unlu_verileri.items() if data['c'] == gender_choice]
|
| 115 |
|
| 116 |
st.sidebar.markdown(f"### 📋 Available Cast / Mevcut Oyuncular")
|
| 117 |
+
st.sidebar.caption("Click name to display / Görmek için isme basın")
|
| 118 |
|
| 119 |
+
# İSİMLERE BASINCA ÇALIŞMASI İÇİN BURASI DÜZELTİLDİ:
|
| 120 |
for n in filtered_names:
|
| 121 |
+
if st.sidebar.button(f"👤 {n}", key=f"sidebar_btn_{n}"):
|
| 122 |
st.session_state.selected_actor = n
|
| 123 |
+
st.rerun() # Sayfayı hemen yenileyerek resmi getirir
|
| 124 |
|
| 125 |
# --- ANA EKRAN ---
|
| 126 |
+
st.title("🎬 CastMatch AI: Talent Matching System")
|
| 127 |
+
st.markdown("#### Discover the perfect roles for global stars!")
|
| 128 |
st.markdown("---")
|
| 129 |
|
| 130 |
col_actor, col_match = st.columns([1, 2])
|
|
|
|
| 132 |
with col_actor:
|
| 133 |
st.subheader("👤 Pick an Actor / Oyuncu Seç")
|
| 134 |
|
| 135 |
+
# Selectbox state ile bağlantılı
|
| 136 |
+
# Eğer sidebar butonu basıldıysa o isim burada otomatik seçilir
|
| 137 |
+
selected_from_box = st.selectbox(
|
| 138 |
"Select from list / Listeden seçin:",
|
| 139 |
+
filtered_names,
|
| 140 |
index=filtered_names.index(st.session_state.selected_actor) if st.session_state.selected_actor in filtered_names else None,
|
| 141 |
placeholder="Choose an actor... / Bir oyuncu seçin...",
|
| 142 |
+
key="main_selectbox"
|
| 143 |
)
|
| 144 |
|
| 145 |
+
# Selectbox'tan manuel seçim yapılırsa state'i güncelle
|
| 146 |
+
if selected_from_box != st.session_state.selected_actor:
|
| 147 |
+
st.session_state.selected_actor = selected_from_box
|
| 148 |
+
# Eğer None değilse hemen rerun yap ki resim gelsin
|
| 149 |
+
if selected_from_box:
|
| 150 |
+
st.rerun()
|
| 151 |
+
|
| 152 |
+
# RESİM GÖSTERME
|
| 153 |
+
if st.session_state.selected_actor:
|
| 154 |
+
actor = st.session_state.selected_actor
|
| 155 |
+
found_path = None
|
| 156 |
+
search_target = actor.replace(" ", "_").lower()
|
| 157 |
+
for f in os.listdir(resim_klasoru):
|
| 158 |
+
if f.lower().startswith(search_target) or actor.lower() in f.lower():
|
| 159 |
+
found_path = os.path.join(resim_klasoru, f)
|
| 160 |
+
break
|
| 161 |
+
|
| 162 |
+
if found_path:
|
| 163 |
+
st.image(found_path, caption=f"Profile: {actor}", use_container_width=True)
|
| 164 |
else:
|
| 165 |
+
st.error("Image not found. / Resim bulunamadı.")
|
| 166 |
+
else:
|
| 167 |
+
st.info("Please select an actor. / Lütfen bir oyuncu seçin.")
|
| 168 |
|
| 169 |
with col_match:
|
| 170 |
+
st.subheader("🎯 Best Career Matches")
|
| 171 |
|
| 172 |
if st.session_state.selected_actor:
|
| 173 |
+
actor = st.session_state.selected_actor
|
| 174 |
+
st.write(f"Comparing {actor}'s DNA...")
|
| 175 |
|
| 176 |
+
if st.button("🚀 Match and Recommend", key="match_btn"):
|
| 177 |
if movie_dict:
|
| 178 |
+
actor_v = unlu_verileri[actor]['v']
|
| 179 |
results = []
|
| 180 |
for i in movie_dict:
|
| 181 |
noise = random.uniform(0, 0.0001)
|
|
|
|
| 185 |
top_matches = sorted(results, key=lambda x: x[1])[:5]
|
| 186 |
for i, (film, score) in enumerate(top_matches, 1):
|
| 187 |
pct = round((1 - score) * 100, 1)
|
| 188 |
+
st.success(f"**{i}. {film}** (%{pct})")
|
|
|
|
| 189 |
st.progress(pct / 100)
|
|
|
|
|
|
|
| 190 |
else:
|
| 191 |
+
st.write("Waiting for selection... / Seçim bekleniyor...")
|
| 192 |
|
| 193 |
st.markdown("---")
|
| 194 |
+
st.info("💡 **How it works?**: Based on available image assets.")
|