Spaces:
Runtime error
Runtime error
Commit
·
04a46c5
1
Parent(s):
868feef
Minor changes
Browse files
app.py
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
import os
|
3 |
-
from nltk.corpus import stopwords
|
4 |
|
5 |
os.system("cp -r ./nltk_data/ /home/user/nltk_data")
|
6 |
|
7 |
def analyze(text):
|
8 |
-
|
9 |
return text
|
10 |
|
11 |
app = gr.Interface(fn=analyze, inputs="text", outputs="text")
|
|
|
1 |
import gradio as gr
|
2 |
+
from model import CustomModel
|
3 |
import os
|
|
|
4 |
|
5 |
os.system("cp -r ./nltk_data/ /home/user/nltk_data")
|
6 |
|
7 |
def analyze(text):
|
8 |
+
model = CustomModel()
|
9 |
return text
|
10 |
|
11 |
app = gr.Interface(fn=analyze, inputs="text", outputs="text")
|
model.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
class CustomModel:
|
2 |
+
|
3 |
+
def __init__(self):
|
4 |
+
self.attr_1_model = pickle.load(open("models/cog_model.pkl", "rb"))
|
5 |
+
self.attr_2_model = pickle.load(open("models/eff_model.pkl", "rb"))
|
6 |
+
self.attr_3_model = pickle.load(open("models/reas_model.pkl", "rb"))
|
7 |
+
self.arg_model = pickle.load(open("models/qual_model.pkl", "rb"))
|
8 |
+
|
9 |
+
def predict(self, array):
|
10 |
+
attr_1 = self.attr_1_model.predict(array, verbose=0)
|
11 |
+
attr_2 = self.attr_2_model.predict(array, verbose=0)
|
12 |
+
attr_3 = self.attr_3_model.predict(array, verbose=0)
|
13 |
+
attr_1 = self.__decode(attr_1)
|
14 |
+
attr_2 = self.__decode(attr_2)
|
15 |
+
attr_3 = self.__decode(attr_3)
|
16 |
+
array = self.__transform(attr_1, attr_2, attr_3, array)
|
17 |
+
pred = self.arg_model.predict(array)
|
18 |
+
return pred
|
19 |
+
|
20 |
+
def __decode(self, array):
|
21 |
+
new_array = []
|
22 |
+
label_map = {
|
23 |
+
0: "1 (Low)",
|
24 |
+
1: "2 (Average)",
|
25 |
+
2: "3 (High)",
|
26 |
+
}
|
27 |
+
for ele in array:
|
28 |
+
new_array.append(label_map[np.argmax(ele)])
|
29 |
+
return np.array(new_array)
|
30 |
+
|
31 |
+
def __transform(self, attr_1, attr_2, attr_3, array):
|
32 |
+
attr_1 = self.__encode(attr_1)
|
33 |
+
attr_2 = self.__encode(attr_2)
|
34 |
+
attr_3 = self.__encode(attr_3)
|
35 |
+
array_new = []
|
36 |
+
for idx, ele in enumerate(array):
|
37 |
+
temp = np.concatenate((attr_1[idx], attr_2[idx], attr_3[idx], ele))
|
38 |
+
array_new.append(temp)
|
39 |
+
array = np.array(array_new)
|
40 |
+
return array
|
41 |
+
|
42 |
+
def __encode(self, array):
|
43 |
+
new_array = []
|
44 |
+
label_map = {
|
45 |
+
"1 (Low)": np.array([0, 0, 1]),
|
46 |
+
"2 (Average)": np.array([0, 1, 0]),
|
47 |
+
"3 (High)": np.array([1, 0, 0]),
|
48 |
+
}
|
49 |
+
for ele in array:
|
50 |
+
new_array.append(label_map[ele])
|
51 |
+
return np.array(new_array)
|