drgou commited on
Commit
ec60682
·
1 Parent(s): 5ea5ebf

add model stuff

Browse files
Files changed (3) hide show
  1. README.md +6 -5
  2. app.py +25 -4
  3. requirement.txt +3 -0
README.md CHANGED
@@ -1,12 +1,13 @@
1
  ---
2
- title: Masterclass Animal Classifier
3
- emoji: 📈
4
- colorFrom: pink
5
- colorTo: yellow
6
  sdk: gradio
7
- sdk_version: 5.32.1
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: Animal Classifier Space
3
+ emoji:
4
+ colorFrom: gray
5
+ colorTo: blue
6
  sdk: gradio
7
+ sdk_version: 5.29.0
8
  app_file: app.py
9
  pinned: false
10
+ short_description: Masterclass 2025
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py CHANGED
@@ -1,7 +1,28 @@
 
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
  import gradio as gr
3
+ import numpy as np
4
+ from huggingface_hub import hf_hub_download
5
 
6
+ # 1) download your SavedModel from the Hub
7
+ repo_id = "drgou/masterclass-2025"
8
+ hf_hub_download(repo_id, filename="config.json", repo_type="model", local_dir="./model")
9
+ hf_hub_download(repo_id, filename="metadata.json", repo_type="model", local_dir="./model")
10
+ hf_hub_download(repo_id, filename="model.weights.h5", repo_type="model", local_dir="./model")
11
 
12
+ # 2) load it
13
+ model = tf.keras.models.load_model("./model")
14
+
15
+ # 3) simple preprocess + predict
16
+ CLASS_NAMES = ["cat","dog","panda"]
17
+ def predict(image):
18
+ resized_image = tf.image.resize(image, (64,64))
19
+ images_to_predict = np.expand_dims(np.array(resized_image), axis=0)
20
+ probs = model.predict(images_to_predict)[0]
21
+ return {c: float(p) for c,p in zip(CLASS_NAMES, probs)}
22
+
23
+ # 4) launch Gradio
24
+ gr.Interface(
25
+ fn=predict,
26
+ inputs=gr.Image(),
27
+ outputs=gr.Label(num_top_classes=3)
28
+ ).launch()
requirement.txt CHANGED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ tensorflow>=2.19.0
2
+ gradio
3
+ huggingface_hub