core4testing / app.py
walter1's picture
Update app.py
cf907ed
raw
history blame
805 Bytes
import gradio as gr
import tensorflow as tf
import numpy as np
import pickle
# Load model, including its weights and the optimizer
model = tf.keras.models.load_model('core4.h5')
# load tokenizer
with open('tokenizer.pickle', 'rb') as handle:
tokenize = pickle.load(handle)
text_labels = ['How to apply', 'how much can I get', 'who can apply']
# model.summary() # model architecture
def greet(string):
tokenizedText = tokenize.texts_to_matrix([string])
prediction = model.predict(np.array([tokenizedText[0]]))
predicted_label = text_labels[np.argmax(prediction)]
print(prediction[0][np.argmax(prediction)])
print("Predicted label: " + predicted_label + "\n")
return predicted_label
#One testing case
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
iface.launch()