File size: 870 Bytes
9e37c1c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import gradio as gr
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing import image
import numpy as np

# Memuat model
model = load_model("cat_dog_model.h5")

# Fungsi prediksi
def predict_image(img):
    img = img.resize((150, 150))  # Ubah ukuran gambar ke (150x150)
    img_array = np.array(img) / 255.0  # Normalisasi
    img_array = np.expand_dims(img_array, axis=0)
    prediction = model.predict(img_array)
    result = "Kucing" if prediction[0] < 0.5 else "Anjing"
    return result

# Antarmuka Gradio
interface = gr.Interface(
    fn=predict_image,
    inputs=gr.Image(type="pil"),  # Input berupa gambar
    outputs="text",  # Output berupa teks
    title="Klasifikasi Gambar Kucing dan Anjing",
    description="Unggah gambar kucing atau anjing untuk memprediksi kelasnya."
)

if __name__ == "__main__":
    interface.launch()