|
from transformers import pipeline |
|
from PIL import Image |
|
import os |
|
import gradio as gr |
|
from timeit import default_timer as timer |
|
from typing import Tuple, Dict |
|
|
|
def predict(img) -> Tuple[Dict, float]: |
|
start_time = timer() |
|
classifier = pipeline("image-classification", model="bazyl/gtsrb-model") |
|
result = classifier(img, top_k=3) |
|
response = {result[i]["label"]: result[i]["score"] for i in range(len(result))} |
|
pred_time = round(timer() - start_time, 5) |
|
return response, pred_time |
|
|
|
title = "GTSRB - German Traffic Sign Recognition by Bazyl Horsey" |
|
description = "CNN created for the GTSRB Dataset, achieved 99.93% test accuracy" |
|
|
|
|
|
example_list = [["examples/" + example] for example in os.listdir("examples")] |
|
|
|
|
|
demo = gr.Interface( |
|
fn=predict, |
|
inputs=gr.Image(type="pil"), |
|
outputs=[ |
|
gr.Label(num_top_classes=3, label="Predictions"), |
|
gr.Number(label="Prediction time (s)"), |
|
], |
|
examples=example_list, |
|
title=title, |
|
description=description, |
|
) |
|
|
|
|
|
demo.launch() |