GarGerry's picture
Create app.py
9e37c1c verified
raw
history blame contribute delete
870 Bytes
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()