GenTex_AI / test_app.py
Afnaan04's picture
Upload folder using huggingface_hub
2134839 verified
Raw
History Blame Contribute Delete
1.44 kB
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()