HMPhuoc commited on
Commit
b5d5483
·
1 Parent(s): 35374d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -16
app.py CHANGED
@@ -54,6 +54,18 @@ def GRU_predict(x):
54
 
55
  return pred_proba
56
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  def judge(x):
58
 
59
  label = ['độc hại', 'cực kì độc hại', 'tục tĩu', 'đe dọa', 'xúc phạm', 'thù ghét cá nhân']
@@ -63,20 +75,24 @@ def judge(x):
63
  lstm_pred = LSTM_predict(x)
64
  gru_pred = GRU_predict(x)
65
 
66
-
 
67
  return_result = 'Result'
68
  result_lstm = np.round(lstm_pred, 2)
69
  result_gru = np.round(gru_pred, 2)
70
- sensitive_result = max(max(result_lstm),max(result_gru))
 
71
 
72
- #print(sensitive_result)
 
 
73
  return_result += '\nMô hình LSTM\n'
74
  return_result += f"{result_lstm}\n"
75
  for i in range(6):
76
  if result_lstm[i]>=0 and result_lstm[i]<0.1:
77
  return_result += "Tính {} là không có\n".format(label[i])
78
  if result_lstm[i]>=0.1 and result_lstm[i]<0.5:
79
- return_result += "Tính {} ở mức nhận thấy được, từ ngữ có thể chưa phù hợp\n".format(label[i])
80
  if result_lstm[i]>=0.5 and result_lstm[i]<0.8:
81
  return_result += "Tính {} ở mức rõ ràng, cần xem xét\n".format(label[i])
82
  if result_lstm[i]>=0.8:
@@ -89,24 +105,39 @@ def judge(x):
89
  if result_gru[i]>=0 and result_gru[i]<0.1:
90
  return_result += "Tính {} là không có\n".format(label[i])
91
  if result_gru[i]>=0.1 and result_gru[i]<0.5:
92
- return_result += "Tính {} ở mức nhận thấy được, từ ngữ có thể chưa phù hợp\n".format(label[i])
93
  if result_gru[i]>=0.5 and result_gru[i]<0.8:
94
  return_result += "Tính {} ở mức rõ ràng, cần xem xét\n".format(label[i])
95
  if result_gru[i]>=0.8:
96
  return_result += "Tính {} ở mức nghiêm trọng, yêu cầu chấn chỉnh\n".format(label[i])
97
 
98
- return_result += "\nTổng quan:\n"
99
- if sensitive_result>=0 and sensitive_result<0.1:
100
- return_result += "Ngôn ngữ phù hợp mọi lứa tuổi.\n"
101
- if sensitive_result>=0.1 and sensitive_result<0.5:
102
- return_result += "Ngôn ngữ có thể còn chứa từ ngữ chưa phù hợp.\n"
103
- if sensitive_result>=0.5 and sensitive_result<0.8:
104
- return_result += "Ngôn ngữ không phù hợp, cần xem xét lại.\n"
105
- if sensitive_result>=0.8:
106
- return_result += "Ngôn ngữ vi phạm tiêu chuẩn cộng đồng nghiêm trọng, yêu cầu chấn chỉnh.\n"
107
 
108
- return return_result
 
 
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
 
111
  if __name__ == "__main__":
112
  # print("Loading")
@@ -117,5 +148,5 @@ if __name__ == "__main__":
117
  # judge(string)
118
  interface = gr.Interface(fn=judge,
119
  inputs=gr.Textbox(lines=2, placeholder='Please write something', label="Input Text"),
120
- outputs='text')
121
  interface.launch()
 
54
 
55
  return pred_proba
56
 
57
+ def plot(result):
58
+ label = ['độc hại', 'cực kì độc hại', 'tục tĩu', 'đe dọa', 'xúc phạm', 'thù ghét cá nhân']
59
+ data = pd.DataFrame()
60
+ data['Nhãn'] = label
61
+ data['Điểm'] = result
62
+
63
+ print(data)
64
+
65
+ p = px.bar(data, x='Nhãn', y='Điểm', color='Nhãn', range_y=[0, 1] )
66
+ return p
67
+ pass
68
+
69
  def judge(x):
70
 
71
  label = ['độc hại', 'cực kì độc hại', 'tục tĩu', 'đe dọa', 'xúc phạm', 'thù ghét cá nhân']
 
75
  lstm_pred = LSTM_predict(x)
76
  gru_pred = GRU_predict(x)
77
 
78
+ #print(result)
79
+
80
  return_result = 'Result'
81
  result_lstm = np.round(lstm_pred, 2)
82
  result_gru = np.round(gru_pred, 2)
83
+ for i in range(6):
84
+ result.append((result_lstm[i]+result_gru[i])/2)
85
 
86
+ final_result = np.round(result, 2)
87
+
88
+ #print(final_result)
89
  return_result += '\nMô hình LSTM\n'
90
  return_result += f"{result_lstm}\n"
91
  for i in range(6):
92
  if result_lstm[i]>=0 and result_lstm[i]<0.1:
93
  return_result += "Tính {} là không có\n".format(label[i])
94
  if result_lstm[i]>=0.1 and result_lstm[i]<0.5:
95
+ return_result += "Tính {} ở mức không ràng, không thể xác định chính xác\n".format(label[i])
96
  if result_lstm[i]>=0.5 and result_lstm[i]<0.8:
97
  return_result += "Tính {} ở mức rõ ràng, cần xem xét\n".format(label[i])
98
  if result_lstm[i]>=0.8:
 
105
  if result_gru[i]>=0 and result_gru[i]<0.1:
106
  return_result += "Tính {} là không có\n".format(label[i])
107
  if result_gru[i]>=0.1 and result_gru[i]<0.5:
108
+ return_result += "Tính {} ở mức không ràng, không thể xác định chính xác\n".format(label[i])
109
  if result_gru[i]>=0.5 and result_gru[i]<0.8:
110
  return_result += "Tính {} ở mức rõ ràng, cần xem xét\n".format(label[i])
111
  if result_gru[i]>=0.8:
112
  return_result += "Tính {} ở mức nghiêm trọng, yêu cầu chấn chỉnh\n".format(label[i])
113
 
 
 
 
 
 
 
 
 
 
114
 
115
+ another_result = ''
116
+ another_result += "\nTổng quan kết quả trung bình:\n"
117
+ another_result += f"{final_result}\n"
118
 
119
+ for i in range(6):
120
+ if final_result[i]>=0 and final_result[i]<0.1:
121
+ another_result += "Tính {} là không có\n".format(label[i])
122
+ if final_result[i]>=0.1 and final_result[i]<0.5:
123
+ another_result += "Tính {} ở mức không rõ ràng, không thể xác định chính xác\n".format(label[i])
124
+ if final_result[i]>=0.5 and final_result[i]<0.8:
125
+ another_result += "Tính {} ở mức rõ ràng, cần xem xét\n".format(label[i])
126
+ if final_result[i]>=0.8:
127
+ another_result += "Tính {} ở mức nghiêm trọng, yêu cầu chấn chỉnh\n".format(label[i])
128
+
129
+ another_result += "\nKết luận:\n"
130
+ if max(final_result)>=0 and max(final_result)<0.1:
131
+ another_result += "Ngôn ngữ phù hợp mọi lứa tuổi.\n"
132
+ if max(final_result)>=0.1 and max(final_result)<0.5:
133
+ another_result += "Ngôn ngữ cần được kiểm tra lại.\n"
134
+ if max(final_result)>=0.5 and max(final_result)<0.8:
135
+ another_result += "Ngôn ngữ không phù hợp, cần xem xét lại.\n"
136
+ if max(final_result)>=0.8:
137
+ another_result += "Ngôn ngữ vi phạm tiêu chuẩn cộng đồng nghiêm trọng, yêu cầu chấn chỉnh.\n"
138
+
139
+ p = plot(final_result)
140
+ return (return_result, another_result, p)
141
 
142
  if __name__ == "__main__":
143
  # print("Loading")
 
148
  # judge(string)
149
  interface = gr.Interface(fn=judge,
150
  inputs=gr.Textbox(lines=2, placeholder='Please write something', label="Input Text"),
151
+ outputs=['text','text','plot'])
152
  interface.launch()