# components/npcs.py :contentReference[oaicite:1]{index=1} :contentReference[oaicite:2]{index=2} :contentReference[oaicite:3]{index=3} import json import os :contentReference[oaicite:4]{index=4} # Reuse Alignment from main app (or import it) :contentReference[oaicite:5]{index=5} :contentReference[oaicite:6]{index=6} :contentReference[oaicite:7]{index=7} :contentReference[oaicite:8]{index=8} :contentReference[oaicite:9]{index=9} :contentReference[oaicite:10]{index=10} :contentReference[oaicite:11]{index=11} :contentReference[oaicite:12]{index=12} :contentReference[oaicite:13]{index=13} :contentReference[oaicite:14]{index=14} :contentReference[oaicite:15]{index=15} :contentReference[oaicite:16]{index=16} :contentReference[oaicite:17]{index=17} :contentReference[oaicite:18]{index=18} :contentReference[oaicite:19]{index=19} :contentReference[oaicite:20]{index=20} def npc_tab(): :contentReference[oaicite:21]{index=21} :contentReference[oaicite:22]{index=22} :contentReference[oaicite:23]{index=23} :contentReference[oaicite:24]{index=24} :contentReference[oaicite:25]{index=25} :contentReference[oaicite:26]{index=26} :contentReference[oaicite:27]{index=27} :contentReference[oaicite:28]{index=28} :contentReference[oaicite:29]{index=29} :contentReference[oaicite:30]{index=30} export_button = gr.Button("💾 Save NPC to Gallery") export_status = gr.Textbox(label="Export Status") def build_and_generate(name, race, occupation, alignment, sex): data = { "name": name, "race": race, "occupation": occupation, "alignment": alignment, "sex": sex } return generate_npc_image(data, art_style="Concept Art") gen_button.click( build_and_generate, inputs=[name, race, occupation, alignment, sex], outputs=npc_img ) export_button.click( lambda n, r, o, a, s, img: save_to_gallery( "npc", {"name": n, "race": r, "occupation": o, "alignment": a, "sex": s}, img ) or "✅ NPC saved!", inputs=[name, race, occupation, alignment, sex, npc_img], outputs=export_status )