Spaces:
Runtime error
Runtime error
Omar Sanseviero
commited on
Commit
·
a2b9d3d
1
Parent(s):
24acd87
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow.compat.v2 as tf
|
| 2 |
+
import tensorflow_hub as hub
|
| 3 |
+
import numpy as np
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import cv2
|
| 6 |
+
from skimage import io
|
| 7 |
+
|
| 8 |
+
m = hub.KerasLayer('https://tfhub.dev/google/aiy/vision/classifier/food_V1/1')
|
| 9 |
+
|
| 10 |
+
labelmap_url = "https://www.gstatic.com/aihub/tfhub/labelmaps/aiy_food_V1_labelmap.csv"
|
| 11 |
+
input_shape = (224, 224)
|
| 12 |
+
|
| 13 |
+
def classify_image(inp):
|
| 14 |
+
inp = inp.reshape((-1, 224, 224, 3))
|
| 15 |
+
output = m(images)
|
| 16 |
+
predicted_index = output.numpy().argmax()
|
| 17 |
+
classes = list(pd.read_csv(labelmap_url)["name"])
|
| 18 |
+
return {labels[i]: float(prediction[i]) for i in range(1000)}
|
| 19 |
+
|
| 20 |
+
image = gr.inputs.Image(shape=(224, 224))
|
| 21 |
+
label = gr.outputs.Label(num_top_classes=3)
|
| 22 |
+
|
| 23 |
+
gr.Interface(
|
| 24 |
+
fn=classify_image,
|
| 25 |
+
inputs=image,
|
| 26 |
+
outputs=label,
|
| 27 |
+
examples=[["isachertorte.png"], ["sandwich.jpg"]],
|
| 28 |
+
).launch()
|