ierhon's picture
Update app.py
d70fed0
raw
history blame
951 Bytes
import gradio as gr
import pickle
from keras.models import load_model
from keras_self_attention import SeqSelfAttention
model = load_model("model.keras", custom_objects={"SeqSelfAttention":SeqSelfAttention})
with open("tokenizer.pckl", "rb") as file:
tokenizer = pickle.load(file)
def classify(text: str, response: str):
question = list(tokenizer.texts_to_sequences([q.lower(),])[0])
answer = list(tokenizer.texts_to_sequences([a.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()