Spaces:
Sleeping
Sleeping
Commit ·
52a4942
1
Parent(s): e6a0a21
Initial commit Plantopia
Browse files- README.md +0 -13
- app.py +40 -0
- label_encoder.pkl +3 -0
- plantopia.h5 +3 -0
- requirements.txt +10 -0
README.md
CHANGED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: Plantopia
|
| 3 |
-
emoji: 🦀
|
| 4 |
-
colorFrom: indigo
|
| 5 |
-
colorTo: green
|
| 6 |
-
sdk: gradio
|
| 7 |
-
sdk_version: 5.31.0
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
-
license: mit
|
| 11 |
-
---
|
| 12 |
-
|
| 13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
import pickle
|
| 5 |
+
from PIL import Image
|
| 6 |
+
|
| 7 |
+
# Load model & label encoder sekali di awal
|
| 8 |
+
model = tf.keras.models.load_model("my_cnn_model.h5")
|
| 9 |
+
with open("label_encoder.pkl", "rb") as f:
|
| 10 |
+
label_encoder = pickle.load(f)
|
| 11 |
+
|
| 12 |
+
# Daftar label
|
| 13 |
+
class_names = label_encoder.inverse_transform(np.arange(len(label_encoder.classes_)))
|
| 14 |
+
|
| 15 |
+
def predict(img: Image.Image):
|
| 16 |
+
img = img.resize((224, 224))
|
| 17 |
+
img_array = np.array(img) / 255.0
|
| 18 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 19 |
+
|
| 20 |
+
prediction = model.predict(img_array)[0]
|
| 21 |
+
predicted_index = np.argmax(prediction)
|
| 22 |
+
predicted_label = class_names[predicted_index]
|
| 23 |
+
predicted_confidence = prediction[predicted_index] * 100
|
| 24 |
+
|
| 25 |
+
result = f"✅ Prediksi penyakit tanaman: {predicted_label}\n"
|
| 26 |
+
result += f"🎯 Akurasi keyakinan model (confidence): {predicted_confidence:.2f}%\n\n"
|
| 27 |
+
result += "--- Detail Probabilitas untuk Semua Kelas ---\n"
|
| 28 |
+
for label, prob in zip(class_names, prediction):
|
| 29 |
+
result += f"{label:15}: {prob:.4f}\n"
|
| 30 |
+
|
| 31 |
+
return result
|
| 32 |
+
|
| 33 |
+
gr.Interface(
|
| 34 |
+
fn=predict,
|
| 35 |
+
inputs=gr.Image(type="pil"),
|
| 36 |
+
outputs="text",
|
| 37 |
+
title="Deteksi Penyakit Daun 🌿",
|
| 38 |
+
description="Upload gambar daun dan sistem akan memprediksi penyakitnya berdasarkan model CNN yang telah dilatih.",
|
| 39 |
+
allow_flagging="never"
|
| 40 |
+
).launch()
|
label_encoder.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8ea2192a47d152a2d6d2a160d64d15c33cada8ce580d22e3ae3deb78ffcdedfd
|
| 3 |
+
size 767
|
plantopia.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5fe734ac4a78796b2cbfff2f89ccc032b71e4d1739763388f725d475749b4d47
|
| 3 |
+
size 80486016
|
requirements.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow>=2.11.0
|
| 2 |
+
pandas
|
| 3 |
+
numpy
|
| 4 |
+
matplotlib
|
| 5 |
+
seaborn
|
| 6 |
+
Pillow
|
| 7 |
+
scikit-image
|
| 8 |
+
opencv-python-headless
|
| 9 |
+
scikit-learn
|
| 10 |
+
opendatasets
|