pepper13 commited on
Commit
abd4d0f
1 Parent(s): ee1a231

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ 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()