| import requests | |
| import base64 | |
| from PIL import Image | |
| import io | |
| URL = "http://127.0.0.1:5000/generate" | |
| def test_generation(): | |
| print(f"Testing {URL}...") | |
| try: | |
| # Test Wood Texture | |
| payload = { | |
| "texture_type": "wood", | |
| "seed": 42, | |
| "creativity": 1.0 | |
| } | |
| response = requests.post(URL, data=payload) | |
| if response.status_code == 200: | |
| data = response.json() | |
| if "image" in data: | |
| print("β Request successful. Image data received.") | |
| # Decode image | |
| img_data = data["image"].split(",")[1] | |
| img_bytes = base64.b64decode(img_data) | |
| img = Image.open(io.BytesIO(img_bytes)) | |
| img.save("test_output.png") | |
| print(f"β Image saved to test_output.png (Size: {img.size})") | |
| return True | |
| else: | |
| print("β Response missing 'image' field:", data) | |
| else: | |
| print(f"β Request failed with status {response.status_code}: {response.text}") | |
| except requests.exceptions.ConnectionError: | |
| print("β Could not connect to the server. Is app.py running?") | |
| except Exception as e: | |
| print(f"β Error: {e}") | |
| return False | |
| if __name__ == "__main__": | |
| test_generation() | |