Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -11,11 +11,11 @@ from sklearn.feature_extraction.text import TfidfVectorizer
|
|
11 |
def load_models():
|
12 |
st.session_state.loaded = True
|
13 |
|
14 |
-
with open('models/tfidf_vectorizer_untrue_inform_detection_tfidf_bg_0.96_F1_score_3Y_N_Q1_082023.pkl', 'rb') as f:
|
15 |
-
|
16 |
|
17 |
-
with open('models/SVM_model_untrue_inform_detection_tfidf_bg_0.96_F1_score_3Y_N_Q1_082023.pkl', 'rb') as f:
|
18 |
-
|
19 |
|
20 |
st.session_state.bert_disinfo = pipeline(task="text-classification",
|
21 |
model=BertForSequenceClassification.from_pretrained("usmiva/bert-desinform-bg", num_labels=2),
|
@@ -48,14 +48,14 @@ if 'lang' not in st.session_state:
|
|
48 |
|
49 |
if all([
|
50 |
'bert_gpt_result' not in st.session_state,
|
51 |
-
'untrue_detector_result' not in st.session_state,
|
52 |
'bert_disinfo_result' not in st.session_state,
|
53 |
'emotions_result' not in st.session_state
|
54 |
]):
|
55 |
st.session_state.bert_gpt_result = [{'label': '', 'score': 1}]
|
56 |
|
57 |
-
st.session_state.untrue_detector_result = ''
|
58 |
-
st.session_state.untrue_detector_probability = 1
|
59 |
|
60 |
st.session_state.bert_disinfo_result = [{'label': '', 'score': 1}]
|
61 |
|
@@ -98,10 +98,10 @@ if st.session_state.agree:
|
|
98 |
if st.button(content['analyze_button'][st.session_state.lang]):
|
99 |
st.session_state.bert_gpt_result = st.session_state.bert_gpt(user_input)
|
100 |
|
101 |
-
user_tfidf_untrue_inf = st.session_state.tfidf_vectorizer_untrue_inf.transform([user_input])
|
102 |
-
st.session_state.untrue_detector_result = st.session_state.untrue_detector.predict(user_tfidf_untrue_inf)[0]
|
103 |
-
st.session_state.untrue_detector_probability = st.session_state.untrue_detector.predict_proba(user_tfidf_untrue_inf)[0]
|
104 |
-
st.session_state.untrue_detector_probability = max(st.session_state.untrue_detector_probability[0], st.session_state.untrue_detector_probability[1])
|
105 |
|
106 |
st.session_state.bert_disinfo_result = st.session_state.bert_disinfo(user_input)
|
107 |
|
@@ -118,14 +118,14 @@ if st.session_state.agree:
|
|
118 |
str(round(st.session_state.bert_gpt_result[0]['score'] * 100, 2)) +
|
119 |
content['bert_human_prob'][st.session_state.lang], icon="✅")
|
120 |
|
121 |
-
if st.session_state.untrue_detector_result == 0:
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
else:
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
|
130 |
if st.session_state.bert_disinfo_result[0]['label'] == 'LABEL_1':
|
131 |
st.warning(content['bert_yes_1'][st.session_state.lang] +
|
|
|
11 |
def load_models():
|
12 |
st.session_state.loaded = True
|
13 |
|
14 |
+
# with open('models/tfidf_vectorizer_untrue_inform_detection_tfidf_bg_0.96_F1_score_3Y_N_Q1_082023.pkl', 'rb') as f:
|
15 |
+
# st.session_state.tfidf_vectorizer_untrue_inf = pickle.load(f)
|
16 |
|
17 |
+
# with open('models/SVM_model_untrue_inform_detection_tfidf_bg_0.96_F1_score_3Y_N_Q1_082023.pkl', 'rb') as f:
|
18 |
+
# st.session_state.untrue_detector = pickle.load(f)
|
19 |
|
20 |
st.session_state.bert_disinfo = pipeline(task="text-classification",
|
21 |
model=BertForSequenceClassification.from_pretrained("usmiva/bert-desinform-bg", num_labels=2),
|
|
|
48 |
|
49 |
if all([
|
50 |
'bert_gpt_result' not in st.session_state,
|
51 |
+
# 'untrue_detector_result' not in st.session_state,
|
52 |
'bert_disinfo_result' not in st.session_state,
|
53 |
'emotions_result' not in st.session_state
|
54 |
]):
|
55 |
st.session_state.bert_gpt_result = [{'label': '', 'score': 1}]
|
56 |
|
57 |
+
# st.session_state.untrue_detector_result = ''
|
58 |
+
# st.session_state.untrue_detector_probability = 1
|
59 |
|
60 |
st.session_state.bert_disinfo_result = [{'label': '', 'score': 1}]
|
61 |
|
|
|
98 |
if st.button(content['analyze_button'][st.session_state.lang]):
|
99 |
st.session_state.bert_gpt_result = st.session_state.bert_gpt(user_input)
|
100 |
|
101 |
+
# user_tfidf_untrue_inf = st.session_state.tfidf_vectorizer_untrue_inf.transform([user_input])
|
102 |
+
# st.session_state.untrue_detector_result = st.session_state.untrue_detector.predict(user_tfidf_untrue_inf)[0]
|
103 |
+
# st.session_state.untrue_detector_probability = st.session_state.untrue_detector.predict_proba(user_tfidf_untrue_inf)[0]
|
104 |
+
# st.session_state.untrue_detector_probability = max(st.session_state.untrue_detector_probability[0], st.session_state.untrue_detector_probability[1])
|
105 |
|
106 |
st.session_state.bert_disinfo_result = st.session_state.bert_disinfo(user_input)
|
107 |
|
|
|
118 |
str(round(st.session_state.bert_gpt_result[0]['score'] * 100, 2)) +
|
119 |
content['bert_human_prob'][st.session_state.lang], icon="✅")
|
120 |
|
121 |
+
# if st.session_state.untrue_detector_result == 0:
|
122 |
+
# st.warning(content['untrue_getect_yes'][st.session_state.lang] +
|
123 |
+
# str(round(st.session_state.untrue_detector_probability * 100, 2)) +
|
124 |
+
# content['untrue_yes_proba'][st.session_state.lang], icon="⚠️")
|
125 |
+
# else:
|
126 |
+
# st.success(content['untrue_getect_no'][st.session_state.lang] +
|
127 |
+
# str(round(st.session_state.untrue_detector_probability * 100, 2)) +
|
128 |
+
# content['untrue_no_proba'][st.session_state.lang], icon="✅")
|
129 |
|
130 |
if st.session_state.bert_disinfo_result[0]['label'] == 'LABEL_1':
|
131 |
st.warning(content['bert_yes_1'][st.session_state.lang] +
|