Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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.
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
# --- 2.
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
@st.cache_data
|
| 12 |
-
def
|
| 13 |
nparr = np.frombuffer(file_bytes, np.uint8)
|
| 14 |
img = cv2.imdecode(nparr, 1)
|
| 15 |
-
if img is None: return None, None
|
| 16 |
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
| 17 |
edges = cv2.Canny(gray, 100, 200)
|
| 18 |
-
return img,
|
| 19 |
-
|
| 20 |
-
# --- 3. ARAYÜZ / INTERFACE ---
|
| 21 |
-
st.title("🚗 Araba Logosu Tanıma / Car Logo Recognition")
|
| 22 |
-
st.markdown("---")
|
| 23 |
|
| 24 |
-
#
|
| 25 |
-
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
img_data, gray_data, edge_data = process_uploaded_image(uploaded_file.getvalue())
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
-
|
| 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 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
st.balloons()
|
| 45 |
-
st.success("✅
|
| 46 |
-
st.metric("
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
st.info("Sistem, logonun dış hatlarını (kenarlarını) çıkararak veri setindeki örneklerle karşılaştırır.")
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 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 |
-
#
|
| 68 |
-
st.
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 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)
|