Spaces:
Running
Running
Commit
·
4d953a5
1
Parent(s):
fe11158
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
#from transformers import pipeline
|
3 |
+
from tensorflow.keras.models import load_model
|
4 |
+
|
5 |
+
#pipe = pipeline(task="image-classification", model="SuperSecureHuman/Flower-CNN")
|
6 |
+
|
7 |
+
model = load_model('./model.h5')
|
8 |
+
|
9 |
+
|
10 |
+
def predict_image(img):
|
11 |
+
img_4d = img.reshape(-1, 224, 224, 3)
|
12 |
+
prediction = model.predict(img_4d)[0]
|
13 |
+
return {class_names[i]: float(prediction[i]) for i in range(3)}
|
14 |
+
|
15 |
+
|
16 |
+
class_names = ['Crescentia_Cujete', 'Fiddle_Wood', 'Gold_Apple', 'Hill_Mango', 'Indian_Tulip_Tree', 'Mahagony', 'Pala_Indigo_Plant', 'Spanish_Cherry', 'Teak', 'Yellow_Trumpet']
|
17 |
+
|
18 |
+
image = gr.inputs.Image(shape=(224, 224))
|
19 |
+
|
20 |
+
label = gr.outputs.Label(num_top_classes=3)
|
21 |
+
|
22 |
+
gr.Interface(fn=predict_image,
|
23 |
+
title="Tree Classification",
|
24 |
+
description="Tree CNN",
|
25 |
+
inputs=image,
|
26 |
+
outputs=label,
|
27 |
+
live=True,
|
28 |
+
interpretation='default',
|
29 |
+
allow_flagging="never").launch()
|