Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pickle
|
3 |
+
from keras.models import load_model
|
4 |
+
|
5 |
+
model = load_model("model.keras")
|
6 |
+
with open("tokenizer.pckl", "rb") as file:
|
7 |
+
tokenizer = pickle.load(file)
|
8 |
+
|
9 |
+
def classify(text: str, response: str):
|
10 |
+
question = list(tokenizer.texts_to_sequences([q.lower(),])[0])
|
11 |
+
answer = list(tokenizer.texts_to_sequences([a.lower(),])[0])
|
12 |
+
arr = np.array([(list(question)+[0,]*l1)[:l1]+(list(answer)+[0,]*l2)[:l2],])
|
13 |
+
prediction = model.predict(arr)[0][0]
|
14 |
+
if prediction > 0.9:
|
15 |
+
return "Surely relevant "+str(prediction)
|
16 |
+
elif prediction > 0.5:
|
17 |
+
return "Relevant "+str(prediction)
|
18 |
+
elif prediction > 0.1:
|
19 |
+
return "Probably relevant "+str(prediction)
|
20 |
+
else:
|
21 |
+
return "Irrelevant "+str(prediction)
|
22 |
+
|
23 |
+
iface = gr.Interface(fn=pwcheck, inputs=["text", "text"], outputs="text")
|
24 |
+
iface.launch()
|