trainingGradio / app.py
Zhenya Datsok
comment
090a65b
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?