File size: 2,488 Bytes
b197a8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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
        )