File size: 1,752 Bytes
3ac7250
 
c970970
3ac7250
 
 
 
c970970
3ac7250
 
 
 
 
 
 
 
 
c970970
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4809d91
 
 
 
c970970
 
 
 
 
 
4809d91
c970970
3ac7250
4809d91
 
3ac7250
c970970
 
 
 
 
 
 
 
 
4809d91
c970970
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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 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)

    predicted = results.pandas().xyxy[0]["name"]

    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(
    """
    <h1 align="center">Group 29 - AI Cafeteria Price Evaluator</h1>
    """)
    examples = ["./examples/img_1.jpg", "./examples/img_2.jpg", "./examples/img_3.jpg", "./examples/img_4.jpg"]
    # gr.Interface(inputs=["image"],outputs=["image"],fn=lambda img:model(img).render()[0]).launch()
    gr.Interface(inputs=["image"], outputs=["image", "text"], fn=predict, examples=examples)

if __name__ == "__main__":
    demo.launch()