File size: 3,613 Bytes
6609c06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/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)