Spaces:
Runtime error

first_api / app.py
mayankraj110's picture
Update app.py
304210b verified
Raw History Blame Contribute Delete
575 Bytes
import gradio as gr
import tensorflow as tf
import numpy as np
from PIL import Image
# Load your model
model = tf.keras.models.load_model("best_model.keras")
# Prediction function
def predict(img: Image.Image):
img = img.resize((224, 224)) # adjust size to match your model
img = np.array(img) / 255.0
img = np.expand_dims(img, axis=0)
pred = model.predict(img)
return {"prediction": pred.tolist()}
# Gradio interface
demo = gr.Interface(
fn=predict,
inputs=gr.Image(type="pil"), # <-- ensures PIL Image
outputs="json"
)
demo.launch()