Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import gradio.inputs | |
| import numpy as np # linear algebra | |
| import os #interacting with input and output directories | |
| import tensorflow as tf #framework for creating the neural network | |
| model = tf.keras.models.load_model(os.path.join(os.getcwd(), 'noteClassifierModel.h5')) | |
| def fn(img): | |
| img = np.expand_dims(img, axis = 0) | |
| pred = model.predict(img) | |
| pred = np.argmax(pred) | |
| num_to_note_dict = {0: 'india_10', 1: 'india_100', 2: 'india_20', | |
| 3: 'india_200', 4: 'india_2000', 5: 'india_50', | |
| 6: 'india_500', 7: 'thai_100', 8: 'thai_1000', | |
| 9: 'thai_20', 10: 'thai_50', 11:'thai_500'} | |
| text_pred = num_to_note_dict[pred] | |
| return text_pred | |
| description = "This interface can be used to classify Indian and Thai currency notes into their correct " \ | |
| "denominations. For eg. if you upload an image of a Rs. 10 note, the output should be 'india_10'" \ | |
| ", similarly a 500 Baht note will output 'thai_500'. So what are you waiting for, go ahead and " \ | |
| "test the NoteClassifier..." | |
| iface = gr.Interface(fn, | |
| inputs= gradio.inputs.Image(tool="select", label = "Note Image", shape=(224, 224)), | |
| outputs='text', | |
| title="Note Classifier", | |
| description=description, | |
| theme="dark-seafoam", | |
| allow_flagging="auto", | |
| flagging_dir='flagging records') | |
| iface.launch(inline=False, share = True) | |