LilithHu commited on
Commit
3662b93
·
verified ·
1 Parent(s): fde1d98

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -12
app.py CHANGED
@@ -21,23 +21,50 @@ labels = ["Non-manipulative / 非操纵性", "Manipulative / 操纵性"]
21
  def classify(text):
22
  inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True).to(device)
23
  with torch.no_grad():
24
- outputs = model(**inputs)
25
- probs = torch.softmax(outputs.logits, dim=1)[0] # 取第一个样本的概率向量
26
- probs = torch.clamp(probs, max=0.95) # 限制最大置信度为 95%
27
- result = "🧠 预测 / Prediction:\n"
28
- for i, label in enumerate(labels):
29
- percent = round(probs[i].item() * 100, 2)
30
- result += f"{label}: {percent}%\n"
31
- return result
32
 
33
 
34
  # Gradio 界面
35
  interface = gr.Interface(
36
  fn=classify,
37
- inputs=gr.Textbox(lines=4, placeholder="Enter text in English or Chinese... / 输入中文或英文句子"),
38
- outputs="text",
39
- title="🔍 Manipulative Language Detector / 操纵性语言识别器",
40
- description="🧪 输入英文或中文句子,系统将判断其是否包含操纵性语言。\nEnter a sentence in English or Chinese to detect if it's manipulative.",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  )
42
 
 
43
  interface.launch()
 
21
  def classify(text):
22
  inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True).to(device)
23
  with torch.no_grad():
24
+ outputs = model(**inputs)
25
+ probs = torch.softmax(outputs.logits, dim=1)[0] # 取第一个样本的概率向量
26
+ probs = torch.clamp(probs, max=0.95) # 限制最大置信度为 95%
27
+ result = "🧠 预测 / Prediction:\n"
28
+ for i, label in enumerate(labels):
29
+ percent = round(probs[i].item() * 100, 2)
30
+ result += f"{label}: {percent}%\n"
31
+ return result
32
 
33
 
34
  # Gradio 界面
35
  interface = gr.Interface(
36
  fn=classify,
37
+ inputs=gr.Textbox(
38
+ lines=4,
39
+ placeholder="Enter a sentence in English or Chinese... / 输入英文或中文句子",
40
+ label="📝 Input Text / 输入文本"
41
+ ),
42
+ outputs=gr.Textbox(label="📊 Prediction / 预测结果"),
43
+ title="🧠 Manipulative Language Detector / 操纵性语言识别器",
44
+ description="""
45
+ 🔍 This tool detects **emotionally manipulative language** in English or Chinese digital communication.
46
+ 🧪 The model was fine-tuned on a manually annotated dataset of 10,000 Chinese messages, categorized into four manipulation types.
47
+
48
+ ---
49
+
50
+ 📌 **Disclaimer / 免责声明:**
51
+ This system is for **research and educational purposes only**.
52
+ It **does not guarantee accuracy** and **should not be used as legal or clinical evidence**.
53
+
54
+ 本工具仅用于**学术研究与教学演示**,不构成法律、医疗或其他正式用途的依据。
55
+
56
+ ---
57
+
58
+ 🤖 **Model Info**:
59
+ - Model: `LilithHu/mbert-manipulative-detector`
60
+ - Base: `mDeBERTa-v3` multilingual pre-trained model
61
+ - Fine-tuned using HuggingFace Transformers on labeled Chinese data
62
+
63
+ 🌐 Built with Gradio and hosted on HuggingFace Spaces.
64
+ """,
65
+ theme="default",
66
+ allow_flagging="never"
67
  )
68
 
69
+
70
  interface.launch()