Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,69 +1,41 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
-
|
| 4 |
-
import
|
| 5 |
-
import json
|
| 6 |
|
| 7 |
-
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
"mobilenet_v2"
|
| 13 |
-
]
|
| 14 |
-
|
| 15 |
-
colname = "mobilenet_v2"
|
| 16 |
-
|
| 17 |
-
radio = gr.inputs.Radio(models_name, default="mobilenet_v2", type="value", label=colname)
|
| 18 |
-
print(radio.label)
|
| 19 |
-
|
| 20 |
-
def predict_image(image, model_name):
|
| 21 |
-
|
| 22 |
-
image = Image.fromarray(np.uint8(image)).convert('RGB')
|
| 23 |
|
| 24 |
-
|
| 25 |
-
print(type(image))
|
| 26 |
-
print(type(model_name))
|
| 27 |
-
print("==========")
|
| 28 |
-
print(image)
|
| 29 |
-
print(model_name)
|
| 30 |
-
print("======================")
|
| 31 |
|
| 32 |
-
# image = np.array(image) / 255
|
| 33 |
-
# image = np.expand_dims(image, axis=0)
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
)
|
| 38 |
|
| 39 |
-
pred =
|
| 40 |
-
print(pred)
|
| 41 |
|
| 42 |
-
acc = dict((labels[i], 0
|
| 43 |
-
acc[pred] = 100.0
|
| 44 |
print(acc)
|
| 45 |
return acc
|
| 46 |
-
# return pred
|
| 47 |
|
| 48 |
-
# open categories.txt in read mode
|
| 49 |
-
categories = open("categories.txt", "r")
|
| 50 |
-
labels = categories.readline().split(";")
|
| 51 |
|
| 52 |
-
image = gr.inputs.Image(shape=(
|
| 53 |
-
print(image)
|
| 54 |
label = gr.outputs.Label(num_top_classes=len(labels))
|
| 55 |
|
| 56 |
-
samples = ['
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
# './samples/tigre.jpg', './samples/whale.jpg', './samples/white.jpg', './samples/whitetip.jpg']
|
| 60 |
|
| 61 |
interface = gr.Interface(
|
| 62 |
fn=predict_image,
|
| 63 |
-
inputs=
|
| 64 |
outputs=label,
|
| 65 |
capture_session=True,
|
| 66 |
allow_flagging=False,
|
| 67 |
-
|
| 68 |
)
|
| 69 |
interface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import numpy as np
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from tensorflow.keras import models
|
|
|
|
| 5 |
|
| 6 |
+
import tensorflow as tf
|
| 7 |
|
| 8 |
+
# open categories.txt in read mode
|
| 9 |
+
categories = open("categories.txt", "r")
|
| 10 |
+
labels = categories.readline().split(";")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
+
model = models.load_model('models/modelnet/best_model.h5')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
def predict_image(image):
|
| 16 |
+
image = np.array(image) / 255
|
| 17 |
+
image = np.expand_dims(image, axis=0)
|
| 18 |
|
| 19 |
+
pred = model.predict(image)
|
|
|
|
| 20 |
|
| 21 |
+
acc = dict((labels[i], "%.2f" % pred[0][i]) for i in range(len(labels)))
|
|
|
|
| 22 |
print(acc)
|
| 23 |
return acc
|
|
|
|
| 24 |
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
image = gr.inputs.Image(shape=(224, 224), label="Upload Your Image Here")
|
|
|
|
| 27 |
label = gr.outputs.Label(num_top_classes=len(labels))
|
| 28 |
|
| 29 |
+
samples = ['samples/basking.jpg', 'samples/blacktip.jpg', 'samples/blue.jpg', 'samples/bull.jpg', 'samples/hammerhead.jpg',
|
| 30 |
+
'samples/lemon.jpg', 'samples/mako.jpg', 'samples/nurse.jpg', 'samples/sand tiger.jpg', 'samples/thresher.jpg',
|
| 31 |
+
'samples/tigre.jpg', 'samples/whale.jpg', 'samples/white.jpg', 'samples/whitetip.jpg']
|
|
|
|
| 32 |
|
| 33 |
interface = gr.Interface(
|
| 34 |
fn=predict_image,
|
| 35 |
+
inputs=image,
|
| 36 |
outputs=label,
|
| 37 |
capture_session=True,
|
| 38 |
allow_flagging=False,
|
| 39 |
+
examples=samples
|
| 40 |
)
|
| 41 |
interface.launch()
|