chaninder commited on
Commit
7c728e6
·
1 Parent(s): c4aa5b2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import tensorflow as tf
3
+ from tensorflow import keras
4
+
5
+ import huggingface_hub
6
+ from huggingface_hub import from_pretrained_keras
7
+
8
+
9
+ # load custom pre-trained model from HuggingFace models
10
+ model_api_link = 'chaninder/trashtacks-model-v1'
11
+ pre_trained_model = from_pretrained_keras(model_api_link)
12
+
13
+ # classification labels
14
+ labels = ['compost', 'e-waste', 'recycle', 'trash']
15
+
16
+
17
+ def classify_image(inp):
18
+ inp = inp.reshape((-1, 224, 224, 3))
19
+ #inp = tf.keras.applications.mobilenet_v2.preprocess_input(inp)
20
+ prediction = pre_trained_model.predict(inp).flatten()
21
+ confidences = {labels[i]: float(prediction[i]) for i in range(4)}
22
+ return confidences
23
+
24
+ # create Gradio interface
25
+
26
+ iface = gr.Interface(fn=classify_image,
27
+ inputs=gr.Image(shape=(224, 224)),
28
+ outputs=gr.Label(num_top_classes=4),
29
+ examples=["banana.jpg", 'can.jpg', 'battery.jpg'])
30
+
31
+ iface.launch(share=True)