Spaces:
Sleeping
Sleeping
File size: 4,557 Bytes
dfdd9cb | 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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | #!/usr/bin/env python3
"""
اختبار API لمعالج النصوص
"""
import requests
import json
import time
import logging
# إعداد التسجيل
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
BASE_URL = "http://localhost:8000"
def test_health_endpoint():
"""اختبار نقطة فحص الحالة"""
try:
response = requests.get(f"{BASE_URL}/health")
if response.status_code == 200:
data = response.json()
logger.info(f"✅ Health check: {data['message']}")
return True
else:
logger.error(f"❌ Health check failed: {response.status_code}")
return False
except Exception as e:
logger.error(f"❌ Health check error: {str(e)}")
return False
def test_text_correction():
"""اختبار تصحيح النصوص"""
try:
data = {
"text": "يحتاز غشاء الطبل تنتقل عظيمات السماء الاحتزازات",
"reference_texts": [
"يهتز غشاء الطبل تنتقل عظيمات السمع الاهتزازات إلى النافذة البيضية",
"يهتز غشاء النافذة البيضية يهتز اللمف الخارجي في القناة الدهليزية"
],
"max_distance": 3,
"threshold_freq": 1
}
response = requests.post(
f"{BASE_URL}/correct-text",
json=data,
headers={"Content-Type": "application/json"}
)
if response.status_code == 200:
result = response.json()
logger.info(f"✅ Text correction successful")
logger.info(f" Original: {result['data']['original_text']}")
logger.info(f" Corrected: {result['data']['corrected_text']}")
logger.info(f" Corrections: {result['data']['corrections_count']}")
return True
else:
logger.error(f"❌ Text correction failed: {response.status_code}")
logger.error(f" Response: {response.text}")
return False
except Exception as e:
logger.error(f"❌ Text correction error: {str(e)}")
return False
def test_text_comparison():
"""اختبار مقارنة النصوص"""
try:
data = {
"reference_text": "يهتز غشاء الطبل تنتقل عظيمات السمع الاهتزازات إلى النافذة البيضية",
"transcribed_text": "يحتاز غشاء الطبل تنتقل عظيمات السماء الاحتزازات إلى النافذة البيضية"
}
response = requests.post(
f"{BASE_URL}/compare-texts",
json=data,
headers={"Content-Type": "application/json"}
)
if response.status_code == 200:
result = response.json()
logger.info(f"✅ Text comparison successful")
logger.info(f" WER: {result['data']['wer_percentage']}")
logger.info(f" CER: {result['data']['cer_percentage']}")
return True
else:
logger.error(f"❌ Text comparison failed: {response.status_code}")
logger.error(f" Response: {response.text}")
return False
except Exception as e:
logger.error(f"❌ Text comparison error: {str(e)}")
return False
def main():
"""الدالة الرئيسية للاختبار"""
logger.info("🚀 بدء اختبار API لمعالج النصوص")
# انتظار تشغيل الخادم
logger.info("انتظار تشغيل الخادم...")
time.sleep(2)
tests_passed = 0
total_tests = 3
# اختبار فحص الحالة
if test_health_endpoint():
tests_passed += 1
# اختبار تصحيح النصوص
if test_text_correction():
tests_passed += 1
# اختبار مقارنة النصوص
if test_text_comparison():
tests_passed += 1
# عرض النتائج
logger.info(f"\n📊 نتائج الاختبارات: {tests_passed}/{total_tests}")
if tests_passed == total_tests:
logger.info("✅ جميع اختبارات API نجحت!")
return True
else:
logger.error("❌ فشلت بعض اختبارات API")
return False
if __name__ == "__main__":
success = main()
exit(0 if success else 1)
|