Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
from huggingface_hub import from_pretrained_keras
|
| 4 |
+
import tensorflow as tf
|
| 5 |
+
|
| 6 |
+
model = from_pretrained_keras("rushic24/bit")
|
| 7 |
+
allImages = []
|
| 8 |
+
directory = 'images'
|
| 9 |
+
CLASSES = ['daisy', 'dandelion', 'roses', 'sunflowers', 'tulips']
|
| 10 |
+
# iterate over files in images directory
|
| 11 |
+
for filename in os.listdir(directory):
|
| 12 |
+
f = os.path.join(directory, filename)
|
| 13 |
+
if os.path.isfile(f):
|
| 14 |
+
allImages.append(f)
|
| 15 |
+
|
| 16 |
+
def flower_classifier(image):
|
| 17 |
+
image = tf.image.resize(image, (224, 224))
|
| 18 |
+
image = image / 255.0
|
| 19 |
+
image = tf.expand_dims(image, 0)
|
| 20 |
+
pred = model(image)
|
| 21 |
+
labeldict = dict(zip([CLASSES[i] for i in range(len(pred))], pred))
|
| 22 |
+
return labeldict
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
iface = gr.Interface(flower_classifier,
|
| 26 |
+
title = "Award-Winning Deep Learning Project",
|
| 27 |
+
examples = allImages,
|
| 28 |
+
inputs = gr.inputs.Image(),
|
| 29 |
+
outputs = gr.outputs.Label(num_top_classes=5),
|
| 30 |
+
capture_session=True)
|
| 31 |
+
iface.launch(debug=True)
|