from hubconf import custom model = custom(path_or_model='best.pt') # custom example model.eval() # model = create(name='yolov7', pretrained=True, channels=3, classes=80, autoshape=True) # pretrained example # Verify inference import numpy as np import torch from PIL import Image import gradio as gr # imgs = [np.zeros((640, 480, 3))] # imgs = 'inference/images/meal.jpg' # results = model(imgs) # batched inference # results.print() # results.save() def total_price(predicted): price = 0 for name, confidence in predicted: if name == "side dish": price += 10 elif name == "purple rice" or name == "white rice" or name == "brown rice": price += 20 elif name == "40dollars meal": price += 40 elif name == "30dollars meal": price += 30 elif name == "25dollars meal": price += 25 return price def predict(input_image): """ Predict model output """ # Disable gradient computation with torch.no_grad(): results = model(input_image) results_pd = results.pandas().xyxy[0] name, confidence = results_pd["name"], results_pd["confidence"] predicted = list(zip(name, confidence)) output_image = results.render()[0] price = total_price(predicted) # Return the output image and price return [output_image, price] with gr.Blocks() as demo: # Title gr.HTML( """
Menu | Price |
---|---|
White/Brown/Purple Rice | 20 |
Side Dish | 10 |
25 Dollar Meal | 25 |
30 Dollar Meal | 30 |
40 Dollar Meal | 40 |