Update app.py
Browse files
app.py
CHANGED
|
@@ -57,23 +57,9 @@ 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 |
-
# ---
|
| 61 |
resim_klasoru = os.path.join(os.getcwd(), "40 resim")
|
| 62 |
|
| 63 |
-
@st.cache_data
|
| 64 |
-
def klasordeki_unluleri_getir():
|
| 65 |
-
mevcut_unlular = {}
|
| 66 |
-
if os.path.exists(resim_klasoru):
|
| 67 |
-
dosyalar = [f.lower() for f in os.listdir(resim_klasoru)]
|
| 68 |
-
for isim, veri in tum_unlu_verileri.items():
|
| 69 |
-
search_pattern1 = isim.lower().replace(" ", "_")
|
| 70 |
-
search_pattern2 = isim.lower()
|
| 71 |
-
if any(search_pattern1 in d or search_pattern2 in d for d in dosyalar):
|
| 72 |
-
mevcut_unlular[isim] = veri
|
| 73 |
-
return mevcut_unlular
|
| 74 |
-
|
| 75 |
-
unlu_verileri = klasordeki_unluleri_getir()
|
| 76 |
-
|
| 77 |
# --- ARAYÜZ AYARLARI ---
|
| 78 |
st.set_page_config(page_title="CastMatch AI", layout="wide")
|
| 79 |
|
|
@@ -86,15 +72,16 @@ gender_choice = st.sidebar.radio(
|
|
| 86 |
["Male / Erkek", "Female / Kadın"]
|
| 87 |
)
|
| 88 |
|
| 89 |
-
|
|
|
|
| 90 |
|
| 91 |
st.sidebar.markdown(f"### 📋 Available Cast / Mevcut Oyuncular")
|
| 92 |
|
| 93 |
-
#
|
| 94 |
selected_actor_sidebar = st.sidebar.radio(
|
| 95 |
-
"
|
| 96 |
-
filtered_names
|
| 97 |
-
label_visibility="collapsed"
|
| 98 |
)
|
| 99 |
|
| 100 |
# --- ANA EKRAN ---
|
|
@@ -107,39 +94,38 @@ col_actor, col_match = st.columns([1, 2])
|
|
| 107 |
with col_actor:
|
| 108 |
st.subheader("👤 Pick an Actor / Oyuncu Seç")
|
| 109 |
|
| 110 |
-
#
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
except:
|
| 114 |
-
current_idx = 0
|
| 115 |
-
|
| 116 |
selected_actor = st.selectbox(
|
| 117 |
"Select from list / Listeden seçin:",
|
| 118 |
-
filtered_names
|
| 119 |
index=current_idx
|
| 120 |
)
|
| 121 |
|
| 122 |
-
|
| 123 |
-
|
|
|
|
| 124 |
search_target = selected_actor.replace(" ", "_").lower()
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
|
|
|
| 135 |
|
| 136 |
with col_match:
|
| 137 |
st.subheader("🎯 Best Career Matches / En İyi Kariyer Eşleşmeleri")
|
| 138 |
st.write("Comparing the star's DNA with movie roles... / Yıldızın DNA'sı film rolleriyle karşılaştırılıyor...")
|
| 139 |
|
| 140 |
-
if st.button("🚀 Match and Recommend / Eşleştir ve Öner")
|
| 141 |
if movie_dict:
|
| 142 |
-
actor_v =
|
| 143 |
results = []
|
| 144 |
for i in movie_dict:
|
| 145 |
noise = random.uniform(0, 0.0001)
|
|
|
|
| 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Ü AYARI ---
|
| 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 |
|
|
|
|
| 72 |
["Male / Erkek", "Female / Kadın"]
|
| 73 |
)
|
| 74 |
|
| 75 |
+
# Klasörde resim olsa da olmasa da isimleri listele ki "Yok" çıkmasın
|
| 76 |
+
filtered_names = [name for name, data in tum_unlu_verileri.items() if data['c'] == gender_choice]
|
| 77 |
|
| 78 |
st.sidebar.markdown(f"### 📋 Available Cast / Mevcut Oyuncular")
|
| 79 |
|
| 80 |
+
# SENKRONİZASYON: Sidebar seçimini ana state'e bağlıyoruz
|
| 81 |
selected_actor_sidebar = st.sidebar.radio(
|
| 82 |
+
"Quick Select:",
|
| 83 |
+
filtered_names,
|
| 84 |
+
label_visibility="collapsed"
|
| 85 |
)
|
| 86 |
|
| 87 |
# --- ANA EKRAN ---
|
|
|
|
| 94 |
with col_actor:
|
| 95 |
st.subheader("👤 Pick an Actor / Oyuncu Seç")
|
| 96 |
|
| 97 |
+
# Sidebar'daki seçimi buradaki selectbox'a zorla eşle
|
| 98 |
+
current_idx = filtered_names.index(selected_actor_sidebar)
|
| 99 |
+
|
|
|
|
|
|
|
|
|
|
| 100 |
selected_actor = st.selectbox(
|
| 101 |
"Select from list / Listeden seçin:",
|
| 102 |
+
filtered_names,
|
| 103 |
index=current_idx
|
| 104 |
)
|
| 105 |
|
| 106 |
+
# RESİM BULMA MANTIĞI
|
| 107 |
+
found_path = None
|
| 108 |
+
if os.path.exists(resim_klasoru):
|
| 109 |
search_target = selected_actor.replace(" ", "_").lower()
|
| 110 |
+
dosyalar = os.listdir(resim_klasoru)
|
| 111 |
+
for f in dosyalar:
|
| 112 |
+
if f.lower().startswith(search_target) or selected_actor.lower() in f.lower():
|
| 113 |
+
found_path = os.path.join(resim_klasoru, f)
|
| 114 |
+
break
|
| 115 |
+
|
| 116 |
+
if found_path:
|
| 117 |
+
st.image(found_path, caption=f"Profile: {selected_actor}", use_container_width=True)
|
| 118 |
+
else:
|
| 119 |
+
# Resim yoksa bir placeholder veya uyarı göster ama isimler kaybolmasın
|
| 120 |
+
st.warning(f"Resim dosyası '40 resim' klasöründe bulunamadı: {selected_actor}")
|
| 121 |
|
| 122 |
with col_match:
|
| 123 |
st.subheader("🎯 Best Career Matches / En İyi Kariyer Eşleşmeleri")
|
| 124 |
st.write("Comparing the star's DNA with movie roles... / Yıldızın DNA'sı film rolleriyle karşılaştırılıyor...")
|
| 125 |
|
| 126 |
+
if st.button("🚀 Match and Recommend / Eşleştir ve Öner"):
|
| 127 |
if movie_dict:
|
| 128 |
+
actor_v = tum_unlu_verileri[selected_actor]['v']
|
| 129 |
results = []
|
| 130 |
for i in movie_dict:
|
| 131 |
noise = random.uniform(0, 0.0001)
|