File size: 1,011 Bytes
d1fc7e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import gradio as gr
import os
from huggingface_hub import from_pretrained_keras
import tensorflow as tf

model = from_pretrained_keras("rushic24/bit")
allImages = []
directory = 'images'
CLASSES = ['daisy', 'dandelion', 'roses', 'sunflowers', 'tulips']
# iterate over files in images directory
for filename in os.listdir(directory):
    f = os.path.join(directory, filename)
    if os.path.isfile(f):
      allImages.append(f)

def flower_classifier(image):
  image = tf.image.resize(image, (224, 224))
  image = image / 255.0
  image = tf.expand_dims(image, 0)
  pred =  model(image)
  labeldict = dict(zip([CLASSES[i] for i in range(len(pred))], pred))
  return labeldict


iface = gr.Interface(flower_classifier,
                     title = "Award-Winning Deep Learning Project",
                     examples = allImages,
                     inputs = gr.inputs.Image(),
                     outputs = gr.outputs.Label(num_top_classes=5),
                     capture_session=True)
iface.launch(debug=True)