File size: 988 Bytes
3a58bce
 
 
7fb5ad9
8e0e6a5
3a58bce
4f935c4
 
0f63582
4f935c4
3a58bce
 
 
 
8256bee
 
48c2a8e
3a58bce
 
 
 
 
 
 
 
 
 
d70fed0
4f935c4
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
import gradio as gr
import pickle
from keras.models import load_model
from keras_self_attention import SeqSelfAttention
import numpy as np


l1, l2 = 10, 10
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([text.lower(),])[0])
    answer = list(tokenizer.texts_to_sequences([response.lower(),])[0])
    arr = np.array([(question+[0,]*l1)[:l1]+(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()