import json, os, shutil, sys, time from gradio_client import Client items = json.load(open('/workspaces/studio/items.json')) STYLE = (", candid photo taken on an iPhone 15, vertical, realistic, natural colors, natural lighting, " "everyday life, authentic, sharp focus, subtle film grain, the main subject in the lower half of the frame") seeds = [int(s) for s in sys.argv[1].split(',')] only = sys.argv[2].split(',') if len(sys.argv) > 2 else None os.makedirs('/tmp/work/hf', exist_ok=True) c = Client("black-forest-labs/FLUX.1-schnell") for it in items: if only and it['id'] not in only: continue for sd in seeds: out = f"/tmp/work/hf/{it['id']}_{sd}.webp" if os.path.exists(out): continue for a in range(40): try: r = c.predict(prompt=it['prompt'] + STYLE, seed=sd, randomize_seed=False, width=1152, height=1536, num_inference_steps=4, api_name="/infer") shutil.copy(r[0], out) print('ok', out, flush=True) break except Exception as e: print('err', out, str(e)[:200], flush=True) time.sleep(150 if "quota" in str(e) else 10)