File size: 846 Bytes
3a58bce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr
import pickle
from keras.models import load_model

model = load_model("model.keras")
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=pwcheck, inputs=["text", "text"], outputs="text")
iface.launch()