Update app.py
Browse files
app.py
CHANGED
|
@@ -71,6 +71,7 @@ tum_unlu_verileri = {
|
|
| 71 |
# --- RESİM KONTROLÜ ---
|
| 72 |
resim_klasoru = os.getcwd()
|
| 73 |
|
|
|
|
| 74 |
def get_available_actors():
|
| 75 |
dosyalar = [f.lower() for f in os.listdir(resim_klasoru)]
|
| 76 |
mevcut = [isim for isim, veri in tum_unlu_verileri.items()
|
|
@@ -79,36 +80,36 @@ def get_available_actors():
|
|
| 79 |
|
| 80 |
mevcut_isimler = get_available_actors()
|
| 81 |
|
| 82 |
-
# --- HAFIZA
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
st.session_state.shared_actor = mevcut_isimler[0] if mevcut_isimler else None
|
| 86 |
|
| 87 |
-
# ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
st.sidebar.title("🔍 Control Panel")
|
| 89 |
gender_choice = st.sidebar.radio("Category / Kategori:", ["Male / Erkek", "Female / Kadın"])
|
| 90 |
|
| 91 |
# Seçilen kategoriye göre isimleri filtrele
|
| 92 |
filtered_names = [n for n in mevcut_isimler if tum_unlu_verileri[n]['c'] == gender_choice]
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
# Index'i her zaman hafızadaki isme göre bulur
|
| 98 |
-
try:
|
| 99 |
-
sidebar_idx = filtered_names.index(st.session_state.shared_actor)
|
| 100 |
-
except:
|
| 101 |
-
sidebar_idx = 0
|
| 102 |
-
|
| 103 |
-
def on_sidebar_change():
|
| 104 |
-
st.session_state.shared_actor = st.session_state.sidebar_key
|
| 105 |
|
|
|
|
|
|
|
| 106 |
st.sidebar.radio(
|
| 107 |
-
"📋
|
| 108 |
-
filtered_names,
|
| 109 |
-
index=
|
| 110 |
-
key="
|
| 111 |
-
on_change=
|
| 112 |
)
|
| 113 |
|
| 114 |
# --- ANA EKRAN ---
|
|
@@ -118,23 +119,15 @@ st.markdown("---")
|
|
| 118 |
col_actor, col_match = st.columns([1, 2])
|
| 119 |
|
| 120 |
with col_actor:
|
| 121 |
-
st.subheader("👤
|
| 122 |
|
| 123 |
-
#
|
| 124 |
-
try:
|
| 125 |
-
main_idx = filtered_names.index(st.session_state.shared_actor)
|
| 126 |
-
except:
|
| 127 |
-
main_idx = 0
|
| 128 |
-
|
| 129 |
-
def on_main_change():
|
| 130 |
-
st.session_state.shared_actor = st.session_state.main_key
|
| 131 |
-
|
| 132 |
final_actor = st.selectbox(
|
| 133 |
-
"
|
| 134 |
-
filtered_names,
|
| 135 |
-
index=
|
| 136 |
-
key="
|
| 137 |
-
on_change=
|
| 138 |
)
|
| 139 |
|
| 140 |
# RESİM GÖSTERME
|
|
@@ -147,9 +140,7 @@ with col_actor:
|
|
| 147 |
break
|
| 148 |
|
| 149 |
if found_path:
|
| 150 |
-
st.image(found_path, caption=final_actor, use_container_width=True)
|
| 151 |
-
else:
|
| 152 |
-
st.info("Waiting for selection... / Seçim bekleniyor...")
|
| 153 |
|
| 154 |
with col_match:
|
| 155 |
st.subheader("🎯 Career Matches")
|
|
@@ -164,10 +155,8 @@ with col_match:
|
|
| 164 |
|
| 165 |
for i, (film, score) in enumerate(sorted(results, key=lambda x: x[1])[:5], 1):
|
| 166 |
pct = round((1 - score) * 100, 1)
|
| 167 |
-
st.success(f"**{i}. {film}**")
|
| 168 |
st.progress(pct / 100)
|
| 169 |
-
else:
|
| 170 |
-
st.write("Please select an actor.")
|
| 171 |
|
| 172 |
st.markdown("---")
|
| 173 |
-
st.info("💡
|
|
|
|
| 71 |
# --- RESİM KONTROLÜ ---
|
| 72 |
resim_klasoru = os.getcwd()
|
| 73 |
|
| 74 |
+
@st.cache_data
|
| 75 |
def get_available_actors():
|
| 76 |
dosyalar = [f.lower() for f in os.listdir(resim_klasoru)]
|
| 77 |
mevcut = [isim for isim, veri in tum_unlu_verileri.items()
|
|
|
|
| 80 |
|
| 81 |
mevcut_isimler = get_available_actors()
|
| 82 |
|
| 83 |
+
# --- HAFIZA (SESSION STATE) ---
|
| 84 |
+
if 'selected_actor' not in st.session_state:
|
| 85 |
+
st.session_state.selected_actor = mevcut_isimler[0] if mevcut_isimler else None
|
|
|
|
| 86 |
|
| 87 |
+
# --- CALLBACKS (Değişim Fonksiyonları) ---
|
| 88 |
+
def update_from_sidebar():
|
| 89 |
+
st.session_state.selected_actor = st.session_state.sidebar_choice
|
| 90 |
+
|
| 91 |
+
def update_from_main():
|
| 92 |
+
st.session_state.selected_actor = st.session_state.main_choice
|
| 93 |
+
|
| 94 |
+
# --- SOL PANEL (SIDEBAR) ---
|
| 95 |
st.sidebar.title("🔍 Control Panel")
|
| 96 |
gender_choice = st.sidebar.radio("Category / Kategori:", ["Male / Erkek", "Female / Kadın"])
|
| 97 |
|
| 98 |
# Seçilen kategoriye göre isimleri filtrele
|
| 99 |
filtered_names = [n for n in mevcut_isimler if tum_unlu_verileri[n]['c'] == gender_choice]
|
| 100 |
|
| 101 |
+
# Eğer hafızadaki oyuncu bu kategoride yoksa kategorinin ilk ismine geç
|
| 102 |
+
if st.session_state.selected_actor not in filtered_names and filtered_names:
|
| 103 |
+
st.session_state.selected_actor = filtered_names[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
+
# SIDEBAR SEÇİM ALANI
|
| 106 |
+
st.sidebar.markdown("---")
|
| 107 |
st.sidebar.radio(
|
| 108 |
+
"📋 Available Cast / Mevcut Oyuncular:",
|
| 109 |
+
filtered_names,
|
| 110 |
+
index=filtered_names.index(st.session_state.selected_actor) if st.session_state.selected_actor in filtered_names else 0,
|
| 111 |
+
key="sidebar_choice",
|
| 112 |
+
on_change=update_from_sidebar
|
| 113 |
)
|
| 114 |
|
| 115 |
# --- ANA EKRAN ---
|
|
|
|
| 119 |
col_actor, col_match = st.columns([1, 2])
|
| 120 |
|
| 121 |
with col_actor:
|
| 122 |
+
st.subheader("👤 Pick an Actor / Oyuncu Seç")
|
| 123 |
|
| 124 |
+
# ANA EKRAN SEÇİM KUTUSU
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
final_actor = st.selectbox(
|
| 126 |
+
"Select from list / Listeden seçin:",
|
| 127 |
+
filtered_names,
|
| 128 |
+
index=filtered_names.index(st.session_state.selected_actor) if st.session_state.selected_actor in filtered_names else 0,
|
| 129 |
+
key="main_choice",
|
| 130 |
+
on_change=update_from_main
|
| 131 |
)
|
| 132 |
|
| 133 |
# RESİM GÖSTERME
|
|
|
|
| 140 |
break
|
| 141 |
|
| 142 |
if found_path:
|
| 143 |
+
st.image(found_path, caption=f"Profile: {final_actor}", use_container_width=True)
|
|
|
|
|
|
|
| 144 |
|
| 145 |
with col_match:
|
| 146 |
st.subheader("🎯 Career Matches")
|
|
|
|
| 155 |
|
| 156 |
for i, (film, score) in enumerate(sorted(results, key=lambda x: x[1])[:5], 1):
|
| 157 |
pct = round((1 - score) * 100, 1)
|
| 158 |
+
st.success(f"**{i}. {film}** (%{pct})")
|
| 159 |
st.progress(pct / 100)
|
|
|
|
|
|
|
| 160 |
|
| 161 |
st.markdown("---")
|
| 162 |
+
st.info("💡 Sol taraftan veya listeden seçim yaparak anında güncelleyebilirsiniz.")
|