Spaces:
Sleeping
Sleeping
| 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") | |