Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,12 +23,22 @@ def classify(text):
|
|
| 23 |
with torch.no_grad():
|
| 24 |
outputs = model(**inputs)
|
| 25 |
probs = torch.softmax(outputs.logits, dim=1)[0]
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
percent = round(confidence * 100, 2)
|
| 29 |
result = f"Prediction / 预测:\n{labels[pred]}\n📊 Confidence /置信度: {percent}%"
|
| 30 |
return result
|
| 31 |
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
# Gradio 界面
|
| 34 |
interface = gr.Interface(
|
|
|
|
| 23 |
with torch.no_grad():
|
| 24 |
outputs = model(**inputs)
|
| 25 |
probs = torch.softmax(outputs.logits, dim=1)[0]
|
| 26 |
+
|
| 27 |
+
threshold = 0.7 # 自定义阈值(你可以改成别的)
|
| 28 |
+
if probs[1].item() > threshold:
|
| 29 |
+
pred = 1 # 判为操纵性
|
| 30 |
+
else:
|
| 31 |
+
pred = 0 # 判为非操纵性
|
| 32 |
+
|
| 33 |
+
confidence = min(probs[pred].item(), 0.95) # 置信度依然可以控制上限
|
| 34 |
+
|
| 35 |
percent = round(confidence * 100, 2)
|
| 36 |
result = f"Prediction / 预测:\n{labels[pred]}\n📊 Confidence /置信度: {percent}%"
|
| 37 |
return result
|
| 38 |
|
| 39 |
+
#谁大选谁
|
| 40 |
+
#pred = torch.argmax(probs).item()
|
| 41 |
+
#confidence = min(probs[pred].item(), 0.95) # 限制置信度最大为95%
|
| 42 |
|
| 43 |
# Gradio 界面
|
| 44 |
interface = gr.Interface(
|