|
import gradio as gr |
|
from PIL import Image |
|
import numpy as np |
|
from tensorflow.keras.preprocessing import image as keras_image |
|
from tensorflow.keras.applications.inception_v3 import preprocess_input |
|
from tensorflow.keras.models import load_model |
|
|
|
|
|
model = load_model('/home/user/app/one_piece_character_classifier.h5') |
|
|
|
def predict_character(img): |
|
img = Image.fromarray(img.astype('uint8'), 'RGB') |
|
img = img.resize((299, 299)) |
|
img_array = keras_image.img_to_array(img) |
|
img_array = np.expand_dims(img_array, axis=0) |
|
img_array = preprocess_input(img_array) |
|
|
|
prediction = model.predict(img_array) |
|
classes = ['Brook', 'Chopper', 'Zoro'] |
|
return {classes[i]: float(prediction[0][i]) for i in range(3)} |
|
|
|
|
|
interface = gr.Interface(fn=predict_character, |
|
inputs="image", |
|
outputs="label", |
|
title="One Piece Classifier", |
|
description="Lade ein Bild eines OP-Charakters hoch und der Klassifikator wird den Namen vorhersagen.") |
|
|
|
|
|
interface.launch() |