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