Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +18 -10
src/streamlit_app.py
CHANGED
|
@@ -4,24 +4,31 @@ import numpy as np
|
|
| 4 |
import os
|
| 5 |
from PIL import Image
|
| 6 |
|
| 7 |
-
# ---
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
st.set_page_config(page_title="Car Logo AI", layout="wide")
|
| 11 |
|
| 12 |
# --- BAŞLIK / TITLE ---
|
| 13 |
st.markdown("<h1 style='text-align: center;'>🚗 Araba Logosu Tanıma / Car Logo Recognition</h1>", unsafe_allow_html=True)
|
| 14 |
-
st.markdown("<p style='text-align: center;'>
|
| 15 |
st.markdown("---")
|
| 16 |
|
| 17 |
-
# ---
|
| 18 |
def predict_logo(uploaded_file):
|
| 19 |
-
# Kritik Düzeltme: Dosyayı okumadan önce başına sarıyoruz
|
| 20 |
uploaded_file.seek(0)
|
| 21 |
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
|
| 22 |
query_img = cv2.imdecode(file_bytes, 0)
|
| 23 |
|
| 24 |
-
# Resim başarıyla okundu mu kontrolü
|
| 25 |
if query_img is None:
|
| 26 |
return None, 0
|
| 27 |
|
|
@@ -30,6 +37,10 @@ def predict_logo(uploaded_file):
|
|
| 30 |
best_brand = None
|
| 31 |
|
| 32 |
# Veri setini tara
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
for brand in os.listdir(base_path):
|
| 34 |
brand_path = os.path.join(base_path, brand)
|
| 35 |
if os.path.isdir(brand_path):
|
|
@@ -48,7 +59,7 @@ def predict_logo(uploaded_file):
|
|
| 48 |
|
| 49 |
return best_brand, best_score
|
| 50 |
|
| 51 |
-
# ---
|
| 52 |
col_left, col_right = st.columns(2)
|
| 53 |
|
| 54 |
with col_left:
|
|
@@ -63,15 +74,12 @@ if uploaded_file is not None:
|
|
| 63 |
|
| 64 |
st.markdown("---")
|
| 65 |
|
| 66 |
-
# ANALİZ BUTONU / ANALYSIS BUTTON
|
| 67 |
if st.button('Analiz Et / Analyze'):
|
| 68 |
with st.spinner('İşleniyor... / Processing...'):
|
| 69 |
brand, score = predict_logo(uploaded_file)
|
| 70 |
|
| 71 |
if brand and score > 0.4:
|
| 72 |
-
# BAŞARI! BALONLAR / SUCCESS! BALLOONS
|
| 73 |
st.balloons()
|
| 74 |
-
|
| 75 |
brand_clean = brand.split('-')[-1]
|
| 76 |
|
| 77 |
res_col1, res_col2 = st.columns(2)
|
|
|
|
| 4 |
import os
|
| 5 |
from PIL import Image
|
| 6 |
|
| 7 |
+
# --- AKILLI YOL YAPILANDIRMASI / SMART PATH CONFIGURATION ---
|
| 8 |
+
# Kendi bilgisayarındaki yol
|
| 9 |
+
local_path = r'C:\Users\MERGEN\OneDrive\Documents\Yapay Zeka Kursu\Prework\14\Car_Logo_Dataset'
|
| 10 |
+
# Hugging Face veya genel bulut yolu
|
| 11 |
+
cloud_path = 'Car_Logo_Dataset'
|
| 12 |
+
|
| 13 |
+
# Bilgisayarında mısın yoksa bulutta mı kontrol et
|
| 14 |
+
if os.path.exists(local_path):
|
| 15 |
+
base_path = local_path
|
| 16 |
+
else:
|
| 17 |
+
base_path = cloud_path
|
| 18 |
|
| 19 |
st.set_page_config(page_title="Car Logo AI", layout="wide")
|
| 20 |
|
| 21 |
# --- BAŞLIK / TITLE ---
|
| 22 |
st.markdown("<h1 style='text-align: center;'>🚗 Araba Logosu Tanıma / Car Logo Recognition</h1>", unsafe_allow_html=True)
|
| 23 |
+
st.markdown("<p style='text-align: center;'>Computer Vision Project</p>", unsafe_allow_html=True)
|
| 24 |
st.markdown("---")
|
| 25 |
|
| 26 |
+
# --- LOGO TANIMA FONKSİYONU / RECOGNITION FUNCTION ---
|
| 27 |
def predict_logo(uploaded_file):
|
|
|
|
| 28 |
uploaded_file.seek(0)
|
| 29 |
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
|
| 30 |
query_img = cv2.imdecode(file_bytes, 0)
|
| 31 |
|
|
|
|
| 32 |
if query_img is None:
|
| 33 |
return None, 0
|
| 34 |
|
|
|
|
| 37 |
best_brand = None
|
| 38 |
|
| 39 |
# Veri setini tara
|
| 40 |
+
if not os.path.exists(base_path):
|
| 41 |
+
st.error(f"Klasör bulunamadı! / Folder not found: {base_path}")
|
| 42 |
+
return None, 0
|
| 43 |
+
|
| 44 |
for brand in os.listdir(base_path):
|
| 45 |
brand_path = os.path.join(base_path, brand)
|
| 46 |
if os.path.isdir(brand_path):
|
|
|
|
| 59 |
|
| 60 |
return best_brand, best_score
|
| 61 |
|
| 62 |
+
# --- ARAYÜZ / UI ---
|
| 63 |
col_left, col_right = st.columns(2)
|
| 64 |
|
| 65 |
with col_left:
|
|
|
|
| 74 |
|
| 75 |
st.markdown("---")
|
| 76 |
|
|
|
|
| 77 |
if st.button('Analiz Et / Analyze'):
|
| 78 |
with st.spinner('İşleniyor... / Processing...'):
|
| 79 |
brand, score = predict_logo(uploaded_file)
|
| 80 |
|
| 81 |
if brand and score > 0.4:
|
|
|
|
| 82 |
st.balloons()
|
|
|
|
| 83 |
brand_clean = brand.split('-')[-1]
|
| 84 |
|
| 85 |
res_col1, res_col2 = st.columns(2)
|