zotthytt12 commited on
Commit
5024345
·
verified ·
1 Parent(s): e527bfa

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ from tensorflow.keras.preprocessing import image
4
+ from huggingface_hub import hf_hub_download
5
+ import numpy as np
6
+ import os
7
+
8
+ MODEL_REPO = "zotthytt12/vegetable-classifier" # <- zmień
9
+ MODEL_FILENAME = "model/veg_model.h5"
10
+
11
+ # pobierz model z Hugging Face Hub
12
+ model_path = hf_hub_download(repo_id=MODEL_REPO, filename=MODEL_FILENAME)
13
+ model = tf.keras.models.load_model(model_path)
14
+
15
+ # (opcjonalnie) nazwy klas
16
+ CLASS_NAMES = ['Bean', 'Bitter_Gourd', 'Bottle_Gourd', 'Brinjal', 'Broccoli',
17
+ 'Cabbage', 'Capsicum', 'Carrot', 'Cauliflower', 'Cucumber',
18
+ 'Papaya', 'Potato', 'Pumpkin', 'Radish', 'Tomato']
19
+
20
+ IMG_SIZE = (128, 128)
21
+
22
+ def predict(img):
23
+ img = img.resize(IMG_SIZE)
24
+ x = image.img_to_array(img)
25
+ x = np.expand_dims(x, axis=0) / 255.0
26
+ preds = model.predict(x)
27
+ probs = preds[0]
28
+ return {CLASS_NAMES[i]: float(probs[i]) for i in range(len(CLASS_NAMES))}
29
+
30
+ iface = gr.Interface(
31
+ fn=predict,
32
+ inputs=gr.Image(type="pil"),
33
+ outputs=gr.Label(num_top_classes=3),
34
+ title="Vegetable Classifier",
35
+ description="Wgraj zdjęcie warzywa, a model powie co to jest."
36
+ )
37
+
38
+ if __name__ == "__main__":
39
+ iface.launch()