zotthytt12 commited on
Commit
82389eb
verified
1 Parent(s): da2310a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -5,21 +5,23 @@ 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
@@ -29,11 +31,11 @@ def predict(img):
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(show_error=True)
 
5
  import numpy as np
6
  import os
7
 
8
+ MODEL_REPO = "zotthytt12/vegetable-classifier"
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
  CLASS_NAMES = ['Bean', 'Bitter_Gourd', 'Bottle_Gourd', 'Brinjal', 'Broccoli',
16
  'Cabbage', 'Capsicum', 'Carrot', 'Cauliflower', 'Cucumber',
17
  'Papaya', 'Potato', 'Pumpkin', 'Radish', 'Tomato']
18
 
19
  IMG_SIZE = (128, 128)
20
 
21
+ def predict(img_path):
22
+ # img_path to 艣cie偶ka do pliku, kt贸ry Gradio stworzy艂
23
+ from PIL import Image
24
+ img = Image.open(img_path)
25
  img = img.resize(IMG_SIZE)
26
  x = image.img_to_array(img)
27
  x = np.expand_dims(x, axis=0) / 255.0
 
31
 
32
  iface = gr.Interface(
33
  fn=predict,
34
+ inputs=gr.Image(type="filepath"), # zmienione z "pil" na "filepath"
35
  outputs=gr.Label(num_top_classes=3),
36
  title="Vegetable Classifier",
37
  description="Wgraj zdj臋cie warzywa, a model powie co to jest."
38
  )
39
 
40
  if __name__ == "__main__":
41
+ iface.launch(show_error=True)