File size: 1,012 Bytes
284eba0 15f8afb 284eba0 15f8afb 284eba0 15f8afb 284eba0 15f8afb 284eba0 15f8afb |
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 36 37 38 39 40 41 42 43 44 45 46 47 |
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",
]
# a file
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()
|