Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -86,33 +86,28 @@ async def analyze_text(input_data: MessageInput):
|
|
| 86 |
probs = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
| 87 |
|
| 88 |
predicted_class = torch.argmax(probs, dim=-1).item()
|
| 89 |
-
|
| 90 |
|
| 91 |
-
# تح
|
| 92 |
-
|
| 93 |
|
| 94 |
-
# ال
|
| 95 |
-
|
| 96 |
-
if predicted_class == 1:
|
| 97 |
verdict = "🚨 محاولة احتيال"
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
elif contains_scam_indicators(text):
|
| 101 |
-
verdict = "⚠️ مشبوه (يحتوي على كلمات دلالية خطر)"
|
| 102 |
-
final_confidence = 85.0 # خفضنا النسبة لأنها فحص يدوي
|
| 103 |
else:
|
| 104 |
verdict = "✅ نص آمن"
|
| 105 |
final_confidence = model_confidence
|
| 106 |
|
| 107 |
return {
|
| 108 |
"verdict": verdict,
|
| 109 |
-
"confidence": final_confidence,
|
| 110 |
-
"model_class": predicted_class,
|
| 111 |
-
"indicators_found": contains_scam_indicators(text)
|
| 112 |
}
|
| 113 |
except Exception as e:
|
| 114 |
return {"error": str(e)}
|
| 115 |
|
| 116 |
|
|
|
|
| 117 |
if __name__ == "__main__":
|
| 118 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 86 |
probs = torch.nn.functional.softmax(outputs.logits, dim=-1)
|
| 87 |
|
| 88 |
predicted_class = torch.argmax(probs, dim=-1).item()
|
| 89 |
+
model_confidence = probs[0][predicted_class].item() * 100
|
| 90 |
|
| 91 |
+
# نتحقق من المؤشرات اليدوية (الكلمات والدومينات)
|
| 92 |
+
found_indicators = contains_scam_indicators(text)
|
| 93 |
|
| 94 |
+
# إذا النموذج قال احتيال (1) أو الفحص اليدوي وجد أدلة (True)
|
| 95 |
+
if predicted_class == 1 or found_indicators:
|
|
|
|
| 96 |
verdict = "🚨 محاولة احتيال"
|
| 97 |
+
# إذا كان الفحص اليدوي هو من كشفه نثبتها على 95 أو نأخذ ثقة النموذج أيهما أعلى
|
| 98 |
+
final_confidence = max(model_confidence, 95.0) if found_indicators else model_confidence
|
|
|
|
|
|
|
|
|
|
| 99 |
else:
|
| 100 |
verdict = "✅ نص آمن"
|
| 101 |
final_confidence = model_confidence
|
| 102 |
|
| 103 |
return {
|
| 104 |
"verdict": verdict,
|
| 105 |
+
"confidence": round(final_confidence, 2)
|
|
|
|
|
|
|
| 106 |
}
|
| 107 |
except Exception as e:
|
| 108 |
return {"error": str(e)}
|
| 109 |
|
| 110 |
|
| 111 |
+
|
| 112 |
if __name__ == "__main__":
|
| 113 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|