Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,28 +11,37 @@ warnings.filterwarnings('ignore')
|
|
| 11 |
# --- 2. SAYFA AYARLARI ---
|
| 12 |
st.set_page_config(page_title="Car Logo AI Pro 2026", layout="wide", page_icon="🚗")
|
| 13 |
|
| 14 |
-
# --- 3. VERİ
|
| 15 |
@st.cache_resource
|
| 16 |
-
def load_car_dataset(
|
| 17 |
dataset = []
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
for
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
for file in files:
|
| 24 |
if file.lower().endswith(('.png', '.jpg', '.jpeg')):
|
| 25 |
full_path = os.path.join(root, file)
|
| 26 |
-
# OpenCV resim okuma (Gri ton)
|
| 27 |
img = cv2.imread(full_path, 0)
|
| 28 |
if img is not None:
|
| 29 |
-
# Hız için önceden boyutlandırıyoruz
|
| 30 |
dataset.append((full_path, cv2.resize(img, (100, 100))))
|
| 31 |
-
return dataset
|
| 32 |
|
| 33 |
-
#
|
| 34 |
-
|
| 35 |
-
dataset = load_car_dataset(folder_name)
|
| 36 |
|
| 37 |
# --- 4. RESİM İŞLEME ---
|
| 38 |
@st.cache_data
|
|
@@ -44,7 +53,7 @@ def process_uploaded_image(file_bytes):
|
|
| 44 |
edges = cv2.Canny(gray, 100, 200)
|
| 45 |
return img, gray, edges
|
| 46 |
|
| 47 |
-
# --- 5. ARAYÜZ
|
| 48 |
st.title("🚗 Araba Logosu Tanıma / Car Logo Recognition")
|
| 49 |
st.markdown("---")
|
| 50 |
|
|
@@ -62,15 +71,14 @@ with col_left:
|
|
| 62 |
|
| 63 |
with col_right:
|
| 64 |
st.subheader("🎯 Sonuç / Result")
|
| 65 |
-
# Hassasiyeti biraz düşürdüm (0.15) ki Hugging Face'te daha kolay bulsun
|
| 66 |
threshold = st.slider("Hassasiyet / Sensitivity", 0.0, 1.0, 0.15)
|
| 67 |
|
| 68 |
if uploaded_file:
|
| 69 |
if st.button("ŞİMDİ TANI / PREDICT NOW", type="primary", use_container_width=True):
|
| 70 |
-
if
|
| 71 |
-
st.error("Veri seti
|
| 72 |
else:
|
| 73 |
-
with st.spinner("
|
| 74 |
query = cv2.resize(gray_img, (100, 100))
|
| 75 |
best_score = -1
|
| 76 |
best_path = None
|
|
@@ -84,20 +92,23 @@ with col_right:
|
|
| 84 |
|
| 85 |
if best_path and best_score >= threshold:
|
| 86 |
st.balloons()
|
| 87 |
-
#
|
| 88 |
parts = os.path.normpath(best_path).split(os.sep)
|
| 89 |
-
#
|
| 90 |
-
brand_raw = parts[-2] if len(parts) > 1 and parts[-2].lower() not in [
|
| 91 |
-
|
| 92 |
brand_name = ''.join([i for i in brand_raw if not i.isdigit() and i not in ['-', '_']]).strip().upper()
|
| 93 |
|
| 94 |
st.success(f"### TAHMİN: **{brand_name}**")
|
| 95 |
st.metric("Benzerlik", f"%{int(best_score*100)}")
|
| 96 |
st.image(best_path, width=150)
|
| 97 |
else:
|
| 98 |
-
st.error("❌ Eşleşme Bulunamadı.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
-
# --- 6. TEKNİK
|
| 101 |
if uploaded_file:
|
| 102 |
st.markdown("---")
|
| 103 |
with st.expander("🔍 Teknik Detaylar"):
|
|
|
|
| 11 |
# --- 2. SAYFA AYARLARI ---
|
| 12 |
st.set_page_config(page_title="Car Logo AI Pro 2026", layout="wide", page_icon="🚗")
|
| 13 |
|
| 14 |
+
# --- 3. AKILLI VERİ SETİ YÜKLEYİCİ (OTOMATİK KLASÖR BULUCU) ---
|
| 15 |
@st.cache_resource
|
| 16 |
+
def load_car_dataset():
|
| 17 |
dataset = []
|
| 18 |
+
# Aranacak olası klasör isimleri
|
| 19 |
+
possible_folders = ['Car_Logo_Dataset', 'dataset', 'car_logo_dataset', 'Dataset', '.']
|
| 20 |
+
|
| 21 |
+
found_path = None
|
| 22 |
+
for folder in possible_folders:
|
| 23 |
+
if os.path.exists(folder) and os.path.isdir(folder):
|
| 24 |
+
# Klasörün içi boş mu kontrol et (Sadece resim olanları say)
|
| 25 |
+
has_images = any(any(f.lower().endswith(('.png', '.jpg', '.jpeg')) for f in files)
|
| 26 |
+
for _, _, files in os.walk(folder))
|
| 27 |
+
if has_images and folder != '.':
|
| 28 |
+
found_path = folder
|
| 29 |
+
break
|
| 30 |
+
|
| 31 |
+
# Eğer özel klasör bulunamazsa ana dizine bak
|
| 32 |
+
search_path = found_path if found_path else '.'
|
| 33 |
+
|
| 34 |
+
for root, dirs, files in os.walk(search_path):
|
| 35 |
for file in files:
|
| 36 |
if file.lower().endswith(('.png', '.jpg', '.jpeg')):
|
| 37 |
full_path = os.path.join(root, file)
|
|
|
|
| 38 |
img = cv2.imread(full_path, 0)
|
| 39 |
if img is not None:
|
|
|
|
| 40 |
dataset.append((full_path, cv2.resize(img, (100, 100))))
|
| 41 |
+
return dataset, search_path
|
| 42 |
|
| 43 |
+
# Veri setini ve hangi klasörden yüklendiğini al
|
| 44 |
+
dataset, loaded_from = load_car_dataset()
|
|
|
|
| 45 |
|
| 46 |
# --- 4. RESİM İŞLEME ---
|
| 47 |
@st.cache_data
|
|
|
|
| 53 |
edges = cv2.Canny(gray, 100, 200)
|
| 54 |
return img, gray, edges
|
| 55 |
|
| 56 |
+
# --- 5. ARAYÜZ ---
|
| 57 |
st.title("🚗 Araba Logosu Tanıma / Car Logo Recognition")
|
| 58 |
st.markdown("---")
|
| 59 |
|
|
|
|
| 71 |
|
| 72 |
with col_right:
|
| 73 |
st.subheader("🎯 Sonuç / Result")
|
|
|
|
| 74 |
threshold = st.slider("Hassasiyet / Sensitivity", 0.0, 1.0, 0.15)
|
| 75 |
|
| 76 |
if uploaded_file:
|
| 77 |
if st.button("ŞİMDİ TANI / PREDICT NOW", type="primary", use_container_width=True):
|
| 78 |
+
if not dataset:
|
| 79 |
+
st.error(f"❌ Veri seti bulunamadı! Lütfen '{loaded_from}' klasörünü kontrol edin.")
|
| 80 |
else:
|
| 81 |
+
with st.spinner("32 Marka Taranıyor..."):
|
| 82 |
query = cv2.resize(gray_img, (100, 100))
|
| 83 |
best_score = -1
|
| 84 |
best_path = None
|
|
|
|
| 92 |
|
| 93 |
if best_path and best_score >= threshold:
|
| 94 |
st.balloons()
|
| 95 |
+
# Marka adını akıllıca ayıkla
|
| 96 |
parts = os.path.normpath(best_path).split(os.sep)
|
| 97 |
+
# Marka ismi klasördeyse onu al, yoksa dosya adını al
|
| 98 |
+
brand_raw = parts[-2] if len(parts) > 1 and parts[-2].lower() not in [loaded_from.lower(), '.'] else parts[-1].split('.')[0]
|
|
|
|
| 99 |
brand_name = ''.join([i for i in brand_raw if not i.isdigit() and i not in ['-', '_']]).strip().upper()
|
| 100 |
|
| 101 |
st.success(f"### TAHMİN: **{brand_name}**")
|
| 102 |
st.metric("Benzerlik", f"%{int(best_score*100)}")
|
| 103 |
st.image(best_path, width=150)
|
| 104 |
else:
|
| 105 |
+
st.error("❌ Eşleşme Bulunamadı.")
|
| 106 |
+
|
| 107 |
+
# Sidebar Bilgi Paneli (Hocan görsün diye)
|
| 108 |
+
st.sidebar.success(f"📂 Yüklenen Klasör: {loaded_from}")
|
| 109 |
+
st.sidebar.info(f"🖼️ Toplam Logo Sayısı: {len(dataset)}")
|
| 110 |
|
| 111 |
+
# --- 6. TEKNİK ANALİZ ---
|
| 112 |
if uploaded_file:
|
| 113 |
st.markdown("---")
|
| 114 |
with st.expander("🔍 Teknik Detaylar"):
|