Nathan Segers
commited on
Commit
·
c43fe72
1
Parent(s):
9bc1ec2
Added Gradio file and requirements
Browse files- app.py +25 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import gradio as gr
|
| 4 |
+
from huggingface_hub import hf_hub_download
|
| 5 |
+
|
| 6 |
+
# 1) download your SavedModel from the Hub
|
| 7 |
+
repo_id = "NathanSegers/masterclass-2025"
|
| 8 |
+
model_dir = hf_hub_download(repo_id, filename="model_saved", repo_type="model", local_dir=".")
|
| 9 |
+
|
| 10 |
+
# 2) load it
|
| 11 |
+
model = tf.keras.models.load_model(model_dir)
|
| 12 |
+
|
| 13 |
+
# 3) simple preprocess + predict
|
| 14 |
+
CLASS_NAMES = ["cat","dog","panda"]
|
| 15 |
+
def predict(image):
|
| 16 |
+
img = tf.image.resize(image, (64,64)) / 255.0
|
| 17 |
+
probs = model.predict(img[None,...])[0]
|
| 18 |
+
return {c: float(p) for c,p in zip(CLASS_NAMES, probs)}
|
| 19 |
+
|
| 20 |
+
# 4) launch Gradio
|
| 21 |
+
gr.Interface(
|
| 22 |
+
fn=predict,
|
| 23 |
+
inputs=gr.Image(shape=(224,224)),
|
| 24 |
+
outputs=gr.Label(num_top_classes=3)
|
| 25 |
+
).launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow>=2.19.0
|
| 2 |
+
gradio
|
| 3 |
+
huggingface_hub
|