Spaces:
Runtime error
Runtime error
Download app.py from mayankraj110/first_api: direct link, hf CLI and curl.
- Browser
- Download file 575 Bytes
-
https://huggingface.co/spaces/mayankraj110/first_api/resolve/main/app.py
- Command line
-
hf download hf://spaces/mayankraj110/first_api/app.py
-
curl -L -o app.py https://huggingface.co/spaces/mayankraj110/first_api/resolve/main/app.py
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() | |