Spaces:
Runtime error
Runtime error
File size: 1,662 Bytes
8eeb235 090a65b 8eeb235 090a65b 8eeb235 090a65b 8eeb235 090a65b 8eeb235 090a65b 8eeb235 090a65b 8eeb235 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | import gradio as gr
import os
from PIL import ImageOps
from torch.utils.benchmark import timer
example_list = [["examples/" + example] for example in os.listdir("examples")]
def processImage(img, text):
"""Transforms and performs a prediction on img and returns prediction and time taken.
"""
# Start the timer
start_time = timer()
inverted_img = ImageOps.invert(img)
text = "Hello" + text
pred_labels_and_probs = "Pred props"
# Calculate the prediction time
pred_time = round(timer() - start_time, 5)
# Return the prediction dictionary and prediction time
return inverted_img, pred_labels_and_probs, pred_time, text
# Create title, description and article strings
title = "FoodRecognition 🍕🥩🍣"
description = "An EfficientNetB2 model to classify images of food as pizza, steak or sushi."
article = "Created at my."
# Create the Gradio demo
demo = gr.Interface(fn=processImage, # mapping function from input to output
inputs=[gr.Image(type="pil"), gr.Textbox()],
outputs=[gr.Image(type="pil"), gr.Label(label="Process image"), # what are the outputs?
gr.Number(label="Prediction time (s)"), gr.Textbox(label="Result")],
# our fn has two outputs, therefore we have two outputs
# examples=example_list,
title=title,
description=description,
article=article,
examples=example_list)
# Launch the demo!
demo.launch(debug=False, # print errors locally?
share=True) # generate a publically shareable URL?
|