yuchuantian commited on
Commit
ec41f01
·
verified ·
1 Parent(s): 5ffac5a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -12
app.py CHANGED
@@ -4,15 +4,30 @@ from transformers.models.bert import BertForSequenceClassification, BertTokenize
4
  from transformers.models.roberta import RobertaForSequenceClassification, RobertaTokenizer
5
 
6
  # torch.set_grad_enabled(False)
7
-
8
- name_en = "yuchuantian/AIGC_detector_env2"
 
9
  model_en = RobertaForSequenceClassification.from_pretrained(name_en)
10
  tokenizer_en = RobertaTokenizer.from_pretrained(name_en)
11
 
12
- name_zh = "yuchuantian/AIGC_detector_zhv2"
 
 
 
 
 
 
13
  model_zh = BertForSequenceClassification.from_pretrained(name_zh)
14
  tokenizer_zh = BertTokenizer.from_pretrained(name_zh)
15
 
 
 
 
 
 
 
 
 
16
 
17
  def predict_func(text: str, tokenizer, model):
18
  with torch.no_grad():
@@ -28,12 +43,32 @@ def predict_en(text):
28
  res = predict_func(text, tokenizer_en, model_en)
29
  return id2label[res['label']], res['score']
30
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  def predict_zh(text):
33
  id2label = ['人类', 'AI']
34
  res = predict_func(text, tokenizer_zh, model_zh)
35
  return id2label[res['label']], res['score']
36
 
 
 
 
 
 
 
 
 
 
 
37
 
38
  print(predict_en('Peking University is one of the best universities in the world.'))
39
 
@@ -46,6 +81,9 @@ with gr.Blocks() as demo:
46
  ## AIGC Detector 大模型AI文本检测器
47
 
48
  **News**
 
 
 
49
  3/25/2025: Our AIGC Detector demo is available! 🔥🔥🔥
50
 
51
  This app is a demo of our AIGC Detector. If you are interested in our project, please keep tuned at our [GitHub](https://github.com/YuchuanTian/AIGC_text_detector) !
@@ -54,19 +92,15 @@ with gr.Blocks() as demo:
54
 
55
  [Paper Link 论文链接](https://arxiv.org/abs/2305.18149)
56
 
57
- The loaded weights are as follows 加载的权重如下:
58
-
59
- English: en v2
60
-
61
- Chinese: zh v2 (one of the best Chinese AI detectors)
62
 
63
  Acknowledgement 致谢
64
-
65
  We sincerely thank [Hello-SimpleAI](https://huggingface.co/spaces/Hello-SimpleAI/chatgpt-detector-single) for their code.
66
-
67
  """)
68
 
69
- with gr.Tab("中文"):
70
  gr.Markdown("""
71
  注意: 本检测器提供的结果仅供参考,应谨慎作为事实依据。
72
  """)
@@ -75,7 +109,27 @@ with gr.Blocks() as demo:
75
  label2 = gr.Textbox(lines=1, label='预测结果')
76
  score2 = gr.Textbox(lines=1, label='模型概率')
77
 
78
- with gr.Tab("English"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  gr.Markdown("""
80
  Note: The results are for reference only; they could not be used as factual evidence.
81
  """)
@@ -84,8 +138,30 @@ with gr.Blocks() as demo:
84
  label1 = gr.Textbox(lines=1, label='Predicted Label')
85
  score1 = gr.Textbox(lines=1, label='Probability')
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  button1.click(predict_en, inputs=[t1], outputs=[label1,score1])
88
  button2.click(predict_zh, inputs=[t2], outputs=[label2,score2])
 
 
 
 
89
 
90
  # Page Count
91
  gr.Markdown("""
 
4
  from transformers.models.roberta import RobertaForSequenceClassification, RobertaTokenizer
5
 
6
  # torch.set_grad_enabled(False)
7
+ print('Loading Models from HuggingFace...')
8
+ # load by default
9
+ name_en = "yuchuantian/AIGC_detector_env3"
10
  model_en = RobertaForSequenceClassification.from_pretrained(name_en)
11
  tokenizer_en = RobertaTokenizer.from_pretrained(name_en)
12
 
13
+ name_en3 = "yuchuantian/AIGC_detector_env3short"
14
+ model_en3 = RobertaForSequenceClassification.from_pretrained(name_en3)
15
+
16
+ name_en5 = "yuchuantian/AIGC_detector_env2"
17
+ model_en5 = RobertaForSequenceClassification.from_pretrained(name_en5)
18
+
19
+ name_zh = "yuchuantian/AIGC_detector_zhv3"
20
  model_zh = BertForSequenceClassification.from_pretrained(name_zh)
21
  tokenizer_zh = BertTokenizer.from_pretrained(name_zh)
22
 
23
+ name_zh4 = "yuchuantian/AIGC_detector_zhv3short"
24
+ model_zh4 = BertForSequenceClassification.from_pretrained(name_zh4)
25
+
26
+ name_zh6 = "yuchuantian/AIGC_detector_zhv2"
27
+ model_zh6 = BertForSequenceClassification.from_pretrained(name_zh6)
28
+
29
+ print('Model Loading from HuggingFace Complete!')
30
+
31
 
32
  def predict_func(text: str, tokenizer, model):
33
  with torch.no_grad():
 
43
  res = predict_func(text, tokenizer_en, model_en)
44
  return id2label[res['label']], res['score']
45
 
46
+ def predict_en3(text):
47
+ id2label = ['Human', 'AI']
48
+ res = predict_func(text, tokenizer_en, model_en3)
49
+ return id2label[res['label']], res['score']
50
+
51
+ def predict_en5(text):
52
+ id2label = ['Human', 'AI']
53
+ res = predict_func(text, tokenizer_en, model_en5)
54
+ return id2label[res['label']], res['score']
55
+
56
 
57
  def predict_zh(text):
58
  id2label = ['人类', 'AI']
59
  res = predict_func(text, tokenizer_zh, model_zh)
60
  return id2label[res['label']], res['score']
61
 
62
+ def predict_zh4(text):
63
+ id2label = ['人类', 'AI']
64
+ res = predict_func(text, tokenizer_zh, model_zh4)
65
+ return id2label[res['label']], res['score']
66
+
67
+ def predict_zh6(text):
68
+ id2label = ['人类', 'AI']
69
+ res = predict_func(text, tokenizer_zh, model_zh6)
70
+ return id2label[res['label']], res['score']
71
+
72
 
73
  print(predict_en('Peking University is one of the best universities in the world.'))
74
 
 
81
  ## AIGC Detector 大模型AI文本检测器
82
 
83
  **News**
84
+
85
+ 6/25/2025: The detectors are updated! Latest LLMs and reasoning models are now covered! 🔥🔥🔥
86
+
87
  3/25/2025: Our AIGC Detector demo is available! 🔥🔥🔥
88
 
89
  This app is a demo of our AIGC Detector. If you are interested in our project, please keep tuned at our [GitHub](https://github.com/YuchuanTian/AIGC_text_detector) !
 
92
 
93
  [Paper Link 论文链接](https://arxiv.org/abs/2305.18149)
94
 
95
+ The loadable versions are as follows 可加载的检测器版本如下:
96
+ English: [En-v3](https://huggingface.co/yuchuantian/AIGC_detector_env3) / [En-v3-short](https://huggingface.co/yuchuantian/AIGC_detector_env3short) / [En_v2](https://huggingface.co/yuchuantian/AIGC_detector_env2)
97
+ Chinese: [Zh-v3](https://huggingface.co/yuchuantian/AIGC_detector_zhv3) / [Zh-v3-short](https://huggingface.co/yuchuantian/AIGC_detector_zhv3short) / [Zh_v2](https://huggingface.co/yuchuantian/AIGC_detector_zhv2)
 
 
98
 
99
  Acknowledgement 致谢
 
100
  We sincerely thank [Hello-SimpleAI](https://huggingface.co/spaces/Hello-SimpleAI/chatgpt-detector-single) for their code.
 
101
  """)
102
 
103
+ with gr.Tab("中文-V3"):
104
  gr.Markdown("""
105
  注意: 本检测器提供的结果仅供参考,应谨慎作为事实依据。
106
  """)
 
109
  label2 = gr.Textbox(lines=1, label='预测结果')
110
  score2 = gr.Textbox(lines=1, label='模型概率')
111
 
112
+
113
+ with gr.Tab("中文-V3-短文本"):
114
+ gr.Markdown("""
115
+ 注意: 本检测器提供的结果仅供参考,应谨慎作为事实依据。
116
+ """)
117
+ t4 = gr.Textbox(lines=5, label='文本',value="北京大学建立于1898年7月3日,初名京师大学堂,辛亥革命后于1912年改为北京大学。1938年更名为国立西南联合大学。1946年10月在北平复员。1952年成为以文理学科为主的综合性大学。")
118
+ button4 = gr.Button("🚀 检测!")
119
+ label4 = gr.Textbox(lines=1, label='预测结果')
120
+ score4 = gr.Textbox(lines=1, label='模型概率')
121
+
122
+ with gr.Tab("中文-V2"):
123
+ gr.Markdown("""
124
+ 注意: 本检测器提供的结果仅供参考,应谨慎作为事实依据。
125
+ """)
126
+ t6 = gr.Textbox(lines=5, label='文本',value="北京大学建立于1898年7月3日,初名京师大学堂,辛亥革命后于1912年改为北京大学。1938年更名为国立西南联合大学。1946年10月在北平复员。1952年成为以文理学科为主的综合性大学。")
127
+ button6 = gr.Button("🚀 检测!")
128
+ label6 = gr.Textbox(lines=1, label='预测结果')
129
+ score6 = gr.Textbox(lines=1, label='模型概率')
130
+
131
+
132
+ with gr.Tab("English-V3"):
133
  gr.Markdown("""
134
  Note: The results are for reference only; they could not be used as factual evidence.
135
  """)
 
138
  label1 = gr.Textbox(lines=1, label='Predicted Label')
139
  score1 = gr.Textbox(lines=1, label='Probability')
140
 
141
+ with gr.Tab("English-V3-Short"):
142
+ gr.Markdown("""
143
+ Note: The results are for reference only; they could not be used as factual evidence.
144
+ """)
145
+ t3 = gr.Textbox(lines=5, label='Text',value="Originated as the Imperial University of Peking in 1898, Peking University was China's first national comprehensive university and the supreme education authority at the time. Since the founding of the People's Republic of China in 1949, it has developed into a comprehensive university with fundamental education and research in both humanities and science. The reform and opening-up of China in 1978 has ushered in a new era for the University unseen in history.")
146
+ button3 = gr.Button("🚀 Predict!")
147
+ label3 = gr.Textbox(lines=1, label='Predicted Label')
148
+ score3 = gr.Textbox(lines=1, label='Probability')
149
+
150
+ with gr.Tab("English-V2"):
151
+ gr.Markdown("""
152
+ Note: The results are for reference only; they could not be used as factual evidence.
153
+ """)
154
+ t1 = gr.Textbox(lines=5, label='Text',value="Originated as the Imperial University of Peking in 1898, Peking University was China's first national comprehensive university and the supreme education authority at the time. Since the founding of the People's Republic of China in 1949, it has developed into a comprehensive university with fundamental education and research in both humanities and science. The reform and opening-up of China in 1978 has ushered in a new era for the University unseen in history.")
155
+ button5 = gr.Button("🚀 Predict!")
156
+ label5 = gr.Textbox(lines=1, label='Predicted Label')
157
+ score5 = gr.Textbox(lines=1, label='Probability')
158
+
159
  button1.click(predict_en, inputs=[t1], outputs=[label1,score1])
160
  button2.click(predict_zh, inputs=[t2], outputs=[label2,score2])
161
+ button3.click(predict_en3, inputs=[t3], outputs=[label3,score3])
162
+ button4.click(predict_zh4, inputs=[t4], outputs=[label4,score4])
163
+ button5.click(predict_en5, inputs=[t5], outputs=[label5,score5])
164
+ button6.click(predict_zh6, inputs=[t6], outputs=[label6,score6])
165
 
166
  # Page Count
167
  gr.Markdown("""