s1ri1337's picture
Create app.py
343b998
raw
history blame
1.24 kB
import tensorflow as tf
from tensorflow.keras.preprocessing import image
import matplotlib.pyplot as plt
from keras.models import load_model
def load_image(img_path, show=False):
img = image.load_img(img_path, target_size=(224, 224))
img_tensor = image.img_to_array(img)
img_tensor = np.expand_dims(img_tensor, axis=0)
img_tensor /= 255
if show:
plt.imshow(img_tensor[0])
plt.axis('off')
plt.show()
return img_tensor
def run_model(img):
model = load_model("res.h5")
#img_path = '/content/Indian/9/1020.jpg'
#new_image = load_image(img_path)
#result = model.predict(new_image)
result = model.predict(img)
results = dict(zip(classes, result[0]))
return max(results, key = results.get)
title = "Indian Sign Language Classifier"
description = "<p style='text-align: center'>Classifies images from 0-9, A-Z made using Indian Sign Language"
examples = ['ex1.jpg','ex2.jpg','ex3.jpg','ex4.jpg','ex5.jpg','ex6.jpg','ex7.jpg','ex8.jpg','ex9.jpg','ex10.jpg']
import gradio as gr
gr.Interface(fn=run_model, inputs=gr.inputs.Image(shape=(224, 224)), outputs='text', title=title, description=description, examples=examples).launch()