multimodalart HF Staff commited on
Commit
64bd8d9
·
verified ·
1 Parent(s): 1d74013

Upload folder using huggingface_hub

Browse files
.gitattributes CHANGED
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ anime_1.jpg filter=lfs diff=lfs merge=lfs -text
37
+ example_ref_2.jpg filter=lfs diff=lfs merge=lfs -text
38
+ example_ref_3.jpg filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,13 +1,18 @@
1
  ---
2
- title: Charactersheet Lora Demo
3
- emoji: 🦀
4
- colorFrom: blue
5
- colorTo: yellow
6
  sdk: gradio
7
  sdk_version: 6.22.0
8
- python_version: '3.12'
9
  app_file: app.py
10
- pinned: false
 
 
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
1
  ---
2
+ title: CharacterSheet LoRA Demo
3
+ emoji: 🧑‍🎨
4
+ colorFrom: indigo
5
+ colorTo: pink
6
  sdk: gradio
7
  sdk_version: 6.22.0
 
8
  app_file: app.py
9
+ short_description: Multi-view character sheet from one image (FLUX.2 LoRA)
10
+ python_version: "3.12"
11
+ startup_duration_timeout: 1h
12
  ---
13
 
14
+ # CharacterSheet LoRA Demo
15
+
16
+ This Space demonstrates the [CharacterSheet](https://huggingface.co/Alissonerdx/CharacterSheet) QuadView LoRA applied on top of [FLUX.2 Klein 9B](https://huggingface.co/black-forest-labs/FLUX.2-klein-9B).
17
+
18
+ Upload a clear, well-framed image of a character and the model produces a multi-view character sheet: a face close-up plus front, side, and back full-body views on a single 1536×1024 sheet.
anime_1.jpg ADDED

Git LFS Details

  • SHA256: 2d9a4aee6e9ccf5e2b57653622ab92c3d16acaa7c6d12054974870e162321899
  • Pointer size: 131 Bytes
  • Size of remote file: 122 kB
app.py ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ os.environ.setdefault("PYTORCH_CUDA_ALLOC_CONF", "expandable_segments:True")
4
+
5
+ import spaces # MUST come before torch / diffusers / transformers
6
+ import torch
7
+ import gradio as gr
8
+ import numpy as np
9
+ import random
10
+ from PIL import Image
11
+ from diffusers import Flux2KleinPipeline
12
+
13
+ # ---------------------------------------------------------------------------
14
+ # Model setup
15
+ # ---------------------------------------------------------------------------
16
+ MODEL_ID = "black-forest-labs/FLUX.2-klein-9B" # distilled, 4-step base
17
+ LORA_REPO = "Alissonerdx/CharacterSheet"
18
+ LORA_WEIGHT = "QuadView_klein9b_v1.safetensors" # FLUX.2 Klein 9B QuadView LoRA
19
+
20
+ TRIGGER_PROMPT = (
21
+ "Convert the character in the image to a Character Sheet showing a face "
22
+ "close-up, front, side and back full body views"
23
+ )
24
+
25
+ dtype = torch.bfloat16
26
+ device = "cuda"
27
+
28
+ print("Loading FLUX.2 Klein 9B pipeline...")
29
+ pipe = Flux2KleinPipeline.from_pretrained(MODEL_ID, torch_dtype=dtype).to("cuda")
30
+ print("Loading CharacterSheet QuadView LoRA...")
31
+ pipe.load_lora_weights(LORA_REPO, weight_name=LORA_WEIGHT)
32
+ print("LoRA loaded. Ready.")
33
+
34
+ MAX_SEED = np.iinfo(np.int32).max
35
+
36
+
37
+ @spaces.GPU(duration=120)
38
+ def generate(
39
+ reference_image,
40
+ prompt=TRIGGER_PROMPT,
41
+ num_inference_steps=8,
42
+ guidance_scale=1.0,
43
+ lora_strength=1.0,
44
+ seed=42,
45
+ randomize_seed=True,
46
+ width=1536,
47
+ height=1024,
48
+ progress=gr.Progress(track_tqdm=True),
49
+ ):
50
+ """Generate a multi-view character sheet from a single reference image.
51
+
52
+ Uses the CharacterSheet QuadView LoRA on FLUX.2 Klein 9B to turn one
53
+ character photo into a face close-up plus front, side, and back full-body
54
+ views arranged on a single sheet.
55
+
56
+ Args:
57
+ reference_image: A clear, well-framed image of the character.
58
+ prompt: Instruction caption; defaults to the QuadView trigger.
59
+ num_inference_steps: Sampling steps (8 is the recommended starting point).
60
+ guidance_scale: CFG scale (1.0 for distilled Klein 9B).
61
+ lora_strength: LoRA scale (1.0 = full strength).
62
+ seed: RNG seed for reproducibility.
63
+ randomize_seed: Use a random seed instead of the provided one.
64
+ width: Output width in pixels.
65
+ height: Output height in pixels.
66
+ """
67
+ if reference_image is None:
68
+ raise gr.Error("Please upload a reference character image.")
69
+
70
+ if randomize_seed:
71
+ seed = random.randint(0, MAX_SEED)
72
+ seed = int(seed)
73
+
74
+ # Apply / adjust LoRA strength
75
+ pipe.set_adapters(["default"], adapter_weights=[float(lora_strength)])
76
+
77
+ generator = torch.Generator(device=device).manual_seed(seed)
78
+
79
+ img = pipe(
80
+ image=reference_image,
81
+ prompt=prompt,
82
+ width=int(width),
83
+ height=int(height),
84
+ num_inference_steps=int(num_inference_steps),
85
+ guidance_scale=float(guidance_scale),
86
+ generator=generator,
87
+ ).images[0]
88
+
89
+ return img, seed
90
+
91
+
92
+ # ---------------------------------------------------------------------------
93
+ # UI
94
+ # ---------------------------------------------------------------------------
95
+ CSS = """
96
+ #col-container { max-width: 1100px; margin: 0 auto; }
97
+ .dark .gradio-container { color: var(--body-text-color); }
98
+ """
99
+
100
+ with gr.Blocks(theme=gr.themes.Citrus(), css=CSS) as demo:
101
+ with gr.Column(elem_id="col-container"):
102
+ gr.Markdown(
103
+ """# CharacterSheet LoRA — QuadView on FLUX.2 Klein 9B
104
+ Turn a single character photo into a multi-view reference sheet (face close-up + front, side, and back full-body views) using the [CharacterSheet LoRA](https://huggingface.co/Alissonerdx/CharacterSheet) on [FLUX.2 Klein 9B](https://huggingface.co/black-forest-labs/FLUX.2-klein-9B)."""
105
+ )
106
+
107
+ with gr.Row():
108
+ with gr.Column():
109
+ reference_image = gr.Image(
110
+ label="Reference character image",
111
+ type="pil",
112
+ sources=["upload", "clipboard"],
113
+ )
114
+ run_button = gr.Button("Generate character sheet", variant="primary")
115
+
116
+ with gr.Accordion("Advanced settings", open=False):
117
+ prompt = gr.Textbox(
118
+ label="Instruction prompt",
119
+ value=TRIGGER_PROMPT,
120
+ lines=3,
121
+ info="The trigger caption for the QuadView LoRA. Edit only if you know what you're doing.",
122
+ )
123
+ with gr.Row():
124
+ num_inference_steps = gr.Slider(
125
+ label="Steps", minimum=1, maximum=20, step=1, value=8,
126
+ info="8 is the recommended starting point for Klein 9B QuadView.",
127
+ )
128
+ guidance_scale = gr.Slider(
129
+ label="CFG scale", minimum=0.0, maximum=10.0, step=0.1, value=1.0,
130
+ )
131
+ lora_strength = gr.Slider(
132
+ label="LoRA strength", minimum=0.0, maximum=2.0, step=0.05, value=1.0,
133
+ )
134
+ with gr.Row():
135
+ seed = gr.Slider(
136
+ label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=42,
137
+ )
138
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
139
+ with gr.Row():
140
+ width = gr.Slider(
141
+ label="Width", minimum=512, maximum=2048, step=16, value=1536,
142
+ )
143
+ height = gr.Slider(
144
+ label="Height", minimum=512, maximum=2048, step=16, value=1024,
145
+ )
146
+
147
+ with gr.Column():
148
+ result = gr.Image(label="Character sheet", show_label=True)
149
+
150
+ gr.Examples(
151
+ examples=[
152
+ ["example_ref.jpg", TRIGGER_PROMPT, 8, 1.0, 1.0, 42, True, 1536, 1024],
153
+ ["example_ref_2.jpg", TRIGGER_PROMPT, 8, 1.0, 1.0, 42, True, 1536, 1024],
154
+ ["example_ref_3.jpg", TRIGGER_PROMPT, 8, 1.0, 1.0, 42, True, 1536, 1024],
155
+ ],
156
+ inputs=[
157
+ reference_image, prompt, num_inference_steps, guidance_scale,
158
+ lora_strength, seed, randomize_seed, width, height,
159
+ ],
160
+ outputs=[result, seed],
161
+ fn=generate,
162
+ cache_examples=True,
163
+ cache_mode="lazy",
164
+ )
165
+
166
+ gr.on(
167
+ triggers=[run_button.click],
168
+ fn=generate,
169
+ inputs=[
170
+ reference_image, prompt, num_inference_steps, guidance_scale,
171
+ lora_strength, seed, randomize_seed, width, height,
172
+ ],
173
+ outputs=[result, seed],
174
+ api_name="generate",
175
+ )
176
+
177
+ demo.launch(mcp_server=True)
ballerina.jpg ADDED
businessman_arms_crossed.jpg ADDED
example_ref.jpg ADDED
example_ref_2.jpg ADDED

Git LFS Details

  • SHA256: c49064ebe24a90b84fd4dce199a79bf698e21762c04801be4336f98216ff92c2
  • Pointer size: 131 Bytes
  • Size of remote file: 168 kB
example_ref_3.jpg ADDED

Git LFS Details

  • SHA256: 41d20e4728d27c0e1563bc541126b9c94c1e054a0524569bfa8c4ef91e0f3fea
  • Pointer size: 131 Bytes
  • Size of remote file: 131 kB
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ git+https://github.com/huggingface/diffusers.git
2
+ transformers
3
+ accelerate
4
+ safetensors
5
+ sentencepiece