import gradio as gr import pickle from keras.models import load_model from keras_self_attention import SeqSelfAttention import numpy as np model = load_model("model.keras", custom_objects={"SeqSelfAttention": SeqSelfAttention}) with open("tokenizer.pckl", "rb") as file: tokenizer = pickle.load(file) l1, l2 = 10, 10 def classify(text: str, response: str): question = list(tokenizer.texts_to_sequences([text.lower(),])[0]) answer = list(tokenizer.texts_to_sequences([response.lower(),])[0]) arr = np.array([(list(question)+[0,]*l1)[:l1]+(list(answer)+[0,]*l2)[:l2],]) prediction = model.predict(arr)[0][0] if prediction > 0.9: return "Surely relevant "+str(prediction) elif prediction > 0.5: return "Relevant "+str(prediction) elif prediction > 0.1: return "Probably relevant "+str(prediction) else: return "Irrelevant "+str(prediction) iface = gr.Interface(fn=classify, inputs=["text", "text"], outputs="text") iface.launch()