Spaces:
Sleeping
Sleeping
File size: 825 Bytes
c5df11c |
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 tensorflow as tf
import joblib
import pickle
from tensorflow.keras.preprocessing.sequence import pad_sequences
# Load your model and tokenizer
model = tf.keras.models.load_model('lstm_model.h5')
tokenizer = joblib.load('tokenizer.pkl')
with open('padding_config.pkl', 'rb') as file:
padding_config = pickle.load(file)
# Preprocessing function
def preprocess(text):
tokenized_text = tokenizer.texts_to_sequences([text])
padded_text = pad_sequences(tokenized_text, **padding_config)
return padded_text
# Prediction function
def predict(text):
processed_text = preprocess(text)
prediction = model.predict(processed_text)
return prediction.tolist()
# Gradio interface
iface = gr.Interface(fn=predict, inputs="text", outputs="json")
# Launch Gradio app
iface.launch()
|