Spaces:
Runtime error
Runtime error
Add processing
Browse files
app.py
CHANGED
|
@@ -1,3 +1,29 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from huggingface_hub import from_pretrained_keras
|
| 3 |
+
from tensorflow.keras.preprocessing.image import array_to_img, img_to_array
|
| 4 |
|
| 5 |
+
from .labels import CLASS_LABELS
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
model = from_pretrained_keras("jsolow/grubguesser")
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def _preprocess(imgage_input):
|
| 12 |
+
img = array_to_img(imgage_input, scale=False)
|
| 13 |
+
img = img.resize((224, 224))
|
| 14 |
+
img = img_to_array(img)
|
| 15 |
+
return img / 255.0
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def predict(image):
|
| 19 |
+
image_array = _preprocess(image)
|
| 20 |
+
predictions = model.predict(image_array)
|
| 21 |
+
return {k:v for k, v in zip(CLASS_LABELS, predictions)}
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
gr.Interface(
|
| 25 |
+
predict,
|
| 26 |
+
inputs=gr.inputs.Image(label="Upload food image", type="filepath"),
|
| 27 |
+
outputs=gr.outputs.Label(num_top_classes=10),
|
| 28 |
+
title="Grubguesser - What is this food?",
|
| 29 |
+
).launch()
|