Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| # -*- coding: utf-8 -*- | |
| """ | |
| اختبار سريع ومبسط لزر التلخيص | |
| """ | |
| import requests | |
| import json | |
| def test_summary_button(): | |
| """محاكاة نفس الطلب الذي يرسله زر التلخيص""" | |
| print("🤖 اختبار زر التلخيص...") | |
| print("=" * 50) | |
| # نفس البيانات التي ترسلها الواجهة | |
| test_data = { | |
| "text": "Hello, how are you? What are you doing today? Tell me.", | |
| "language": "arabic", | |
| "type": "full" | |
| } | |
| try: | |
| print("📤 إرسال طلب التلخيص...") | |
| print(f"البيانات: {test_data}") | |
| response = requests.post( | |
| 'http://localhost:5001/summarize', | |
| json=test_data, | |
| headers={ | |
| 'Content-Type': 'application/json', | |
| 'Accept': 'application/json' | |
| }, | |
| timeout=30 | |
| ) | |
| print(f"\n📥 استلام الرد:") | |
| print(f"Status Code: {response.status_code}") | |
| print(f"Headers: {dict(response.headers)}") | |
| if response.status_code == 200: | |
| data = response.json() | |
| print(f"\n✅ نجح التلخيص!") | |
| print(f"Keys في الرد: {list(data.keys())}") | |
| if data.get('success'): | |
| print(f"نوع التلخيص: {data.get('type')}") | |
| if 'summary' in data: | |
| summary = data['summary'] | |
| print(f"\nالملخص:") | |
| print("-" * 30) | |
| print(summary) | |
| print("-" * 30) | |
| return True | |
| else: | |
| print("⚠️ لا يوجد ملخص في الرد") | |
| return False | |
| else: | |
| print(f"❌ فشل التلخيص: {data.get('error')}") | |
| return False | |
| else: | |
| print(f"❌ خطأ HTTP: {response.status_code}") | |
| print(f"الرد: {response.text}") | |
| return False | |
| except Exception as e: | |
| print(f"❌ خطأ في الطلب: {e}") | |
| return False | |
| def test_cors_manually(): | |
| """اختبار CORS يدوياً""" | |
| print("\n🔧 اختبار CORS...") | |
| try: | |
| # طلب OPTIONS أولاً | |
| options_response = requests.options('http://localhost:5001/summarize') | |
| print(f"OPTIONS Status: {options_response.status_code}") | |
| cors_origin = options_response.headers.get('Access-Control-Allow-Origin') | |
| print(f"CORS Origin: '{cors_origin}'") | |
| if cors_origin == '*': | |
| print("✅ CORS صحيح") | |
| return True | |
| else: | |
| print(f"❌ مشكلة CORS: {cors_origin}") | |
| return False | |
| except Exception as e: | |
| print(f"❌ خطأ في اختبار CORS: {e}") | |
| return False | |
| if __name__ == "__main__": | |
| print("🚀 اختبار زر التلخيص المحدث") | |
| print("=" * 50) | |
| # اختبار CORS | |
| cors_ok = test_cors_manually() | |
| if cors_ok: | |
| # اختبار التلخيص | |
| summary_ok = test_summary_button() | |
| if summary_ok: | |
| print("\n🎉 جميع الاختبارات نجحت!") | |
| print("✅ زر التلخيص يعمل بشكل صحيح") | |
| else: | |
| print("\n❌ هناك مشكلة في التلخيص") | |
| else: | |
| print("\n❌ مشكلة CORS تمنع التلخيص") | |
| print("=" * 50) | |