Bryan LE GRAND commited on
Commit
a69a642
1 Parent(s): 9c32af6

Upload 7 files

Browse files
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+
4
+ class_names = ['apples', 'artichokes', 'asparagus', 'aubergine', 'avocados', 'banana', 'bell peppers', 'broccoli', 'carrots', 'celery', 'courgette', 'garlic', 'ginger', 'grapefruit', 'grapes', 'kiwi', 'mangos', 'mushrooms', 'onions', 'orange', 'passion fruit', 'peas', 'pineapple', 'potatoes', 'salad', 'spinach', 'strawberry', 'sweet potatos', 'tomato', 'watermelon']
5
+ model = tf.keras.models.load_model("fruits_and_vegetables_model.h5")
6
+
7
+ def load_and_predict_img(inp, img_shape=224):
8
+ img_4d=inp.reshape(-1,224,224,3) # reshape our image for passing to the model
9
+ prediction = model.predict(img_4d) # predicting using the model
10
+ pred_labels_and_probs = {class_names[i]: float(prediction[0][i]) for i in range(len(class_names))}
11
+ return_string = f"We believe this is a {class_names[tf.argmax(prediction[0])]}, we are {round(float(prediction[0][tf.argmax(prediction[0])]),2)}% confident in our prediction"
12
+ return return_string, pred_labels_and_probs
13
+
14
+ # Create examples list from "examples/" directory
15
+ example_list = [["examples/" + example] for example in os.listdir("examples")]
16
+
17
+ fruits_and_veggies = gr.Interface(
18
+ fn=load_and_predict_img,
19
+ inputs=gr.Image(shape=(224,224), label="Upload an image"),
20
+ outputs=[gr.Textbox(label="Result"),
21
+ gr.Label(num_top_classes=3, label="Top 3 Predictions")],
22
+ title="Fruits and Vegetable Identifier",
23
+ description="""Take photos of your fruits and vegetables to identify them. Here is a list of fruits and veggies that this application can recognize...
24
+ Apples, Artichokes, Asparagus, Aubergine, Avocados, Banana, Bell Pepper, Broccoli, Carrot, Celery, Courgette, Garlic, Ginger,
25
+ Grapefruit, Grapes, Kiwi, Mangos, Mushrooms, Onions, Oranges, Passion Fruit, Peas, Pineapple, Potato, Salad, Spinach, Strawberry, Sweet Potato, Tomato, Watermelon""",
26
+ allow_flagging="never",
27
+ examples=example_list
28
+ )
29
+ fruits_and_veggies.launch()
examples/apples.jpg ADDED
examples/courgette.jpg ADDED
examples/ginger.jpg ADDED
examples/pineapples.jpg ADDED
fruits_and_vegetables_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:006c2fab16011add419afc452d0fe9e849c8a2e06e7361e9c2f03c991ea5239c
3
+ size 23325712
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ tensoflow==2.12.0
2
+ gradio==3.35.2