hotbiz commited on
Commit
ef59a8c
1 Parent(s): d65a30e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -119
app.py CHANGED
@@ -1,121 +1,3 @@
1
  import gradio as gr
2
- import numpy as np
3
- import random
4
- import spaces
5
- import torch
6
- from diffusers import DiffusionPipeline
7
 
8
- dtype = torch.bfloat16
9
- device = "cuda" if torch.cuda.is_available() else "cpu"
10
-
11
- pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", 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=0.0
28
- ).images[0]
29
- return image, seed
30
-
31
- examples = [
32
- "Create a vibrant and festive scene of an Indonesian Independence Day parade celebrating the 79th anniversary. The parade features a diverse array of colorful floats, traditional costumes from various regions, and enthusiastic participants waving the Indonesian flag. The background showcases iconic Indonesian landmarks, such as the Monas (National Monument) and lush tropical scenery. The atmosphere is filled with joy and patriotism, with crowds of people cheering along the streets, red and white decorations everywhere, and children holding balloons and small flags. The sky is bright with a few clouds, symbolizing a hopeful and united nation.",
33
- "Depict a scene of a beautiful 20-year-old girl named Dewi, with a sweet and gentle face, shopping at the bustling Gombong morning market. She is dressed in stylish, revealing attire that accentuates her allure. Dewi moves gracefully among the stalls, attracting the admiring gazes of all the men around her. The market is filled with vibrant activity, with vendors selling fresh produce, local delicacies, and various goods. The atmosphere is lively, with bright sunlight casting soft shadows, and Dewi stands out as the captivating focal point of the scene.",
34
- ]
35
-
36
- css="""
37
- #col-container {
38
- margin: 0 auto;
39
- max-width: 520px;
40
- }
41
- """
42
-
43
- with gr.Blocks(css=css) as demo:
44
-
45
- with gr.Column(elem_id="col-container"):
46
- gr.Markdown(f"""# FLUX.1 [schnell]
47
- 12B param rectified flow transformer distilled from [FLUX.1 [pro]](https://blackforestlabs.ai/) for 4 step generation
48
- [[blog](https://blackforestlabs.ai/announcing-black-forest-labs/)] [[model](https://huggingface.co/black-forest-labs/FLUX.1-schnell)]
49
- """)
50
-
51
- with gr.Row():
52
-
53
- prompt = gr.Text(
54
- label="Prompt",
55
- show_label=False,
56
- max_lines=1,
57
- placeholder="Enter your prompt",
58
- container=False,
59
- )
60
-
61
- run_button = gr.Button("Run", scale=0)
62
-
63
- result = gr.Image(label="Result", show_label=False)
64
-
65
- with gr.Accordion("Advanced Settings", open=False):
66
-
67
- seed = gr.Slider(
68
- label="Seed",
69
- minimum=0,
70
- maximum=MAX_SEED,
71
- step=1,
72
- value=0,
73
- )
74
-
75
- randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
76
-
77
- with gr.Row():
78
-
79
- width = gr.Slider(
80
- label="Width",
81
- minimum=256,
82
- maximum=MAX_IMAGE_SIZE,
83
- step=32,
84
- value=1024,
85
- )
86
-
87
- height = gr.Slider(
88
- label="Height",
89
- minimum=256,
90
- maximum=MAX_IMAGE_SIZE,
91
- step=32,
92
- value=1024,
93
- )
94
-
95
- with gr.Row():
96
-
97
-
98
- num_inference_steps = gr.Slider(
99
- label="Number of inference steps",
100
- minimum=1,
101
- maximum=50,
102
- step=1,
103
- value=4,
104
- )
105
-
106
- gr.Examples(
107
- examples = examples,
108
- fn = infer,
109
- inputs = [prompt],
110
- outputs = [result, seed],
111
- cache_examples="lazy"
112
- )
113
-
114
- gr.on(
115
- triggers=[run_button.click, prompt.submit],
116
- fn = infer,
117
- inputs = [prompt, seed, randomize_seed, width, height, num_inference_steps],
118
- outputs = [result, seed]
119
- )
120
-
121
- demo.launch()
 
1
  import gradio as gr
 
 
 
 
 
2
 
3
+ gr.load("models/black-forest-labs/FLUX.1-schnell").launch()