Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import numpy as np | |
| import tensorflow as tf | |
| model = tf.keras.models.load_model('model.h5') | |
| def softmax(x): | |
| e_x = np.exp(x - np.max(x)) | |
| return e_x / e_x.sum() | |
| def temp(image): | |
| img = (image['composite']) | |
| img = np.expand_dims(img, axis=0).astype('float32') | |
| img = np.expand_dims(img, axis=3).astype('float32') | |
| y_pred = model.predict(img) | |
| prediction = {0:'অ', 1:'আ', 3:'ই', 4:'ঈ', 5:'উ', 6:'ঊ', 7:'ঋ', 8:'এ', 9:'ঐ', 10:'ও', 2:'ঔ'} | |
| for i in range(11): | |
| if np.argmax(softmax(y_pred[0])) == i: | |
| return prediction[i] | |
| iface = gr.Interface( | |
| title = 'স্বরবর্ণ Classifier', | |
| description = 'An experimental project to try handwritten bengali স্বরবর্ণ classification', | |
| thumbnail = 'thumb.png', | |
| article = 'There are 11 স্বরবর্ণ (SWARABARNA) in bengali alphabet system; just write any of them and it will predict: অ, আ, ই, ঈ, উ, ঊ, ঋ, এ, ঐ, ও, ঔ', | |
| theme = 'gstaff/whiteboard', | |
| fn = temp, | |
| inputs = gr.Sketchpad(crop_size=(28,28), type='numpy', image_mode='L', brush=gr.Brush()), | |
| outputs = gr.Label(label='predicted letter'), | |
| ) | |
| iface.launch() |