File size: 2,372 Bytes
ab792dc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Test script pour vérifier que l'application HF fonctionne correctement
"""

from bayesian_network_interface import AutonomyBayesianNetwork

def test_hf_deployment():
    """Test complet de l'application HF"""
    print("🧪 Testing HuggingFace deployment...")

    # Test 1: Chargement du réseau
    print("1. Loading network...")
    bn = AutonomyBayesianNetwork()
    assert bn.pgmpy_model is not None, "Network failed to load"
    print(f"   ✅ Network loaded with {len(list(bn.pgmpy_model.nodes()))} variables")

    # Test 2: Structure du réseau
    print("2. Testing network structure...")
    structure = bn.get_network_structure()
    assert len(structure['nodes']) == 12, f"Expected 12 nodes, got {len(structure['nodes'])}"
    assert len(structure['edges']) == 22, f"Expected 22 edges, got {len(structure['edges'])}"
    print(f"   ✅ Structure: {len(structure['nodes'])} nodes, {len(structure['edges'])} edges")

    # Test 3: Inférence
    print("3. Testing inference...")
    result = bn.perform_inference_pgmpy({'Age': 'age_70_79', 'Sex': 'female'}, ['Global_Autonomy'])
    assert not result.empty, "Inference failed"
    assert len(result) == 4, f"Expected 4 states, got {len(result)}"
    print(f"   ✅ Inference working: {len(result)} probability states")

    # Test 4: Facteurs influents
    print("4. Testing influential factors...")
    factors = bn.get_most_influential_factors()
    assert len(factors) > 0, "No influential factors found"
    print(f"   ✅ Found {len(factors)} influential factors")

    # Test 5: Recommandations
    print("5. Testing recommendations...")
    profile = {'Age': 'age_80_89', 'Sex': 'male', 'Education_Level': 'primary_or_below'}
    recommendations = bn.generate_recommendations(profile)
    assert len(recommendations) >= 0, "Recommendations failed"
    print(f"   ✅ Generated {len(recommendations)} recommendations")

    print("\n🎉 All tests passed! HuggingFace deployment is ready.")
    print("\n📊 Sample results:")
    print(f"   - Autonomy probability for 70-79 female: {result.iloc[0]['Probability']:.1%}")
    print(f"   - Most influential factor: {factors[0][0]} ({factors[0][1]:.1%} impact)")
    if recommendations:
        print(f"   - Top recommendation: {recommendations[0]['recommendation'][:50]}...")

if __name__ == "__main__":
    test_hf_deployment()