jpbernardo commited on
Commit
dd37b39
·
verified ·
1 Parent(s): b0c2c94

Upload 3 files

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. app.py +48 -0
  3. model.keras +3 -0
  4. requirements.txt +4 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ model.keras filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Sun Nov 2 22:59:41 2025
4
+
5
+ @author: mathe
6
+ """
7
+
8
+ import gradio as gr
9
+ import numpy as np
10
+ from PIL import Image
11
+ import tensorflow as tf
12
+
13
+ # === CONFIGURAÇÕES ===
14
+ IMG_SIZE = 224
15
+ CLASS_NAMES = ["gato", "cachorro"] # mesma ordem do treino (0=cat, 1=dog)
16
+
17
+ # === CARREGAR MODELO ===
18
+ model = tf.keras.models.load_model("model.keras")
19
+
20
+ # === FUNÇÃO DE PREVISÃO ===
21
+ def preprocess_pil(img: Image.Image):
22
+ img = img.convert("RGB").resize((IMG_SIZE, IMG_SIZE))
23
+ arr = np.array(img, dtype=np.float32)
24
+ # MobileNetV2 preprocess (como no treino)
25
+ arr = tf.keras.applications.mobilenet_v2.preprocess_input(arr)
26
+ arr = np.expand_dims(arr, axis=0)
27
+ return arr
28
+
29
+ def predict(img: Image.Image):
30
+ x = preprocess_pil(img)
31
+ probs = model.predict(x)[0] # [p_cat, p_dog]
32
+ return {
33
+ CLASS_NAMES[0]: float(probs[0]),
34
+ CLASS_NAMES[1]: float(probs[1])
35
+ }
36
+
37
+ # === INTERFACE GRADIO ===
38
+ demo = gr.Interface(
39
+ fn=predict,
40
+ inputs=gr.Image(type="pil", label="Envie uma imagem"),
41
+ outputs=gr.Label(num_top_classes=2),
42
+ title="Classificador de Gatos vs. Cães 🐱🐶",
43
+ description="Modelo treinado com MobileNetV2 (Transfer Learning, TensorFlow)."
44
+ )
45
+
46
+ # === EXECUÇÃO LOCAL OU NO SPACE ===
47
+ if __name__ == "__main__":
48
+ demo.launch()
model.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:109ec1bd3ddd598830d804af3168c9fccf2407354f17d59438c89b6f53accbde
3
+ size 9659576
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio>=4.44
2
+ tensorflow==2.19.0
3
+ pillow
4
+ numpy