Spaces:
Sleeping
Sleeping
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() | |