Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| # -*- coding: utf-8 -*- | |
| """ | |
| اختبار مشكلة endpoint التلخيص | |
| """ | |
| import requests | |
| import json | |
| def test_cors_preflight(): | |
| """اختبار طلب OPTIONS (CORS preflight)""" | |
| print("🔍 اختبار CORS preflight...") | |
| try: | |
| response = requests.options('http://localhost:5001/summarize') | |
| print(f"Status Code: {response.status_code}") | |
| print(f"Headers: {dict(response.headers)}") | |
| # تحقق من CORS headers | |
| cors_origin = response.headers.get('Access-Control-Allow-Origin') | |
| print(f"CORS Origin: '{cors_origin}'") | |
| if cors_origin and ',' in cors_origin: | |
| print("❌ مشكلة: CORS header يحتوي على قيم متعددة!") | |
| return False | |
| elif cors_origin == '*': | |
| print("✅ CORS header صحيح") | |
| return True | |
| else: | |
| print(f"⚠️ CORS header غير متوقع: {cors_origin}") | |
| return False | |
| except Exception as e: | |
| print(f"❌ خطأ في طلب OPTIONS: {e}") | |
| return False | |
| def test_summarize_endpoint(): | |
| """اختبار endpoint التلخيص""" | |
| print("\n🤖 اختبار endpoint التلخيص...") | |
| test_data = { | |
| "text": "Hello, how are you? What are you doing today? Tell me.", | |
| "language": "arabic" | |
| } | |
| try: | |
| response = requests.post( | |
| 'http://localhost:5001/summarize', | |
| json=test_data, | |
| headers={'Content-Type': 'application/json'} | |
| ) | |
| print(f"Status Code: {response.status_code}") | |
| print(f"Response: {response.text}") | |
| if response.status_code == 200: | |
| data = response.json() | |
| if data.get('success'): | |
| print("✅ التلخيص نجح!") | |
| return True | |
| else: | |
| print(f"❌ فشل التلخيص: {data.get('error')}") | |
| return False | |
| else: | |
| print(f"❌ خطأ HTTP: {response.status_code}") | |
| return False | |
| except Exception as e: | |
| print(f"❌ خطأ في طلب POST: {e}") | |
| return False | |
| def test_server_status(): | |
| """اختبار حالة الخادم""" | |
| print("🌐 اختبار حالة الخادم...") | |
| try: | |
| response = requests.get('http://localhost:5001/record') | |
| print(f"Status Code: {response.status_code}") | |
| if response.status_code == 200: | |
| data = response.json() | |
| print(f"Server Status: {data.get('status')}") | |
| return True | |
| else: | |
| print(f"❌ الخادم غير متاح: {response.status_code}") | |
| return False | |
| except Exception as e: | |
| print(f"❌ لا يمكن الوصول للخادم: {e}") | |
| return False | |
| if __name__ == "__main__": | |
| print("=" * 50) | |
| print("🚀 بدء اختبار مشكلة التلخيص") | |
| print("=" * 50) | |
| # اختبار حالة الخادم | |
| server_ok = test_server_status() | |
| if server_ok: | |
| # اختبار CORS | |
| cors_ok = test_cors_preflight() | |
| if cors_ok: | |
| # اختبار التلخيص | |
| summarize_ok = test_summarize_endpoint() | |
| if summarize_ok: | |
| print("\n🎉 جميع الاختبارات نجحت!") | |
| else: | |
| print("\n❌ فشل في اختبار التلخيص") | |
| else: | |
| print("\n❌ مشكلة في CORS - يجب إعادة تشغيل الخادم") | |
| else: | |
| print("\n❌ الخادم غير متاح - يجب تشغيله أولاً") | |
| print("=" * 50) | |