cora / tests /repro_error.py
tokgae's picture
Upload folder using huggingface_hub
38ab39c verified
import os
import io
import sys
import traceback
from PIL import Image
from cora_engine import CoraEngine
from dotenv import load_dotenv
def test_engine_directly():
load_dotenv()
print("Initializing CoraEngine...")
try:
engine = CoraEngine()
except Exception:
print("Failed to init engine:")
traceback.print_exc()
return
prompt = "A Roman gladiator in the Colosseum, fine art"
print(f"Generating for: '{prompt}'...")
try:
result = engine.generate_from_text(prompt)
print(f"Generation result type: {type(result)}")
if result:
print(f"Image Mode: {result.mode}")
print(f"Image Size: {result.size}")
print(f"Image Format: {result.format}")
img_bytes = io.BytesIO()
result.save(img_bytes, format="PNG")
print(f"✅ Successfully saved result to PNG. Size: {len(img_bytes.getvalue())} bytes")
# Try to re-open the buffer to see if it fails like the user-reported error
try:
img_bytes.seek(0)
re_opened = Image.open(img_bytes)
re_opened.verify()
print("✅ Buffer verification successful.")
except Exception as inner_e:
print(f"❌ BUFFER VERIFICATION FAILED: {inner_e}")
except Exception as e:
print("\n❌ CATCHING ERROR:")
print(f"Error Message: {e}")
print("\nFULL TRACEBACK:")
traceback.print_exc()
if __name__ == "__main__":
# Ensure current dir is in path
sys.path.append(os.getcwd())
test_engine_directly()