Spaces:
Runtime error
Runtime error
Subhranil Sarkar
commited on
Commit
·
fad8c25
1
Parent(s):
e5fbe15
Add application files
Browse files
28.jpg
ADDED
![]() |
57.jpg
ADDED
![]() |
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
import tensorflow as tf
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
|
7 |
+
MODEL = tf.keras.models.load_model("my_model")
|
8 |
+
CLASS_NAMES = ['circle', 'rectangle']
|
9 |
+
|
10 |
+
|
11 |
+
def classify_predict(inp):
|
12 |
+
image = inp
|
13 |
+
image_batch = np.expand_dims(image, 0)
|
14 |
+
predictions = MODEL.predict(image_batch)
|
15 |
+
values, indices = tf.math.top_k(predictions, 2)
|
16 |
+
predicted_values = values.numpy().tolist()[0]
|
17 |
+
indcs = indices.numpy().tolist()[0]
|
18 |
+
confidences = {CLASS_NAMES[i]: round(v, 4) for i, v in zip(indcs, predicted_values)}
|
19 |
+
print(confidences)
|
20 |
+
return confidences
|
21 |
+
|
22 |
+
|
23 |
+
interface = gr.Interface(
|
24 |
+
fn=classify_predict,
|
25 |
+
inputs=gr.inputs.Image(shape=(64, 64)),
|
26 |
+
outputs="label",
|
27 |
+
examples=["28.jpg", "57.jpg"]
|
28 |
+
)
|
29 |
+
|
30 |
+
interface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
tensorflow
|
2 |
+
numpy
|