jsolow commited on
Commit
56c8e47
1 Parent(s): 7585ee7

Add processing

Browse files
Files changed (1) hide show
  1. app.py +27 -1
app.py CHANGED
@@ -1,3 +1,29 @@
1
  import gradio as gr
 
 
2
 
3
- gr.Interface.load("models/jsolow/grubguesser").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()