pepper13 commited on
Commit
147b85b
1 Parent(s): c5ea3ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -26
app.py CHANGED
@@ -4,59 +4,46 @@ import random
4
  from diffusers import DiffusionPipeline
5
  import torch
6
 
7
- device = "cuda" if torch.cuda.is_available() else "cpu"
 
8
  model_repo_id = "black-forest-labs/FLUX.1-dev"
9
 
10
- torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
11
  pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype).to(device)
12
  pipe.load_lora_weights("pepper13/flux-anime")
13
 
14
- MAX_SEED = np.iinfo(np.int32).max
15
- MAX_IMAGE_SIZE = 1024
16
-
17
- def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, 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
-
22
  image = pipe(
23
- prompt=prompt,
24
- negative_prompt=negative_prompt,
25
  guidance_scale=guidance_scale,
26
  num_inference_steps=num_inference_steps,
27
  width=width,
28
- height=height,
29
- generator=generator
30
  ).images[0]
31
 
32
- return image, seed
33
 
34
  with gr.Blocks() as demo:
35
  with gr.Column(elem_id="col-container"):
36
  with gr.Row():
37
- prompt = gr.Text(label="Prompt", show_label=False, max_lines=1, placeholder="Enter your prompt", container=False)
38
- run_button = gr.Button("Run", scale=0)
39
 
40
  result = gr.Image(label="Result", show_label=False)
41
 
42
  with gr.Accordion("Advanced Settings", open=False):
43
- negative_prompt = gr.Text(label="Negative prompt", max_lines=1, placeholder="Enter a negative prompt", visible=False)
44
- seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0)
45
- randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
46
-
47
  with gr.Row():
48
- width = gr.Slider(label="Width", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=512)
49
- height = gr.Slider(label="Height", minimum=256, maximum=MAX_IMAGE_SIZE, step=32, value=512)
50
 
51
  with gr.Row():
52
- guidance_scale = gr.Slider(label="Guidance scale", minimum=0.0, maximum=10.0, step=0.1, value=0.0)
53
  num_inference_steps = gr.Slider(label="Number of inference steps", minimum=1, maximum=50, step=1, value=20)
54
 
55
  gr.on(
56
  triggers=[run_button.click, prompt.submit],
57
  fn=infer,
58
- inputs=[prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
59
- outputs=[result, seed]
60
  )
61
 
62
  demo.launch()
 
4
  from diffusers import DiffusionPipeline
5
  import torch
6
 
7
+ torch_dtype, device = torch.float16, torch.device("cuda") if torch.cuda.is_available() else torch.float32, torch.device("cpu")
8
+
9
  model_repo_id = "black-forest-labs/FLUX.1-dev"
10
 
 
11
  pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype).to(device)
12
  pipe.load_lora_weights("pepper13/flux-anime")
13
 
14
+ def infer(prompt, randomize_seed, width, height, guidance_scale, num_inference_steps):
 
 
 
 
 
 
 
15
  image = pipe(
16
+ prompt=prompt,
 
17
  guidance_scale=guidance_scale,
18
  num_inference_steps=num_inference_steps,
19
  width=width,
20
+ height=height
 
21
  ).images[0]
22
 
23
+ return image
24
 
25
  with gr.Blocks() as demo:
26
  with gr.Column(elem_id="col-container"):
27
  with gr.Row():
28
+ prompt = gr.Text(label="Prompt", show_label=False, placeholder="Enter your prompt")
29
+ run_button = gr.Button("Generate", scale=0)
30
 
31
  result = gr.Image(label="Result", show_label=False)
32
 
33
  with gr.Accordion("Advanced Settings", open=False):
 
 
 
 
34
  with gr.Row():
35
+ width = gr.Slider(label="Width", minimum=256, maximum=1024, step=32, value=512)
36
+ height = gr.Slider(label="Height", minimum=256, maximum=1024, step=32, value=512)
37
 
38
  with gr.Row():
39
+ guidance_scale = gr.Slider(label="Guidance scale", minimum=0.1, maximum=10.0, step=0.1, value=7.0)
40
  num_inference_steps = gr.Slider(label="Number of inference steps", minimum=1, maximum=50, step=1, value=20)
41
 
42
  gr.on(
43
  triggers=[run_button.click, prompt.submit],
44
  fn=infer,
45
+ inputs=[prompt, negative_prompt, width, height, guidance_scale, num_inference_steps],
46
+ outputs=[result]
47
  )
48
 
49
  demo.launch()