ESMATUGBA commited on
Commit
8458122
·
verified ·
1 Parent(s): 040ce8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -29
app.py CHANGED
@@ -17,7 +17,6 @@ model_data = load_data()
17
  movie_dict = model_data['movie_dict'] if model_data else {}
18
 
19
  # --- 2. OYUNCU DNA VERİTABANI ---
20
- # Sylvester Stallone 1. sırada sabitlendi.
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]},
@@ -61,18 +60,34 @@ tum_unlu_verileri = {
61
  # --- ARAYÜZ AYARLARI ---
62
  st.set_page_config(page_title="CastMatch AI", layout="wide")
63
 
64
- # --- SOL PANEL (SIDEBAR) ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  st.sidebar.title("🔍 Control Panel / Kontrol Paneli")
66
  st.sidebar.markdown("---")
 
67
 
68
- gender_choice = st.sidebar.radio(
69
- "1. Select Category / Kategori Seçin:",
70
- ["Male / Erkek", "Female / Kadın"]
71
- )
72
-
73
- # Hugging Face ana dizinindeki tüm dosyaları tara
74
  ana_dizin_dosyalari = os.listdir(".")
75
-
76
  filtered_names = [name for name in tum_unlu_verileri.keys() if tum_unlu_verileri[name]['c'] == gender_choice]
77
 
78
  st.sidebar.markdown(f"### 📋 Available Cast / Mevcut Oyuncular")
@@ -81,63 +96,55 @@ for n in filtered_names:
81
 
82
  # --- ANA EKRAN ---
83
  st.title("🎬 CastMatch AI: Talent Matching System / Yetenek Eşleştirme Sistemi")
84
- st.markdown("#### Discover the perfect roles for global stars! / Dünya yıldızları için en ideal rolleri keşfedin!")
85
  st.markdown("---")
86
 
87
  col_actor, col_match = st.columns([1, 2])
88
 
89
  with col_actor:
90
  st.subheader("👤 Pick an Actor / Oyuncu Seç")
91
- selected_actor = st.selectbox("Select from list / Listeden seçin:", ["Choose... / Seçiniz..."] + filtered_names)
92
 
93
- # Titreme önleyici sabit alan
94
- image_placeholder = st.empty()
95
-
96
- if selected_actor != "Choose... / Seçiniz...":
97
  found_path = None
98
- # Hugging Face dosya isimlendirmelerine göre esnek arama
99
  target_underscore = selected_actor.replace(" ", "_").lower()
100
  target_plain = selected_actor.lower()
101
 
102
  for f in ana_dizin_dosyalari:
103
  f_lower = f.lower()
104
  if f_lower.endswith(('.jpg', '.png', '.jpeg')):
105
- # Hem alt tireli hem boşluklu isimleri kontrol et
106
  if target_underscore in f_lower or target_plain in f_lower:
107
  found_path = f
108
  break
109
 
110
  if found_path:
111
- image_placeholder.image(found_path, caption=f"Profile: {selected_actor}", use_container_width=True)
112
  else:
113
- image_placeholder.error(f"Image not found! / Resim bulunamadı! Aranan: {selected_actor}")
114
  else:
115
- image_placeholder.info("Please select an actor. / Lütfen bir oyuncu seçin.")
 
116
 
117
  with col_match:
118
  st.subheader("🎯 Best Career Matches / En İyi Kariyer Eşleşmeleri")
119
 
120
- if st.button("🚀 Match and Recommend / Eşleştir ve Öner") and selected_actor != "Choose... / Seçiniz...":
121
  if movie_dict:
122
  actor_v = tum_unlu_verileri[selected_actor]['v']
123
  results = []
124
  for i in movie_dict:
125
  dist = spatial.distance.cosine(actor_v, movie_dict[i][1][:6])
126
- # Skor Hatası Düzeltmesi (0-1 Arasına Kilitlendi)
127
  dist = max(0, min(1, dist))
128
  results.append((movie_dict[i][0], dist))
129
 
130
- # En yakın mesafeler en iyi eşleşmelerdir
131
  top_matches = sorted(results, key=lambda x: x[1])[:5]
132
-
133
  for i, (film, score) in enumerate(top_matches, 1):
134
- # Skoru yüzdeye çevir
135
  pct = max(0, min(100, round((1 - score) * 100, 1)))
136
- st.success(f"**{i}. {film}**")
137
- st.write(f"Match Score / Uyum Skoru: **%{pct}**")
138
  st.progress(pct / 100)
139
  else:
140
- st.error("Model file missing! / Model dosyası eksik!")
141
 
142
  st.markdown("---")
143
- st.info("💡 **How it works? / Nasıl çalışır?**: This AI analyzes career vectors based on files uploaded to Hugging Face. / Bu yapay zeka Hugging Face'e yüklenen dosyalara göre analiz yapar.")
 
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]},
 
60
  # --- ARAYÜZ AYARLARI ---
61
  st.set_page_config(page_title="CastMatch AI", layout="wide")
62
 
63
+ # TITREME ÇÖZÜMÜ: CSS ile resim alanını sabitleme
64
+ st.markdown("""
65
+ <style>
66
+ /* Resim konteynırını sabitle */
67
+ [data-testid="stImage"] {
68
+ min-height: 400px !important;
69
+ max-height: 400px !important;
70
+ background-color: transparent;
71
+ display: flex;
72
+ align-items: center;
73
+ justify-content: center;
74
+ }
75
+ /* Resmi çerçeveye sığdır */
76
+ .stImage img {
77
+ max-height: 400px !important;
78
+ width: auto !important;
79
+ object-fit: contain;
80
+ }
81
+ </style>
82
+ """, unsafe_allow_html=True)
83
+
84
+ # --- SIDEBAR ---
85
  st.sidebar.title("🔍 Control Panel / Kontrol Paneli")
86
  st.sidebar.markdown("---")
87
+ gender_choice = st.sidebar.radio("1. Select Category / Kategori Seçin:", ["Male / Erkek", "Female / Kadın"])
88
 
89
+ # Hugging Face ana dizin dosyaları
 
 
 
 
 
90
  ana_dizin_dosyalari = os.listdir(".")
 
91
  filtered_names = [name for name in tum_unlu_verileri.keys() if tum_unlu_verileri[name]['c'] == gender_choice]
92
 
93
  st.sidebar.markdown(f"### 📋 Available Cast / Mevcut Oyuncular")
 
96
 
97
  # --- ANA EKRAN ---
98
  st.title("🎬 CastMatch AI: Talent Matching System / Yetenek Eşleştirme Sistemi")
 
99
  st.markdown("---")
100
 
101
  col_actor, col_match = st.columns([1, 2])
102
 
103
  with col_actor:
104
  st.subheader("👤 Pick an Actor / Oyuncu Seç")
105
+ selected_actor = st.selectbox("Select from list / Seçiniz:", ["Choose..."] + filtered_names)
106
 
107
+ # Resim Alanı
108
+ if selected_actor != "Choose...":
 
 
109
  found_path = None
 
110
  target_underscore = selected_actor.replace(" ", "_").lower()
111
  target_plain = selected_actor.lower()
112
 
113
  for f in ana_dizin_dosyalari:
114
  f_lower = f.lower()
115
  if f_lower.endswith(('.jpg', '.png', '.jpeg')):
 
116
  if target_underscore in f_lower or target_plain in f_lower:
117
  found_path = f
118
  break
119
 
120
  if found_path:
121
+ st.image(found_path, use_container_width=False)
122
  else:
123
+ st.error(f"Image not found! / Resim bulunamadı: {selected_actor}")
124
  else:
125
+ # Seçim yokken boşluğu koru (Titremeyi önler)
126
+ st.markdown('<div style="height: 400px; border: 1px dashed #ccc; display: flex; align-items: center; justify-content: center; color: #999;">Select an actor to view profile</div>', unsafe_allow_html=True)
127
 
128
  with col_match:
129
  st.subheader("🎯 Best Career Matches / En İyi Kariyer Eşleşmeleri")
130
 
131
+ if st.button("🚀 Match and Recommend / Eşleştir ve Öner") and selected_actor != "Choose...":
132
  if movie_dict:
133
  actor_v = tum_unlu_verileri[selected_actor]['v']
134
  results = []
135
  for i in movie_dict:
136
  dist = spatial.distance.cosine(actor_v, movie_dict[i][1][:6])
137
+ # Skor Hatası Düzeltmesi
138
  dist = max(0, min(1, dist))
139
  results.append((movie_dict[i][0], dist))
140
 
 
141
  top_matches = sorted(results, key=lambda x: x[1])[:5]
 
142
  for i, (film, score) in enumerate(top_matches, 1):
 
143
  pct = max(0, min(100, round((1 - score) * 100, 1)))
144
+ st.success(f"**{i}. {film}** (%{pct})")
 
145
  st.progress(pct / 100)
146
  else:
147
+ st.error("Model file missing! / Model dosyası bulunamadı!")
148
 
149
  st.markdown("---")
150
+ st.info("💡 Career analysis is based on Hugging Face assets.")