Spaces:
Sleeping
Sleeping
File size: 1,446 Bytes
9231c87 f8f5302 e1be59e f8f5302 9231c87 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import tensorflow as tf
import gradio as gr
import numpy as np
from huggingface_hub import hf_hub_download
# Repository Not Found for url: https://huggingface.co/IDS75912/CTAIAnimalClassifier/resolve/main/config.json.
# Please make sure you specified the correct `repo_id` and `repo_type`.
# If you are trying to access a private or gated repo, make sure you are authenticated. For more details, see https://huggingface.co/docs/huggingface_hub/authentication
# Invalid username or password
# 1) download your SavedModel from the Hub:
# so refer to the repository where your model is, not the one for the space!
repo_id = "IDS75912/masterclass-2025"
hf_hub_download(repo_id, filename="config.json", repo_type="model", local_dir="./model")
hf_hub_download(repo_id, filename="metadata.json", repo_type="model", local_dir="./model")
hf_hub_download(repo_id, filename="model.weights.h5", repo_type="model", local_dir="./model")
# 2) load it
model = tf.keras.models.load_model("./model")
# 3) simple preprocess + predict
CLASS_NAMES = ["cat","dog","panda"]
def predict(image):
resized_image = tf.image.resize(image, (64,64))
images_to_predict = np.expand_dims(np.array(resized_image), axis=0)
probs = model.predict(images_to_predict)[0]
return {c: float(p) for c,p in zip(CLASS_NAMES, probs)}
# 4) launch Gradio
gr.Interface(
fn=predict,
inputs=gr.Image(),
outputs=gr.Label(num_top_classes=3)
).launch(share=True) |