CoolFace
Apppublic

mayankraj110/first_api

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
app.py26 linesDownload Raw Back to root
1import gradio as gr2import tensorflow as tf3import numpy as np4from PIL import Image5 6# Load your model7model = tf.keras.models.load_model("best_model.keras")8 9# Prediction function10def predict(img: Image.Image):11    img = img.resize((224, 224))  # adjust size to match your model12    img = np.array(img) / 255.013    img = np.expand_dims(img, axis=0)14 15    pred = model.predict(img)16    return {"prediction": pred.tolist()}17 18# Gradio interface19demo = gr.Interface(20    fn=predict,21    inputs=gr.Image(type="pil"),   # <-- ensures PIL Image22    outputs="json"23)24 25demo.launch()26