SimpleDemo / app.py
desankha's picture
model file and custom_classes added , app and requirements files updated
dc7bcbb
Raw
History Blame Contribute Delete
949 Bytes
# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import gradio as gr
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import layers
from tensorflow.keras.layers import TextVectorization, Embedding, Dense
from custom_classes import TransformerEncoder, PositionalEmbedding
model = keras.models.load_model(
"full_transformer_encoder.keras",
custom_objects={"TransformerEncoder": TransformerEncoder,
"PositionalEmbedding": PositionalEmbedding})
def make_prediction(input_text):
myTensor = tf.convert_to_tensor(input_text, dtype=tf.string)
pred = model(tf.reshape(myTensor, (-1,1)))
label_index = int(pred.numpy()[0,0] + 0.5)
mapping = {0: 'Negative', 1: 'Positive'}
label = mapping[label_index]
return label
#Create the Gradio demo
demo = gr.Interface(fn=make_prediction,
inputs="text",
outputs="text",
title="Text Classification",
description="built via gradio")
demo.launch()