Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -36,7 +36,7 @@ def predict_top_classes(img, model_name):
|
|
36 |
temp = model.predict(x)
|
37 |
|
38 |
idx = np.argsort(np.squeeze(temp))[::-1]
|
39 |
-
top5_value = np.asarray([temp[0][i] for i in idx[0:5]
|
40 |
top5_idx = idx[0:5]
|
41 |
|
42 |
return {CLASS_LABEL[i]: str(v) for i, v in zip(top5_idx, top5_value)}
|
@@ -48,16 +48,22 @@ models = {
|
|
48 |
"DenseNet201": 4
|
49 |
}
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
interface = gr.Interface(
|
52 |
-
|
53 |
-
[
|
54 |
-
gr.inputs.Image(type='pil'),
|
55 |
-
gr.Dropdown(
|
56 |
-
choices=list(models.keys()),
|
57 |
-
value=1,
|
58 |
-
label="Select a model"
|
59 |
-
)
|
60 |
-
],
|
61 |
outputs='label'
|
62 |
)
|
63 |
-
|
|
|
|
36 |
temp = model.predict(x)
|
37 |
|
38 |
idx = np.argsort(np.squeeze(temp))[::-1]
|
39 |
+
top5_value = np.asarray([temp[0][i] for i in idx[0:5])
|
40 |
top5_idx = idx[0:5]
|
41 |
|
42 |
return {CLASS_LABEL[i]: str(v) for i, v in zip(top5_idx, top5_value)}
|
|
|
48 |
"DenseNet201": 4
|
49 |
}
|
50 |
|
51 |
+
def dropdown_example(choice, img):
|
52 |
+
model_name = models[choice]
|
53 |
+
return predict_top_classes(img, model_name)
|
54 |
+
|
55 |
+
dropdown = gr.inputs.Dropdown(
|
56 |
+
choices=list(models.keys()),
|
57 |
+
type="str",
|
58 |
+
label="Select a model"
|
59 |
+
)
|
60 |
+
|
61 |
+
image_input = gr.inputs.Image(type='pil')
|
62 |
+
|
63 |
interface = gr.Interface(
|
64 |
+
fn=dropdown_example,
|
65 |
+
inputs=[dropdown, image_input],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
outputs='label'
|
67 |
)
|
68 |
+
|
69 |
+
interface.launch()
|