amrutha2912's picture
Update app.py
629a599
raw
history blame contribute delete
No virus
1.22 kB
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("inc.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, 299, 299, 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 = ['6.jpg','q.jpg','c.jpg','3.jpg','n.jpg']
import gradio as gr
gr.Interface(fn=run_model, inputs=gr.inputs.Image(shape=(299,299)), outputs=gr.outputs.Label(num_top_classes=35), title=title, description=description, examples=examples).launch()