ghmk commited on
Commit
7c6f253
·
1 Parent(s): 9769277

Add app.py and requirements.txt for CharacterForgePro

Browse files
Files changed (2) hide show
  1. app.py +112 -0
  2. requirements.txt +9 -0
app.py ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import random
4
+ import spaces
5
+ import torch
6
+ from diffusers import Flux2KleinPipeline
7
+
8
+ dtype = torch.bfloat16
9
+ device = "cuda" if torch.cuda.is_available() else "cpu"
10
+
11
+ pipe = Flux2KleinPipeline.from_pretrained("black-forest-labs/FLUX.2-klein-9B", torch_dtype=dtype).to(device)
12
+
13
+ MAX_SEED = np.iinfo(np.int32).max
14
+ MAX_IMAGE_SIZE = 2048
15
+
16
+ @spaces.GPU()
17
+ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, num_inference_steps=4, progress=gr.Progress(track_tqdm=True)):
18
+ if randomize_seed:
19
+ seed = random.randint(0, MAX_SEED)
20
+ generator = torch.Generator().manual_seed(seed)
21
+ image = pipe(
22
+ prompt=prompt,
23
+ width=width,
24
+ height=height,
25
+ num_inference_steps=num_inference_steps,
26
+ generator=generator,
27
+ guidance_scale=1.0
28
+ ).images[0]
29
+ return image, seed
30
+
31
+ examples = [
32
+ "character turnaround sheet, female warrior with red hair, front view, full body, white background",
33
+ "character turnaround sheet, male wizard with blue robes, front view, full body, white background",
34
+ "character turnaround sheet, female elf archer, front view, full body, white background",
35
+ ]
36
+
37
+ css="""
38
+ #col-container {
39
+ margin: 0 auto;
40
+ max-width: 520px;
41
+ }
42
+ """
43
+
44
+ with gr.Blocks(css=css) as demo:
45
+ with gr.Column(elem_id="col-container"):
46
+ gr.Markdown(f"""# CharacterForgePro
47
+ Generate character images using FLUX.2 klein 9B on Zero GPU.
48
+ """)
49
+
50
+ with gr.Row():
51
+ prompt = gr.Text(
52
+ label="Prompt",
53
+ show_label=False,
54
+ max_lines=1,
55
+ placeholder="Enter your prompt",
56
+ container=False,
57
+ )
58
+ run_button = gr.Button("Run", scale=0)
59
+
60
+ result = gr.Image(label="Result", show_label=False)
61
+
62
+ with gr.Accordion("Advanced Settings", open=False):
63
+ seed = gr.Slider(
64
+ label="Seed",
65
+ minimum=0,
66
+ maximum=MAX_SEED,
67
+ step=1,
68
+ value=0,
69
+ )
70
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
71
+
72
+ with gr.Row():
73
+ width = gr.Slider(
74
+ label="Width",
75
+ minimum=256,
76
+ maximum=MAX_IMAGE_SIZE,
77
+ step=32,
78
+ value=1024,
79
+ )
80
+ height = gr.Slider(
81
+ label="Height",
82
+ minimum=256,
83
+ maximum=MAX_IMAGE_SIZE,
84
+ step=32,
85
+ value=1024,
86
+ )
87
+
88
+ with gr.Row():
89
+ num_inference_steps = gr.Slider(
90
+ label="Number of inference steps",
91
+ minimum=1,
92
+ maximum=50,
93
+ step=1,
94
+ value=4,
95
+ )
96
+
97
+ gr.Examples(
98
+ examples=examples,
99
+ fn=infer,
100
+ inputs=[prompt],
101
+ outputs=[result, seed],
102
+ cache_examples="lazy"
103
+ )
104
+
105
+ gr.on(
106
+ triggers=[run_button.click, prompt.submit],
107
+ fn=infer,
108
+ inputs=[prompt, seed, randomize_seed, width, height, num_inference_steps],
109
+ outputs=[result, seed]
110
+ )
111
+
112
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ accelerate>=1.12.0
2
+ diffusers>=0.37.0
3
+ gradio>=6.2.0
4
+ torch>=2.5.0
5
+ transformers>=5.0.0
6
+ sentencepiece
7
+ numpy
8
+ Pillow
9
+ invisible_watermark