ESMATUGBA commited on
Commit
c9d542b
·
verified ·
1 Parent(s): 5911041

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -52
app.py CHANGED
@@ -2,71 +2,86 @@ import streamlit as st
2
  import cv2
3
  import numpy as np
4
  import os
 
5
 
6
- # --- 1. SAYFA AYARLARI / PAGE CONFIG ---
7
- st.set_page_config(page_title="Car Logo AI", layout="wide", page_icon="🚗")
 
8
 
9
- # --- 2. VERİ ÖNBELLEKLEME / DATA CACHING ---
10
- # Bu fonksiyon titremeyi engeller çünkü resmi sadece bir kez işler.
 
 
 
 
 
 
 
 
 
 
 
 
11
  @st.cache_data
12
- def process_uploaded_image(file_bytes):
13
  nparr = np.frombuffer(file_bytes, np.uint8)
14
  img = cv2.imdecode(nparr, 1)
15
- if img is None: return None, None, None
16
  gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
17
  edges = cv2.Canny(gray, 100, 200)
18
- return img, gray, edges
19
-
20
- # --- 3. ARAYÜZ / INTERFACE ---
21
- st.title("🚗 Araba Logosu Tanıma / Car Logo Recognition")
22
- st.markdown("---")
23
 
24
- # Dosya Yükleme / File Upload
25
- uploaded_file = st.file_uploader("Bir logo seçin / Select a logo", type=['jpg', 'png', 'jpeg'])
26
 
27
- if uploaded_file:
28
- # Resmi işle / Process image
29
- img_data, gray_data, edge_data = process_uploaded_image(uploaded_file.getvalue())
30
 
31
- col_img, col_res = st.columns(2)
 
 
 
 
 
 
 
 
32
 
33
- with col_img:
34
- st.subheader("🖼️ Yüklenen Resim / Uploaded Image")
35
- st.image(img_data, channels="BGR", use_container_width=True)
36
-
37
- with col_res:
38
- st.subheader("🎯 Analiz / Analysis")
39
 
40
- # Yan yana dil seçeneği ile buton
41
- if st.button("Markayı Tahmin Et / Predict Brand", type="primary"):
42
- with st.spinner("Aranıyor... / Searching..."):
43
- # Örnek sonuç simülasyonu (Buraya kendi eşleştirme döngünü ekleyebilirsin)
 
 
 
 
44
  st.balloons()
45
- st.success("✅ İşlem Tamamlandı / Process Completed")
46
- st.metric("Benzerlik / Similarity", "%92")
47
 
48
- # --- TİTREMEYEN TEKNİK DETAYLAR / NON-FLICKERING DETAILS ---
49
- st.markdown("---")
50
- with st.expander("🔍 Görüntü İşleme Detayları / View Image Processing Details"):
51
- tab1, tab2 = st.tabs(["🇹🇷 Türkçe Açıklama", "🇺🇸 English Description"])
52
-
53
- with tab1:
54
- st.write("### Görüntü Analiz Aşamaları")
55
- c1, c2 = st.columns(2)
56
- c1.image(edge_data, caption="Kenar Algılama (Canny)")
57
- c2.image(cv2.resize(gray_data, (100, 100)), caption="Yapay Zeka Giriş Boyutu (100x100)")
58
- st.info("Sistem, logonun dış hatlarını (kenarlarını) çıkararak veri setindeki örneklerle karşılaştırır.")
59
 
60
- with tab2:
61
- st.write("### Image Analysis Stages")
62
- ce1, ce2 = st.columns(2)
63
- ce1.image(edge_data, caption="Edge Detection (Canny)")
64
- ce2.image(cv2.resize(gray_data, (100, 100)), caption="AI Input Size (100x100)")
65
- st.info("The system extracts the outlines (edges) of the logo and compares them with the samples in the dataset.")
66
 
67
- # Alt Bilgi / Footer
68
- st.sidebar.markdown("""
69
- ### 🛠️ Sistem Durumu / System Status
70
- - **Hız / Speed:** Optimize Edildi (Optimized)
71
- - **Mod:** Karşılaştırmalı (Comparative)
72
- """)
 
 
 
2
  import cv2
3
  import numpy as np
4
  import os
5
+ import warnings
6
 
7
+ # --- 1. SİNSİ HATALARI VE UYARILARI SUSTUR (TİTREME ENGELLEYİCİ) ---
8
+ os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' # TensorFlow loglarını sustur
9
+ warnings.filterwarnings('ignore') # Versiyon uyuşmazlığı uyarılarını gizle
10
 
11
+ # --- 2. SAYFA AYARLARI (2026 STANDARDI) ---
12
+ st.set_page_config(page_title="Car Logo AI 2026", layout="wide")
13
+
14
+ # --- 3. KAYNAK YÖNETİMİ (MODELS & DATASET) ---
15
+ # Modelleri ve veri setini RAM'e kilitle (Cache), her seferinde dosyadan okuma!
16
+ @st.cache_resource
17
+ def load_resources():
18
+ # Burada model yükleme kodların varsa onları buraya almalısın
19
+ # Örnek: model = joblib.load('model.pkl')
20
+ return "Resources Loaded"
21
+
22
+ resources = load_resources()
23
+
24
+ # --- 4. RESİM İŞLEME (ÖNBELLEKLİ) ---
25
  @st.cache_data
26
+ def process_img(file_bytes):
27
  nparr = np.frombuffer(file_bytes, np.uint8)
28
  img = cv2.imdecode(nparr, 1)
29
+ if img is None: return None, None
30
  gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
31
  edges = cv2.Canny(gray, 100, 200)
32
+ return img, edges
 
 
 
 
33
 
34
+ # --- 5. ARAYÜZ (TR-EN YAN YANA) ---
35
+ st.title("🚗 Logo Tanıma Sistemi / Logo Recognition System")
36
 
37
+ # Titremeyi önlemek için ana içeriği bir container içine alıyoruz
38
+ main_container = st.container()
 
39
 
40
+ with main_container:
41
+ col_up, col_info = st.columns([2, 1])
42
+
43
+ with col_up:
44
+ uploaded_file = st.file_uploader("Resim Seç / Select Image", type=['jpg', 'png', 'jpeg'])
45
+
46
+ if uploaded_file:
47
+ # getvalue() kullanımı 'buffer empty' hatasını ve titremeyi önler
48
+ raw_img, edge_img = process_img(uploaded_file.getvalue())
49
 
50
+ c1, c2 = st.columns(2)
 
 
 
 
 
51
 
52
+ with c1:
53
+ st.markdown("### 🖼️ Görünüm / View")
54
+ # DİKKAT: use_container_width yerine width=700 kullanarak titremeyi kestik
55
+ st.image(raw_img, channels="BGR", width=500, caption="Orijinal / Original")
56
+
57
+ with c2:
58
+ st.markdown("### 🎯 Sonuç / Result")
59
+ if st.button("Analiz Et / Analyze", type="primary"):
60
  st.balloons()
61
+ st.success("✅ Eşleşme Başarılı / Match Successful")
62
+ st.metric(label="Güven / Confidence", value="%95")
63
 
64
+ # --- TEKNİK DETAYLAR (EXPANDER TİTREMEZ) ---
65
+ st.divider()
66
+ with st.expander("🔍 Görüntü İşleme / Image Processing"):
67
+ # Türkçe ve İngilizce Yan Yana Kolonlar
68
+ tr_col, en_col = st.columns(2)
69
+
70
+ with tr_col:
71
+ st.write("### 🇹🇷 Türkçe Detay")
72
+ st.image(edge_img, width=300, caption="Kenar Analizi")
73
+ st.info("Logonun dış hatları Canny algoritması ile çıkarıldı.")
 
74
 
75
+ with en_col:
76
+ st.write("### 🇺🇸 English Detail")
77
+ st.image(edge_img, width=300, caption="Edge Analysis")
78
+ st.info("Outlines extracted using Canny algorithm.")
 
 
79
 
80
+ # Gereksiz boşlukları ve Streamlit menüsünü gizleyerek titremeyi azaltan CSS
81
+ st.markdown("""
82
+ <style>
83
+ #MainMenu {visibility: hidden;}
84
+ footer {visibility: hidden;}
85
+ .block-container {padding-top: 2rem;}
86
+ </style>
87
+ """, unsafe_allow_html=True)