0xrushi commited on
Commit
9da5fda
1 Parent(s): 9452024

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ from huggingface_hub import from_pretrained_keras
4
+ import tensorflow as tf
5
+ import numpy as np
6
+
7
+ model = from_pretrained_keras("rushic24/bit")
8
+ allImages = []
9
+ directory = 'images'
10
+ CLASSES = ['daisy', 'dandelion', 'roses', 'sunflowers', 'tulips']
11
+ # iterate over files in images directory
12
+ for filename in os.listdir(directory):
13
+ f = os.path.join(directory, filename)
14
+ if os.path.isfile(f):
15
+ allImages.append(f)
16
+
17
+ def flower_classifier(image):
18
+ print(image.shape)
19
+ image = tf.image.resize(image, (224, 224))
20
+ image = image / 255.0
21
+ image = tf.expand_dims(image, 0)
22
+ pred = np.argmax(model(image))
23
+ label = CLASSES[pred]
24
+ return label
25
+
26
+
27
+ iface = gr.Interface(flower_classifier,
28
+ title = "Image Classification using BigTransfer (BiT)",
29
+ inputs = gr.inputs.Image(),
30
+ outputs = gr.outputs.Label(num_top_classes=5),
31
+ capture_session=True,
32
+ examples = allImages,
33
+ )
34
+ iface.launch(debug=True)