Spaces:
Sleeping
Sleeping
File size: 1,350 Bytes
16067ee | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | import json
import random
from app import get_response, predict_intent
with open("intents_augmented.json", encoding="utf-8") as f:
intents = json.load(f)["intents"]
total = 0
correct = 0
results = []
print("\n بدء اختبار الردود الفعلية من البوت...\n")
for intent in intents:
tag = intent["tag"]
patterns = intent["patterns"]
responses = intent["responses"]
for example in patterns:
total += 1
reply = get_response(example)
predicted_tag, conf = predict_intent(example)
is_correct = any(r.strip() == reply.strip() for r in responses)
results.append({
"input": example,
"expected_tag": tag,
"predicted_tag": predicted_tag,
"confidence": round(conf, 3),
"reply": reply,
"is_correct": is_correct
})
status = "T" if is_correct else "F"
print(f"{status} {example} → {predicted_tag} ({conf:.2f})")
if is_correct:
correct += 1
accuracy = (correct / total) * 100
print(f"\n دقة الردود الفعلية: {accuracy:.2f}% ({correct}/{total})\n")
with open("results/full_eval.json", "w", encoding="utf-8") as f:
json.dump(results, f, ensure_ascii=False, indent=2)
print("تم حفظ التفاصيل في results/full_eval.json")
|