|
|
|
|
|
""" |
|
|
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...") |
|
|
|
|
|
|
|
|
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") |
|
|
|
|
|
|
|
|
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") |
|
|
|
|
|
|
|
|
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") |
|
|
|
|
|
|
|
|
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") |
|
|
|
|
|
|
|
|
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() |