Cricles commited on
Commit
8808739
·
verified ·
1 Parent(s): 5bafffa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -15
app.py CHANGED
@@ -72,29 +72,46 @@ user_input = st.text_area('',height=200)
72
 
73
  model_type = st.radio(
74
  "Выберите модель",
75
- ("fasttext", "ru-BERT")
76
  )
77
 
78
  def highlight_obscene_words(text, model_type):
79
- label, prob=model_wrapper(text.lower(),model_type)
80
- if label=='__label__positive':
81
- st.markdown(
82
- "<span style='background:#47916B;'>{}:приемлемо</span>".format(text),
83
- unsafe_allow_html=True
84
- )
85
- else:
86
- st.markdown(
87
- "<span style='background:#ffcccc;'>{}:токсично</span>".format(text),
88
- unsafe_allow_html=True
89
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
 
91
  if st.button("Проверить текст"):
92
  if user_input.strip():
93
  st.subheader("Результат:")
94
  result = re.split(r'[.\n!?]+', user_input)
95
  result = [part for part in result if part.strip() != ""]
96
- if result!=[]:
97
- for text in result:
98
- highlight_obscene_words(text,model_type)
 
 
 
99
  else:
100
  st.warning("Пожалуйста, введите текст для проверки")
 
72
 
73
  model_type = st.radio(
74
  "Выберите модель",
75
+ ("fasttext", "ru-BERT","FRIDA")
76
  )
77
 
78
  def highlight_obscene_words(text, model_type):
79
+ if model_type=="FRIDA":
80
+ result=model_wrapper(text)
81
+ for item in result:
82
+ if item.label=="non-toxic":
83
+ st.markdown(
84
+ "<span style='background:#47916B;'>{}:приемлемо</span>".format(text),
85
+ unsafe_allow_html=True
86
+ )
87
+ else:
88
+ st.markdown(
89
+ "<span style='background:#ffcccc;'>{}:токсично</span>".format(text),
90
+ unsafe_allow_html=True
91
+ )
92
+ else:
93
+ label, prob=model_wrapper(text.lower(),model_type)
94
+ if label=='__label__positive':
95
+ st.markdown(
96
+ "<span style='background:#47916B;'>{}:приемлемо</span>".format(text),
97
+ unsafe_allow_html=True
98
+ )
99
+ else:
100
+ st.markdown(
101
+ "<span style='background:#ffcccc;'>{}:токсично</span>".format(text),
102
+ unsafe_allow_html=True
103
+ )
104
 
105
  if st.button("Проверить текст"):
106
  if user_input.strip():
107
  st.subheader("Результат:")
108
  result = re.split(r'[.\n!?]+', user_input)
109
  result = [part for part in result if part.strip() != ""]
110
+ if model_type=="FRIDA":
111
+ highlight_obscene_words(text,model_type)
112
+ else:
113
+ if result!=[]:
114
+ for text in result:
115
+ highlight_obscene_words(text,model_type)
116
  else:
117
  st.warning("Пожалуйста, введите текст для проверки")