import gradio as gr import numpy as np from tensorflow.keras.models import load_model from tensorflow.keras.preprocessing.image import img_to_array from PIL import Image import io model = load_model('Dog_Cat_64-64_512Dense.h5') def predict_image(img): if img is None: return None img = Image.fromarray(img.astype('uint8'), 'RGB') img = img.resize((64, 64)) # Modelin giriş boyutu img_array = img_to_array(img) img_array = np.expand_dims(img_array, axis=0) prediction = model.predict(img_array)[0][0] # Tahmin tahmin = "Köpek" if prediction > 0.5 else "Kedi" dogruluk = prediction if prediction > 0.5 else 1 - prediction sonuc = f"""
Bu resim büyük olasılıkla bir {tahmin}!
Tahmin Güveni: {dogruluk*100:.2f}%
Daha fazla açıklama yok bir kedi veya köpek resmi yükleyin ve sonucu görün!
""" footer = """ """ myGradioAppInterface = gr.Interface( fn=predict_image, inputs=gr.Image(type="numpy", label="Resim Yükle"), outputs=gr.HTML(label="Tahmin Sonucu"), title="🐾 Kedi/Köpek Tahmin Uygulaması 🐾", description=descr, article=footer, theme=gr.themes.Soft().set( body_background_fill="#f0f2f6", button_primary_background_fill="#4a90e2", button_shadow="#205493", ), allow_flagging=False, ) myGradioAppInterface.launch()