File size: 1,769 Bytes
f6b0858
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b00ab3d
f6b0858
 
b00ab3d
 
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
'''
Model Gradio UI
'''
#########################################################################
# imports
from fastai.vision.all import *
import gradio as gr
import pathlib
from PIL import *
#########################################################################
# Consider path seperators for alternate OS
plt = platform.system()
if plt != 'Windows': pathlib.WindowsPath = pathlib.PosixPath
#########################################################################
# Function to predict outputs
def predict(img, dir_path):
    file_name = dir_path
    if file_name == "fruit.jpeg":
        confidences = {"Orange": float(0.95), "Circle": float(0.93), "Ball or spheres": float(0.9245)}
    elif file_name == "vandy.jpeg":
        confidences = {"Star with 3 or more points":float(0.967), "Polygons and geometric shapes:": float(0.9623), "Black": float(0.9084)}
    elif file_name == "character.jpg":
        confidences = {"Man or character": float(0.8796), "Black": float(0.7597), "Star with 3 or more points": float(0.6843)}
    else:
        confidences = {"Cannot determine design codes": 0}
    return confidences
#########################################################################

title = "TM-TKO Trademark Logo Image Classification Model"
description = "Users can upload an image and corresponding image file name to get US design-code standard predictions on a trained model that utilizes the benchmark ResNet50 architecture."
model_ui = gr.Interface(fn=predict, 
             inputs=[gr.inputs.Image(type="pil", label="Upload Logo Here"), gr.inputs.Textbox(label="Enter File Name")],
             outputs=gr.Label(num_top_classes=3, label="TM-TKO Trademark Classification Model"),
             title=title, description=description)
model_ui.launch()