ESMATUGBA commited on
Commit
d517292
·
verified ·
1 Parent(s): 4efc851

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -32
app.py CHANGED
@@ -15,14 +15,11 @@ st.set_page_config(page_title="Car Logo AI Pro 2026", layout="wide", page_icon="
15
  @st.cache_resource
16
  def load_car_dataset(base_path):
17
  dataset = []
18
- if not os.path.exists(base_path):
19
- image_files = [f for f in os.listdir('.') if f.lower().endswith(('.png', '.jpg', '.jpeg'))]
20
- for f in image_files:
21
- img = cv2.imread(f, 0)
22
- if img is not None:
23
- dataset.append((f, cv2.resize(img, (100, 100))))
24
- else:
25
- for root, dirs, files in os.walk(base_path):
26
  for file in files:
27
  if file.lower().endswith(('.png', '.jpg', '.jpeg')):
28
  full_path = os.path.join(root, file)
@@ -31,6 +28,7 @@ def load_car_dataset(base_path):
31
  dataset.append((full_path, cv2.resize(img, (100, 100))))
32
  return dataset
33
 
 
34
  dataset = load_car_dataset('Car_Logo_Dataset')
35
 
36
  # --- 4. RESİM İŞLEME / IMAGE PROCESSING ---
@@ -52,9 +50,9 @@ col_left, col_right = st.columns([1, 1], gap="large")
52
  with col_left:
53
  st.subheader("📤 Yükleme Alanı / Upload Area")
54
 
55
- # İSTEDİĞİN ÖZEL YAZIYI BURAYA EKLEDİK
56
  st.markdown("""
57
- <div style="color: #555; font-size: 0.9em; margin-bottom: -15px;">
58
  200MB per file • JPG, PNG, JPEG
59
  </div>
60
  """, unsafe_allow_html=True)
@@ -62,8 +60,7 @@ with col_left:
62
  uploaded_file = st.file_uploader(
63
  "Yeni bir logo seçin / Select a new logo",
64
  type=['jpg', 'png', 'jpeg'],
65
- key="main_uploader",
66
- label_visibility="visible"
67
  )
68
 
69
  st.markdown("---")
@@ -75,11 +72,11 @@ with col_left:
75
 
76
  with col_right:
77
  st.subheader("🎯 Analiz ve Sonuç / Analysis & Result")
78
- threshold = st.slider("Hassasiyet / Sensitivity", 0.0, 1.0, 0.20)
79
 
80
  if uploaded_file:
81
  if st.button("ŞİMDİ TANI / PREDICT NOW", type="primary", use_container_width=True):
82
- with st.spinner("32 Marka Taranıyor... / Scanning..."):
83
  query = cv2.resize(gray_img, (100, 100))
84
  best_score = -1
85
  best_path = None
@@ -91,34 +88,42 @@ with col_right:
91
  best_score = max_val
92
  best_path = path
93
 
 
94
  if best_path and best_score >= threshold:
95
  st.balloons()
96
- folder_name = os.path.basename(os.path.dirname(best_path))
97
- if not folder_name or folder_name == '.':
98
- folder_name = os.path.basename(best_path).split('.')[0]
99
 
100
- brand_name = ''.join([i for i in folder_name if not i.isdigit() and i not in ['-', '_']]).strip().upper()
 
 
 
 
 
 
 
 
 
 
 
 
 
101
 
102
  st.success(f"### TAHMİN / PREDICTION: **{brand_name}**")
103
  st.metric("Benzerlik / Similarity", f"%{int(best_score*100)}")
104
- st.image(best_path, width=150, caption=f"Eşleşen Referans: {brand_name}")
105
  else:
106
  st.error("❌ Eşleşme Bulunamadı / Match Not Found")
107
- else:
108
- st.info("Lütfen soldaki panelden bir logo yükleyerek başlayın.")
109
 
110
  # --- 6. TEKNİK ANALİZ ---
111
  if uploaded_file:
112
  st.markdown("---")
113
  with st.expander("🔍 Teknik Detaylar / Technical Details"):
114
- tab_tr, tab_en = st.tabs(["🇹🇷 Türkçe", "🇺🇸 English"])
115
- with tab_tr:
116
- st.write("### Görüntü İşleme Aşamaları")
117
- c1, c2 = st.columns(2)
118
- c1.image(edge_img, width=300, caption="Canny Kenar Analizi")
119
- c2.image(cv2.resize(gray_img, (100, 100)), caption="Sistemin Gördüğü (100x100)")
120
- with tab_en:
121
- st.write("### Image Processing Stages")
122
- ce1, ce2 = st.columns(2)
123
- ce1.image(edge_img, width=300, caption="Canny Edge Detection")
124
- ce2.image(cv2.resize(gray_img, (100, 100)), caption="AI View (100x100)")
 
15
  @st.cache_resource
16
  def load_car_dataset(base_path):
17
  dataset = []
18
+ # Klasör yolunu normalize et (Windows/Linux uyumu için)
19
+ target_path = os.path.normpath(base_path)
20
+
21
+ if os.path.exists(target_path):
22
+ for root, dirs, files in os.walk(target_path):
 
 
 
23
  for file in files:
24
  if file.lower().endswith(('.png', '.jpg', '.jpeg')):
25
  full_path = os.path.join(root, file)
 
28
  dataset.append((full_path, cv2.resize(img, (100, 100))))
29
  return dataset
30
 
31
+ # Veri setini yükle
32
  dataset = load_car_dataset('Car_Logo_Dataset')
33
 
34
  # --- 4. RESİM İŞLEME / IMAGE PROCESSING ---
 
50
  with col_left:
51
  st.subheader("📤 Yükleme Alanı / Upload Area")
52
 
53
+ # İstediğin özel 200MB uyarısı
54
  st.markdown("""
55
+ <div style="color: #666; font-size: 0.85em; margin-bottom: -10px; font-family: sans-serif;">
56
  200MB per file • JPG, PNG, JPEG
57
  </div>
58
  """, unsafe_allow_html=True)
 
60
  uploaded_file = st.file_uploader(
61
  "Yeni bir logo seçin / Select a new logo",
62
  type=['jpg', 'png', 'jpeg'],
63
+ key="main_uploader"
 
64
  )
65
 
66
  st.markdown("---")
 
72
 
73
  with col_right:
74
  st.subheader("🎯 Analiz ve Sonuç / Analysis & Result")
75
+ threshold = st.slider("Hassasiyet / Sensitivity (Threshold)", 0.0, 1.0, 0.20)
76
 
77
  if uploaded_file:
78
  if st.button("ŞİMDİ TANI / PREDICT NOW", type="primary", use_container_width=True):
79
+ with st.spinner("32 Marka Taranıyor... / Scanning 32 Brands..."):
80
  query = cv2.resize(gray_img, (100, 100))
81
  best_score = -1
82
  best_path = None
 
88
  best_score = max_val
89
  best_path = path
90
 
91
+ # --- AKILLI MARKA İSMİ AYIKLAMA ---
92
  if best_path and best_score >= threshold:
93
  st.balloons()
 
 
 
94
 
95
+ # Yolu parçalarına ayır
96
+ parts = os.path.normpath(best_path).split(os.sep)
97
+
98
+ # Klasör yapısına göre marka adını bul (Genelde sondan bir önceki parça)
99
+ if len(parts) > 1:
100
+ raw_brand = parts[-2]
101
+ # Eğer üst klasör ismini (Car_Logo_Dataset) aldıysa dosya adına bak
102
+ if "DATASET" in raw_brand.upper() or raw_brand == ".":
103
+ raw_brand = parts[-1].split('.')[0]
104
+ else:
105
+ raw_brand = parts[-1].split('.')[0]
106
+
107
+ # Gereksiz karakterleri ve sayıları temizle
108
+ brand_name = ''.join([i for i in raw_brand if not i.isdigit() and i not in ['-', '_']]).strip().upper()
109
 
110
  st.success(f"### TAHMİN / PREDICTION: **{brand_name}**")
111
  st.metric("Benzerlik / Similarity", f"%{int(best_score*100)}")
112
+ st.image(best_path, width=150, caption=f"Eşleşen: {brand_name}")
113
  else:
114
  st.error("❌ Eşleşme Bulunamadı / Match Not Found")
 
 
115
 
116
  # --- 6. TEKNİK ANALİZ ---
117
  if uploaded_file:
118
  st.markdown("---")
119
  with st.expander("🔍 Teknik Detaylar / Technical Details"):
120
+ t1, t2 = st.tabs(["🇹🇷 Türkçe", "🇺🇸 English"])
121
+ with t1:
122
+ st.image(edge_img, width=300, caption="Kenar Analizi")
123
+ st.info(f"Sistem veri setindeki {len(dataset)} referans ile karşılaştırma yaptı.")
124
+ with t2:
125
+ st.image(edge_img, width=300, caption="Edge Analysis")
126
+ st.info(f"System compared with {len(dataset)} reference images.")
127
+
128
+ # Görsel Stil
129
+ st.markdown("<style>.stMetric { background: #f0f2f6; border-radius: 10px; padding: 10px; }</style>", unsafe_allow_html=True)