File size: 1,220 Bytes
772ff82
 
 
 
f1c89f5
b87e2f7
a655577
 
 
 
b87e2f7
0e87e15
 
 
 
b87e2f7
 
a655577
b87e2f7
 
 
186f56a
72a880a
186f56a
9128e25
186f56a
 
12668ff
186f56a
b87e2f7
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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()