ESMATUGBA commited on
Commit
cdb045f
·
verified ·
1 Parent(s): 1e7ccc7

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +109 -0
  2. fish_transfer_model.h5 +3 -0
app.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ import cv2
5
+ from PIL import Image
6
+ from tensorflow.keras.applications import MobileNetV2
7
+ from tensorflow.keras.models import Sequential
8
+ from tensorflow.keras.layers import GlobalAveragePooling2D, Dense, Dropout
9
+
10
+ # --- 1. SAYFA AYARLARI / PAGE CONFIG ---
11
+ st.set_page_config(page_title="Fish Classifier / Balık Sınıflandırıcı", page_icon="🐟", layout="wide")
12
+
13
+ # --- 2. MODEL YÜKLEME / LOAD MODEL ---
14
+ @st.cache_resource
15
+ def load_my_model():
16
+ # Mimariyi manuel kuruyoruz (Sürüm çakışmasını önlemek için)
17
+ base_model = MobileNetV2(weights='imagenet', include_top=False, input_shape=(170, 170, 3))
18
+ base_model.trainable = False
19
+
20
+ model = Sequential([
21
+ base_model,
22
+ GlobalAveragePooling2D(),
23
+ Dense(256, activation='relu'),
24
+ Dropout(0.5),
25
+ Dense(9, activation='softmax')
26
+ ])
27
+
28
+ # Ağırlıkları yükle
29
+ try:
30
+ model.load_weights('fish_transfer_model.h5')
31
+ except:
32
+ model = tf.keras.models.load_model('fish_transfer_model.h5')
33
+ return model
34
+
35
+ model = load_my_model()
36
+
37
+ # --- 3. SÖZLÜK / DICTIONARY ---
38
+ translate = {
39
+ 'Black Sea Sprat': 'Karadeniz Çaça',
40
+ 'Gilt-Head Bream': 'Çipura',
41
+ 'Hourse Mackerel': 'İstavrit',
42
+ 'Red Mullet': 'Barbun',
43
+ 'Red Sea Bream': 'Mercan',
44
+ 'Sea Bass': 'Levrek',
45
+ 'Shrimp': 'Karides',
46
+ 'Striped Red Mullet': 'Tekir',
47
+ 'Trout': 'Alabalık'
48
+ }
49
+ class_labels = sorted(list(translate.keys()))
50
+
51
+ # --- 4. SOL PANEL / SIDEBAR ---
52
+ with st.sidebar:
53
+ st.title("🔍 Species List / Tür Listesi")
54
+ st.write("Supported Fish Types / Desteklenen Balıklar:")
55
+ for en, tr in translate.items():
56
+ st.write(f"🔹 **{en}** / {tr}")
57
+
58
+ st.markdown("---")
59
+ st.info("Model: MobileNetV2\n\nAccuracy / Doğruluk: %99")
60
+
61
+ # --- 5. ANA EKRAN / MAIN SCREEN ---
62
+ st.title("🐟 Fish Classification System / Akıllı Balık Tanımlama")
63
+ st.subheader("Deep Learning Project / Derin Öğrenme Projesi")
64
+
65
+ # Sabit konteyner (Titremeyi önler)
66
+ main_container = st.container()
67
+
68
+ with main_container:
69
+ uploaded_file = st.file_uploader("Upload an image... / Bir resim yükleyin...", type=["jpg", "png", "jpeg"])
70
+
71
+ if uploaded_file is not None:
72
+ col1, col2 = st.columns([1, 1])
73
+
74
+ # Sol Kolon: Resim
75
+ image = Image.open(uploaded_file)
76
+ col1.image(image, caption="Uploaded Image / Yüklenen Resim", use_container_width=True)
77
+
78
+ # Sağ Kolon: Tahmin
79
+ with col2:
80
+ st.write("### Analysis Result / Analiz Sonucu")
81
+
82
+ # --- ÖN İŞLEME / PREPROCESSING ---
83
+ img = np.array(image.convert('RGB'))
84
+ img = cv2.resize(img, (170, 170))
85
+ img = img / 255.0
86
+ img = np.expand_dims(img, axis=0)
87
+
88
+ # --- TAHMİN / PREDICTION ---
89
+ preds = model.predict(img)
90
+ idx = np.argmax(preds)
91
+ prob = np.max(preds) * 100
92
+
93
+ label_en = class_labels[idx]
94
+ label_tr = translate[label_en]
95
+
96
+ # --- GÖRSEL KUTLAMA / CELEBRATION ---
97
+ st.success(f"**Result / Sonuç:** {label_en} / {label_tr}")
98
+ st.balloons() # Balonlar burada uçuyor! 🎈
99
+
100
+ st.metric(label="Confidence / Güven Oranı", value=f"%{prob:.2f}")
101
+
102
+ # Olasılık Grafiği / Chart
103
+ st.write("Probabilities / Olasılıklar:")
104
+ chart_data = {f"{k} / {translate[k]}": float(preds[0][i]) for i, k in enumerate(class_labels)}
105
+ st.bar_chart(chart_data)
106
+
107
+ # --- 6. ALT BİLGİ / FOOTER ---
108
+ st.markdown("---")
109
+ st.caption("Developed by Batman / Gotham City Data Labs 🦇")
fish_transfer_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7d534938fb8f88e5966a84154950c55fdf352cb5d48bdd30e0e8b71bc1ff761e
3
+ size 13367824