Spaces:
Runtime error
Runtime error
''' | |
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() |