|
import gradio as gr |
|
import tensorflow as tf |
|
import numpy as np |
|
import gdown |
|
from PIL import Image |
|
|
|
|
|
labels = [ |
|
"plane", |
|
"car", |
|
"bird", |
|
"cat", |
|
"deer", |
|
"dog", |
|
"frog", |
|
"horse", |
|
"ship", |
|
"truck", |
|
] |
|
|
|
|
|
url = "https://drive.google.com/uc?id=12700bE-pomYKoVQ214VrpBoJ7akXcTpL" |
|
output = "modelV2Lmixed.keras" |
|
gdown.download(url, output, quiet=False) |
|
|
|
inception_net = tf.keras.models.load_model("./modelV2Lmixed.keras") |
|
|
|
|
|
def classify_image(inp): |
|
inp = inp.reshape((-1, 224, 224, 3)) |
|
inp = tf.keras.applications.efficientnet.preprocess_input(inp) |
|
prediction = inception_net.predict(inp).flatten() |
|
confidences = {labels[i]: float(prediction[i]) for i in range(10)} |
|
return confidences |
|
|
|
|
|
import gradio as gr |
|
|
|
gr.Interface( |
|
fn=classify_image, |
|
inputs=gr.inputs.Image(shape=(32, 32)), |
|
outputs=gr.outputs.Label(num_top_classes=3), |
|
examples=["03_cat.jpg", "05_dog.jpg"], |
|
theme="default", |
|
css=".footer{display:none !important}", |
|
).launch() |
|
|