| import streamlit as st, tensorflow as tf, numpy as np, json |
| from PIL import Image |
|
|
| st.set_page_config(page_title="CNN vs Transfer", page_icon="🚢") |
| st.title("🌾🍇 CNN vs Transfer Learning") |
| st.caption("Rice (5 sınıf) ve Grapevine Disease — iki ayrı modelin tahminleri") |
|
|
| MODELS = {"🌾 Rice": "rice", "🍇 Grapevine Disease": "grapevine"} |
| choice = st.selectbox("Veri seti / Model", list(MODELS.keys())) |
| tag = MODELS[choice] |
|
|
| @st.cache_resource |
| def load(tag): |
| return tf.keras.models.load_model(f"model_{tag}.keras"), json.load(open(f"classes_{tag}.json")) |
|
|
| model, CLS = load(tag) |
|
|
| f = st.file_uploader("Görsel yükle", ["jpg","jpeg","png"]) |
| if f: |
| img = Image.open(f).convert("RGB").resize((224,224)) |
| st.image(img, width=300) |
| p = model.predict(np.expand_dims(np.array(img,"float32"),0), verbose=0)[0] |
| idx = int(p.argmax()) |
| st.subheader(f"Tahmin: **{CLS[idx]}**") |
| st.metric("Güven", f"%{p[idx]*100:.1f}") |
| st.bar_chart(dict(zip(CLS, p.astype(float)))) |