"""Regenerate one vocabulary picture with an explicit cartoon prompt.
python tools/redo_one.py <key> "<subject>" [--people]"""
import json, sys, urllib.request
key, subject, people = sys.argv[1], sys.argv[2], "--people" in sys.argv
style = ("Flat vector cartoon for a children's picture dictionary, like a picture-book drawing: rounded shapes, thick clean dark outlines, "
         "bright cheerful flat colours, simple shading, plain soft cream background. This MUST be a cartoon drawing, NOT a photograph, "
         "NOT photo-realistic, NOT a 3D render. No text, no letters, no numbers.")
if people:
    prompt = f"Children's picture-dictionary cartoon: {subject}. Any children are eight years old, drawn as cute cartoon kids. {style}"
else:
    prompt = f"Children's picture-dictionary cartoon: {subject}. ONLY this, centred, no people, no hands. {style}"
body = json.dumps(dict(key="VOCAB", file=key + ".png", course="Yaseen-French2", prompt=prompt, save=True, overwrite=True)).encode()
req = urllib.request.Request("http://localhost:8879/api/generate", data=body, headers={"Content-Type": "application/json"})
try:
    d = json.load(urllib.request.urlopen(req, timeout=500))
    print(key, d.get("detail") or ("ok %ss" % d.get("seconds")), flush=True)
except Exception as e:
    print(key, "ERROR", e, flush=True)
