ESMATUGBA commited on
Commit
76d9788
·
verified ·
1 Parent(s): 4e90266

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -43
app.py CHANGED
@@ -4,18 +4,17 @@ import numpy as np
4
  import os
5
  import warnings
6
 
7
- # --- 1. SİNSİ HATALARI SUSTUR (2026 OPTİMİZASYONU) ---
8
  os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
9
  warnings.filterwarnings('ignore')
10
 
11
  # --- 2. SAYFA AYARLARI / PAGE CONFIG ---
12
  st.set_page_config(page_title="Car Logo AI Pro 2026", layout="wide", page_icon="🚗")
13
 
14
- # --- 3. VERİ SETİNİ BELLEĞE YÜKLE (TİTREMEYİ ÖNLEYEN ANA YER) ---
15
  @st.cache_resource
16
  def load_car_dataset(base_path):
17
  dataset = []
18
- # Eğer klasör yoksa hata verme, ana dizine bak
19
  if not os.path.exists(base_path):
20
  image_files = [f for f in os.listdir('.') if f.lower().endswith(('.png', '.jpg', '.jpeg'))]
21
  for f in image_files:
@@ -32,10 +31,9 @@ def load_car_dataset(base_path):
32
  dataset.append((full_path, cv2.resize(img, (100, 100))))
33
  return dataset
34
 
35
- # Veri setini yükle (32 markalık klasörü tara)
36
  dataset = load_car_dataset('Car_Logo_Dataset')
37
 
38
- # --- 4. RESİM İŞLEME FONKSİYONU ---
39
  @st.cache_data
40
  def process_uploaded_image(file_bytes):
41
  nparr = np.frombuffer(file_bytes, np.uint8)
@@ -49,31 +47,38 @@ def process_uploaded_image(file_bytes):
49
  st.title("🚗 Araba Logosu Tanıma Sistemi / Car Logo Recognition")
50
  st.markdown("---")
51
 
52
- # Sol ve Sağ Kolon Ayarı
53
- col_ui, col_res = st.columns([1, 1], gap="large")
54
 
55
- with col_ui:
56
- st.subheader("📤 Yükleme Paneli / Upload Panel")
57
- uploaded_file = st.file_uploader("Bir logo seçin / Select a logo", type=['jpg', 'png', 'jpeg'])
58
 
59
- # Hassasiyet Sliderı
60
- threshold = st.sidebar.slider("Hassasiyet / Sensitivity (Threshold)", 0.0, 1.0, 0.20)
61
- st.sidebar.info(f"Sistemde yüklü referans sayısı: {len(dataset)}")
62
-
63
- if uploaded_file:
64
- # Resmi işle (Önbellekten gelir, titreme yapmaz)
65
- raw_img, gray_img, edge_img = process_uploaded_image(uploaded_file.getvalue())
66
-
67
- with col_ui:
68
- # 2026 Standartlarında sabit genişlik (Titremeyi önler)
69
- st.image(raw_img, channels="BGR", width=450, caption="Yüklenen / Uploaded")
70
 
71
- with col_res:
72
- st.subheader("🎯 Analiz Sonucu / Analysis Result")
 
73
 
74
- if st.button("ŞİMDİ TANI / PREDICT NOW", type="primary"):
 
 
 
 
 
 
 
 
 
 
 
75
  with st.spinner("32 Marka Taranıyor... / Scanning..."):
76
- # Karşılaştırma döngüsü
77
  query = cv2.resize(gray_img, (100, 100))
78
  best_score = -1
79
  best_path = None
@@ -85,43 +90,49 @@ if uploaded_file:
85
  best_score = max_val
86
  best_path = path
87
 
88
- # MARKAYI YAZDIRMA BÖLÜMÜ
89
  if best_path and best_score >= threshold:
90
  st.balloons()
91
 
92
- # Dosya yolundan 32 markadan hangisi olduğunu bul
93
  folder_name = os.path.basename(os.path.dirname(best_path))
94
  if not folder_name or folder_name == '.':
95
  folder_name = os.path.basename(best_path).split('.')[0]
96
 
97
- # İsmi temizle ve büyük harf yap
98
  brand_name = ''.join([i for i in folder_name if not i.isdigit() and i not in ['-', '_']]).strip().upper()
99
 
100
  st.success(f"### TAHMİN / PREDICTION: **{brand_name}**")
101
  st.metric("Benzerlik / Similarity", f"%{int(best_score*100)}")
102
- st.image(best_path, width=150, caption=f"Eşleşen: {brand_name}")
103
  else:
104
  st.error("❌ Eşleşme Bulunamadı / Match Not Found")
 
 
105
 
106
- # --- TEKNİK ANALİZ (TİTREMEYEN ALT BÖLÜM) ---
 
107
  st.markdown("---")
108
- with st.expander("🔍 Teknik Görüntü Analizi / Technical Image Analysis"):
109
- tr_col, en_col = st.columns(2)
110
 
111
- with tr_col:
112
- st.write("### 🇹🇷 Türkçe Analiz")
113
- st.image(edge_img, width=300, caption="Canny Kenar Tespiti")
114
- st.write(f"Logonun dış hatları çıkartıldı ve sistemdeki {len(dataset)} resimle karşılaştırıldı.")
 
 
115
 
116
- with en_col:
117
- st.write("### 🇺🇸 English Analysis")
118
- st.image(edge_img, width=300, caption="Canny Edge Detection")
119
- st.write(f"Outlines were extracted and compared with {len(dataset)} reference images.")
 
 
120
 
121
- # Stil Ayarları (2026 Görünümü)
122
  st.markdown("""
123
  <style>
124
- .stButton>button { height: 3em; font-size: 20px; font-weight: bold; }
125
- .stMetric { background: #f0f2f6; padding: 10px; border-radius: 10px; }
126
  </style>
127
  """, unsafe_allow_html=True)
 
4
  import os
5
  import warnings
6
 
7
+ # --- 1. SİNSİ HATALARI SUSTUR / SILENCE ERRORS (2026) ---
8
  os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
9
  warnings.filterwarnings('ignore')
10
 
11
  # --- 2. SAYFA AYARLARI / PAGE CONFIG ---
12
  st.set_page_config(page_title="Car Logo AI Pro 2026", layout="wide", page_icon="🚗")
13
 
14
+ # --- 3. VERİ SETİNİ BELLEĞE YÜKLE / LOAD DATASET TO RAM ---
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:
 
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 ---
37
  @st.cache_data
38
  def process_uploaded_image(file_bytes):
39
  nparr = np.frombuffer(file_bytes, np.uint8)
 
47
  st.title("🚗 Araba Logosu Tanıma Sistemi / Car Logo Recognition")
48
  st.markdown("---")
49
 
50
+ # İki ana sütun oluşturuyoruz
51
+ col_left, col_right = st.columns([1, 1], gap="large")
52
 
53
+ with col_left:
54
+ st.subheader("📤 Yükleme Alanı / Upload Area")
 
55
 
56
+ # DOSYA YÜKLEME KUTUSU (Her zaman en üstte sabit kalır)
57
+ uploaded_file = st.file_uploader(
58
+ "Yeni bir logo seçin / Select a new logo",
59
+ type=['jpg', 'png', 'jpeg'],
60
+ key="main_uploader"
61
+ )
62
+
63
+ st.markdown("---") # Görsel ayırıcı çizgi
 
 
 
64
 
65
+ if uploaded_file:
66
+ # Resmi işle (Önbellekten gelir, titreme yapmaz)
67
+ raw_img, gray_img, edge_img = process_uploaded_image(uploaded_file.getvalue())
68
 
69
+ # Seçilen resmin önizlemesi (Yükleme kutusunun altında)
70
+ st.write("🖼️ **Seçilen Logo / Selected Logo:**")
71
+ st.image(raw_img, channels="BGR", width=400)
72
+
73
+ with col_right:
74
+ st.subheader("🎯 Analiz ve Sonuç / Analysis & Result")
75
+
76
+ # Hassasiyet Ayarı (Yan panel yerine burada daha erişilebilir)
77
+ threshold = st.slider("Hassasiyet / Sensitivity", 0.0, 1.0, 0.20)
78
+
79
+ if uploaded_file:
80
+ if st.button("ŞİMDİ TANI / PREDICT NOW", type="primary", use_container_width=True):
81
  with st.spinner("32 Marka Taranıyor... / Scanning..."):
 
82
  query = cv2.resize(gray_img, (100, 100))
83
  best_score = -1
84
  best_path = None
 
90
  best_score = max_val
91
  best_path = path
92
 
93
+ # SONUÇLARI GÖSTER
94
  if best_path and best_score >= threshold:
95
  st.balloons()
96
 
97
+ # Dosya yolundan marka adını ayıkla
98
  folder_name = os.path.basename(os.path.dirname(best_path))
99
  if not folder_name or folder_name == '.':
100
  folder_name = os.path.basename(best_path).split('.')[0]
101
 
 
102
  brand_name = ''.join([i for i in folder_name if not i.isdigit() and i not in ['-', '_']]).strip().upper()
103
 
104
  st.success(f"### TAHMİN / PREDICTION: **{brand_name}**")
105
  st.metric("Benzerlik / Similarity", f"%{int(best_score*100)}")
106
+ st.image(best_path, width=150, caption=f"Eşleşen Referans: {brand_name}")
107
  else:
108
  st.error("❌ Eşleşme Bulunamadı / Match Not Found")
109
+ else:
110
+ st.info("Lütfen soldaki panelden bir logo yükleyerek başlayın. / Please start by uploading a logo from the left panel.")
111
 
112
+ # --- 6. TEKNİK ANALİZ (ALT BÖLÜM) ---
113
+ if uploaded_file:
114
  st.markdown("---")
115
+ with st.expander("🔍 Teknik Detaylar / Technical Details"):
116
+ tab_tr, tab_en = st.tabs(["🇹🇷 Türkçe", "🇺🇸 English"])
117
 
118
+ with tab_tr:
119
+ st.write("### Görüntü İşleme Aşamaları")
120
+ c1, c2 = st.columns(2)
121
+ c1.image(edge_img, width=300, caption="Canny Kenar Analizi")
122
+ c2.image(cv2.resize(gray_img, (100, 100)), caption="Sistemin Gördüğü (100x100)")
123
+ st.info(f"Sistem şu an {len(dataset)} farklı referans resim üzerinden karşılaştırma yapıyor.")
124
 
125
+ with tab_en:
126
+ st.write("### Image Processing Stages")
127
+ ce1, ce2 = st.columns(2)
128
+ ce1.image(edge_img, width=300, caption="Canny Edge Detection")
129
+ ce2.image(cv2.resize(gray_img, (100, 100)), caption="AI View (100x100)")
130
+ st.info(f"The system is currently comparing through {len(dataset)} different reference images.")
131
 
132
+ # Stil Ayarları
133
  st.markdown("""
134
  <style>
135
+ .stButton>button { font-weight: bold; margin-top: 10px; }
136
+ .stMetric { background: #f8f9fa; border-radius: 10px; padding: 10px; border: 1px solid #ddd; }
137
  </style>
138
  """, unsafe_allow_html=True)