TRACES commited on
Commit
445f48d
·
1 Parent(s): 16ae58d

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +19 -14
main.py CHANGED
@@ -11,14 +11,14 @@ from sklearn.feature_extraction.text import TfidfVectorizer
11
  def load_models():
12
  st.session_state.loaded = True
13
 
14
- with open('models/tfidf_vectorizer_svm_model_2_classes_gpt_chatgpt_detection_tfidf_bg_0.886_F1_score.pkl', 'rb') as f:
15
- st.session_state.tfidf_vectorizer_disinformation = pickle.load(f)
16
 
17
  with open('models/tfidf_vectorizer_untrue_inform_detection_tfidf_bg_0.96_F1_score_3Y_N_Q1_082023.pkl', 'rb') as f:
18
  st.session_state.tfidf_vectorizer_untrue_inf = pickle.load(f)
19
 
20
- with open('models/svm_model_2_classes_gpt_chatgpt_detection_tfidf_bg_0.886_F1_score.pkl', 'rb') as f:
21
- st.session_state.gpt_detector = pickle.load(f)
22
 
23
  with open('models/SVM_model_untrue_inform_detection_tfidf_bg_0.96_F1_score_3Y_N_Q1_082023.pkl', 'rb') as f:
24
  st.session_state.untrue_detector = pickle.load(f)
@@ -55,12 +55,14 @@ if all([
55
  # st.session_state.gpt_detector_result = ''
56
  # st.session_state.gpt_detector_probability = [1, 0]
57
 
 
 
58
  st.session_state.untrue_detector_result = ''
59
  st.session_state.untrue_detector_probability = 1
60
 
61
  st.session_state.bert_disinfo_result = [{'label': '', 'score': 1}]
62
 
63
- st.session_state.bert_gpt_result = [{'label': '', 'score': 1}]
64
 
65
  content = load_content()
66
  if 'loaded' not in st.session_state:
@@ -101,6 +103,8 @@ if st.session_state.agree:
101
  # st.session_state.gpt_detector_result = st.session_state.gpt_detector.predict(user_tfidf_disinformation)[0]
102
  # st.session_state.gpt_detector_probability = st.session_state.gpt_detector.predict_proba(user_tfidf_disinformation)[0]
103
 
 
 
104
  user_tfidf_untrue_inf = st.session_state.tfidf_vectorizer_untrue_inf.transform([user_input])
105
  st.session_state.untrue_detector_result = st.session_state.untrue_detector.predict(user_tfidf_untrue_inf)[0]
106
  st.session_state.untrue_detector_probability = st.session_state.untrue_detector.predict_proba(user_tfidf_untrue_inf)[0]
@@ -108,7 +112,7 @@ if st.session_state.agree:
108
 
109
  st.session_state.bert_disinfo_result = st.session_state.bert_disinfo(user_input)
110
 
111
- st.session_state.bert_gpt_result = st.session_state.bert_gpt(user_input)
112
 
113
  # if st.session_state.gpt_detector_result == 1:
114
  # st.warning(content['gpt_getect_yes'][st.session_state.lang] +
@@ -119,6 +123,15 @@ if st.session_state.agree:
119
  # str(round(st.session_state.gpt_detector_probability[0] * 100, 2)) +
120
  # content['gpt_no_proba'][st.session_state.lang], icon="✅")
121
 
 
 
 
 
 
 
 
 
 
122
  if st.session_state.untrue_detector_result == 0:
123
  st.warning(content['untrue_getect_yes'][st.session_state.lang] +
124
  str(round(st.session_state.untrue_detector_probability * 100, 2)) +
@@ -137,14 +150,6 @@ if st.session_state.agree:
137
  str(round(st.session_state.bert_disinfo_result[0]['score'] * 100, 2)) +
138
  content['bert_no_2'][st.session_state.lang], icon="✅")
139
 
140
- if st.session_state.bert_gpt_result[0]['label'] == 'LABEL_1':
141
- st.warning(content['bert_gpt_1'][st.session_state.lang] +
142
- str(round(st.session_state.bert_gpt_result[0]['score'] * 100, 2)) +
143
- content['bert_gpt_2'][st.session_state.lang], icon = "⚠️")
144
- else:
145
- st.success(content['bert_human_1'][st.session_state.lang] +
146
- str(round(st.session_state.bert_gpt_result[0]['score'] * 100, 2)) +
147
- content['bert_human_2'][st.session_state.lang], icon="✅")
148
 
149
  st.info(content['disinformation_definition'][st.session_state.lang], icon="ℹ️")
150
 
 
11
  def load_models():
12
  st.session_state.loaded = True
13
 
14
+ # with open('models/tfidf_vectorizer_svm_model_2_classes_gpt_chatgpt_detection_tfidf_bg_0.886_F1_score.pkl', 'rb') as f:
15
+ # st.session_state.tfidf_vectorizer_disinformation = pickle.load(f)
16
 
17
  with open('models/tfidf_vectorizer_untrue_inform_detection_tfidf_bg_0.96_F1_score_3Y_N_Q1_082023.pkl', 'rb') as f:
18
  st.session_state.tfidf_vectorizer_untrue_inf = pickle.load(f)
19
 
20
+ # with open('models/svm_model_2_classes_gpt_chatgpt_detection_tfidf_bg_0.886_F1_score.pkl', 'rb') as f:
21
+ # st.session_state.gpt_detector = pickle.load(f)
22
 
23
  with open('models/SVM_model_untrue_inform_detection_tfidf_bg_0.96_F1_score_3Y_N_Q1_082023.pkl', 'rb') as f:
24
  st.session_state.untrue_detector = pickle.load(f)
 
55
  # st.session_state.gpt_detector_result = ''
56
  # st.session_state.gpt_detector_probability = [1, 0]
57
 
58
+ st.session_state.bert_gpt_result = [{'label': '', 'score': 1}]
59
+
60
  st.session_state.untrue_detector_result = ''
61
  st.session_state.untrue_detector_probability = 1
62
 
63
  st.session_state.bert_disinfo_result = [{'label': '', 'score': 1}]
64
 
65
+
66
 
67
  content = load_content()
68
  if 'loaded' not in st.session_state:
 
103
  # st.session_state.gpt_detector_result = st.session_state.gpt_detector.predict(user_tfidf_disinformation)[0]
104
  # st.session_state.gpt_detector_probability = st.session_state.gpt_detector.predict_proba(user_tfidf_disinformation)[0]
105
 
106
+ st.session_state.bert_gpt_result = st.session_state.bert_gpt(user_input)
107
+
108
  user_tfidf_untrue_inf = st.session_state.tfidf_vectorizer_untrue_inf.transform([user_input])
109
  st.session_state.untrue_detector_result = st.session_state.untrue_detector.predict(user_tfidf_untrue_inf)[0]
110
  st.session_state.untrue_detector_probability = st.session_state.untrue_detector.predict_proba(user_tfidf_untrue_inf)[0]
 
112
 
113
  st.session_state.bert_disinfo_result = st.session_state.bert_disinfo(user_input)
114
 
115
+
116
 
117
  # if st.session_state.gpt_detector_result == 1:
118
  # st.warning(content['gpt_getect_yes'][st.session_state.lang] +
 
123
  # str(round(st.session_state.gpt_detector_probability[0] * 100, 2)) +
124
  # content['gpt_no_proba'][st.session_state.lang], icon="✅")
125
 
126
+ if st.session_state.bert_gpt_result[0]['label'] == 'LABEL_1':
127
+ st.warning(content['bert_gpt_1'][st.session_state.lang] +
128
+ str(round(st.session_state.bert_gpt_result[0]['score'] * 100, 2)) +
129
+ content['bert_gpt_2'][st.session_state.lang], icon = "⚠️")
130
+ else:
131
+ st.success(content['bert_human_1'][st.session_state.lang] +
132
+ str(round(st.session_state.bert_gpt_result[0]['score'] * 100, 2)) +
133
+ content['bert_human_2'][st.session_state.lang], icon="✅")
134
+
135
  if st.session_state.untrue_detector_result == 0:
136
  st.warning(content['untrue_getect_yes'][st.session_state.lang] +
137
  str(round(st.session_state.untrue_detector_probability * 100, 2)) +
 
150
  str(round(st.session_state.bert_disinfo_result[0]['score'] * 100, 2)) +
151
  content['bert_no_2'][st.session_state.lang], icon="✅")
152
 
 
 
 
 
 
 
 
 
153
 
154
  st.info(content['disinformation_definition'][st.session_state.lang], icon="ℹ️")
155