Spaces:
Build error
Build error
| import tensorflow as tf | |
| import gradio as gr | |
| from pathlib import Path | |
| # model_v1 = tf.keras.models.load_model("models/v1.hdf5") | |
| # model_v2 = tf.keras.models.load_model("models/v2.hdf5") | |
| model_v3 = tf.keras.models.load_model("models/v3.hdf5") | |
| class_names=['Real', 'Fake'] | |
| def predict(image) -> str: | |
| image = image.resize((224, 224)) | |
| img = tf.keras.preprocessing.image.img_to_array(image) | |
| img = tf.expand_dims(img, axis=0) | |
| # y_pred_v1 = tf.round(model_v1.predict(img, verbose=0)[0]) | |
| # y_pred_v2 = tf.round(model_v2.predict(img, verbose=0)[0]) | |
| y_pred_v3 = tf.round(model_v3.predict(img, verbose=0)[0]) | |
| # return class_names[int(y_pred_v1)], class_names[int(y_pred_v2)], class_names[int(y_pred_v3)] | |
| return class_names[int(y_pred_v3)] | |
| TITLE = "Anti Spoof Detection (MUKHAM)" | |
| interface = gr.Interface(predict, | |
| inputs=gr.Image(source='upload', type='pil'), | |
| # outputs=[gr.Textbox(label="V1 Prediction [Acc: 0.970 | Loss: 0.100]"), | |
| # gr.Textbox(label="V2 Prediction [Acc: 0.985 | Loss: 0.039]"), | |
| # gr.Textbox(label="V3 Prediction [Acc: 0.997 | Loss: 0.005]")], | |
| outputs=[gr.Textbox(label="Model Prediction [Acc: 0.997 | Loss: 0.005]")], | |
| title=TITLE) | |
| # examples=[[i] for i in Path('/examples')]) | |
| interface.launch(debug=True) |