ma4389 commited on
Commit
dac2453
·
verified ·
1 Parent(s): bf24396

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +37 -0
  2. model.h5 +3 -0
  3. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ from tensorflow.keras.applications.mobilenet_v2 import preprocess_input
4
+ from tensorflow.keras.preprocessing import image
5
+ import numpy as np
6
+
7
+ # Load model
8
+ model = tf.keras.models.load_model("model.h5")
9
+
10
+ # Class labels (Italian animal names)
11
+ class_names = [
12
+ "cane", "cavallo", "elefante", "farfalla", "gallina",
13
+ "gatto", "mucca", "pecora", "ragno", "scoiattolo"
14
+ ]
15
+
16
+ # Prediction function
17
+ def predict(img):
18
+ img = img.convert("RGB")
19
+ img = img.resize((224, 224))
20
+ img_array = image.img_to_array(img)
21
+ img_array = preprocess_input(img_array)
22
+ img_array = np.expand_dims(img_array, axis=0)
23
+
24
+ predictions = model.predict(img_array)[0]
25
+ return {class_names[i]: float(predictions[i]) for i in range(len(class_names))}
26
+
27
+ # Gradio Interface
28
+ interface = gr.Interface(
29
+ fn=predict,
30
+ inputs=gr.Image(type="pil"),
31
+ outputs=gr.Label(num_top_classes=3),
32
+ title="Animal Classifier (10 Species)",
33
+ description="Upload an image of an animal. The model will classify it as one of: cane, cavallo, elefante, farfalla, gallina, gatto, mucca, pecora, ragno, scoiattolo."
34
+ )
35
+
36
+ if __name__ == "__main__":
37
+ interface.launch()
model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7bf4beb3a718712e7dc52f18a6965132ce3f457a608e8598b13b27252d6103ac
3
+ size 30495248
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio>=4.0.0
2
+ tensorflow>=2.10.0
3
+ numpy
4
+ Pillow