File size: 1,262 Bytes
e9e471e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Test the updated image generation function
"""

from ai_services import generate_image_with_huggingface

def test_image_generation():
    """Test the updated image generation function"""
    print("🧪 Testing updated image generation function...")
    
    # Test with a simple topic
    result = generate_image_with_huggingface(
        "educational diagram of ancient persia", 
        "ancient persia", 
        "worksheet"
    )
    
    if result:
        print("✅ Image generation successful!")
        print(f"Result type: {type(result)}")
        print(f"Result length: {len(result)}")
        print(f"Result starts with: {result[:50]}...")
        
        # Save the result to a file
        if result.startswith("data:image"):
            with open("test_generated_image.png", "wb") as f:
                import base64
                image_data = result.split(",")[1]  # Remove data:image/png;base64, prefix
                f.write(base64.b64decode(image_data))
            print("✅ Image saved as test_generated_image.png")
        else:
            print(f"❌ Unexpected result format: {result[:100]}")
    else:
        print("❌ Image generation failed")

if __name__ == "__main__":
    test_image_generation()