Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from tensorflow.keras.models import load_model
|
| 3 |
+
from tensorflow.keras.preprocessing import image
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
# Memuat model
|
| 7 |
+
model = load_model("cat_dog_model.h5")
|
| 8 |
+
|
| 9 |
+
# Fungsi prediksi
|
| 10 |
+
def predict_image(img):
|
| 11 |
+
img = img.resize((150, 150)) # Ubah ukuran gambar ke (150x150)
|
| 12 |
+
img_array = np.array(img) / 255.0 # Normalisasi
|
| 13 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 14 |
+
prediction = model.predict(img_array)
|
| 15 |
+
result = "Kucing" if prediction[0] < 0.5 else "Anjing"
|
| 16 |
+
return result
|
| 17 |
+
|
| 18 |
+
# Antarmuka Gradio
|
| 19 |
+
interface = gr.Interface(
|
| 20 |
+
fn=predict_image,
|
| 21 |
+
inputs=gr.Image(type="pil"), # Input berupa gambar
|
| 22 |
+
outputs="text", # Output berupa teks
|
| 23 |
+
title="Klasifikasi Gambar Kucing dan Anjing",
|
| 24 |
+
description="Unggah gambar kucing atau anjing untuk memprediksi kelasnya."
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
if __name__ == "__main__":
|
| 28 |
+
interface.launch()
|