Spaces:
Running
Running
hugfaceguy0001
commited on
Commit
•
58ab0a6
1
Parent(s):
fbe14df
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,23 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
)
|
24 |
-
|
25 |
demo.launch()
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
tokenizer = AutoTokenizer.from_pretrained("hugfaceguy0001/AITextDetector")
|
5 |
+
model = AutoModelForSequenceClassification.from_pretrained("hugfaceguy0001/AITextDetector")
|
6 |
+
def detect_text(text):
|
7 |
+
inputs = tokenizer(text, return_tensors="pt")
|
8 |
+
logits = model(**inputs).logits
|
9 |
+
probs = torch.nn.functional.softmax(logits)[0,:]
|
10 |
+
labels = {model.config.id2label[i]:float(probs[i]) for i in range(3)}
|
11 |
+
labels = dict(sorted(labels.items(),key=lambda x:x[1],reverse=True))
|
12 |
+
return labels
|
13 |
+
|
14 |
+
myexamples = ["黑神话这个游戏,你喷它优化、喷它地图、喷它空气墙、喷它战斗、喷它剧情;这些东西不管我自己觉得有没有喷一下的必要,可也都或多或少的能理解它为什么被喷的原因。",
|
15 |
+
"加密通信助长犯罪的说法并不成立,理由如下:隐私权的基本保障:加密技术保障了个人和组织的隐私权,这是基本人权的一部分。无论是个人的日常通信、商业机密,还是新闻记者的来源保护,加密通信都在确保合法和正当的隐私需求不被侵犯。"]
|
16 |
+
|
17 |
+
demo = gr.Interface(fn=detect_text,
|
18 |
+
inputs=gr.Text(label="请输入待检测的文本:"),
|
19 |
+
outputs=gr.Label(num_top_classes=3),
|
20 |
+
examples=myexamples
|
21 |
+
)
|
22 |
+
|
|
|
|
|
23 |
demo.launch()
|