Spaces:
Build error
Build error
import tensorflow as tf | |
from tensorflow.keras.preprocessing import image | |
import matplotlib.pyplot as plt | |
from keras.models import load_model | |
import numpy as np | |
#import json | |
def load_image(img): | |
img_tensor = image.img_to_array(img) | |
img_tensor = np.expand_dims(img_tensor, axis=0) | |
img_tensor /= 255 | |
return img_tensor | |
def run_model(img): | |
model = load_model("res.h5") | |
new_image = load_image(img) | |
classes = ['1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'] | |
img = img.reshape((-1, 224, 224, 3)) | |
result = model.predict(img) | |
results = dict(zip(classes, result[0])) | |
return max(results, key = results.get) | |
#return json.dumps(str(results)) | |
title = "Indian Sign Language Classifier" | |
description = "<p style='text-align: center'>Classifies images from 0-9, A-Z made using Indian Sign Language" | |
examples = ['5.jpg','9.jpg','A.jpg','L.jpg','P.jpg'] | |
import gradio as gr | |
gr.Interface(fn=run_model, inputs=gr.inputs.Image(shape=(224,224)), outputs=gr.outputs.Label(num_top_classes=35), title=title, description=description, examples=examples).launch() | |