import tarfile import gradio as gr from huggingface_hub import hf_hub_download from tensorflow.keras.models import load_model from tensorflow.keras.applications import resnet50 def load_model(tar_file: str='model.tar.gz'): tar_file = tarfile.open(tar_file) tar_file.extractall('./') tar_file.close() model_path = './model' return load_model(model_path) hf_hub_download(repo_id='chansung/', filename='outputs/model.tar.gz') model = load_model() labels = ['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck'] def classify_image(inp): inp = inp.reshape((-1, 224, 224, 3)) inp = resnet50.preprocess_input(inp) prediction = model.predict(inp).flatten() confidences = {labels[i]: float(prediction[i]) for i in range(1000)} return confidences gr.Interface(fn=classify_image, inputs=gr.inputs.Image(shape=(224, 224)), outputs=gr.outputs.Label(num_top_classes=3), examples=["banana.jpg", "car.jpg"]).launch()