EduFalcao commited on
Commit
57b9e42
·
verified ·
1 Parent(s): 0b93655

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +26 -14
  2. app.py +39 -0
  3. requirements.txt +4 -0
README.md CHANGED
@@ -1,14 +1,26 @@
1
- ---
2
- title: CropVision
3
- emoji: 🚀
4
- colorFrom: green
5
- colorTo: green
6
- sdk: gradio
7
- sdk_version: 5.28.0
8
- app_file: app.py
9
- pinned: false
10
- license: mit
11
- short_description: Modelo CropVision
12
- ---
13
-
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CropVision – Hugging Face Space
2
+
3
+ Este Space demonstra um modelo CNN que classifica folhas de videira da região do Douro em quatro classes:
4
+
5
+ * Healthy
6
+ * Leaf Blight
7
+ * Black Rot
8
+ * ESCA
9
+
10
+ O backend usa **Gradio** para a interface de upload/predição e **TensorFlow/Keras** para inferência.
11
+ Licença do código: **MIT** (ver ficheiro LICENSE ou campo de licença do repositório).
12
+
13
+ ## Como usar
14
+
15
+ 1. Faça upload de `cropvision_model.keras` (ou `.h5`) na raiz do Space, juntamente com `app.py` e `requirements.txt`.
16
+ 2. O Space compila automaticamente e disponibiliza uma página de teste.
17
+
18
+ ## Requisitos
19
+
20
+ ```
21
+ gradio
22
+ tensorflow
23
+ pillow
24
+ numpy
25
+ ```
26
+
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from tensorflow.keras.preprocessing.image import img_to_array
4
+ from tensorflow.keras.models import load_model
5
+ from PIL import Image
6
+
7
+ # --- Constants ---
8
+ IMG_SIZE = (224, 224)
9
+ CLASS_ORDER = ['Healthy', 'Leaf Blight', 'Black Rot', 'ESCA']
10
+ MODEL_PATH = "cropvision_model.keras" # ensure this file is in the same folder
11
+
12
+ # --- Load model once at startup ---
13
+ model = load_model(MODEL_PATH)
14
+
15
+ # --- Prediction function ---
16
+ def predict(image: Image.Image):
17
+ # Resize & preprocess
18
+ img = image.convert("RGB").resize(IMG_SIZE)
19
+ arr = img_to_array(img) / 255.0
20
+ arr = np.expand_dims(arr, 0)
21
+
22
+ # Inference
23
+ probs = model.predict(arr)
24
+ cls = CLASS_ORDER[int(np.argmax(probs))]
25
+ conf = float(np.max(probs))
26
+
27
+ return f"{cls} ({conf:.1%})"
28
+
29
+ # --- Gradio UI ---
30
+ demo = gr.Interface(
31
+ fn=predict,
32
+ inputs=gr.Image(type="pil", label="Carrega uma imagem"),
33
+ outputs=gr.Textbox(label="Resultado"),
34
+ title="CropVision – classificação de doenças na videira",
35
+ description="Modelo que vai distinguir Healthy / Leaf Blight / Black Rot / ESCA"
36
+ )
37
+
38
+ if __name__ == "__main__":
39
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ tensorflow
3
+ pillow
4
+ numpy