Amal360 commited on
Commit
40897cf
·
verified ·
1 Parent(s): 2458152

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +153 -0
app.py ADDED
@@ -0,0 +1,153 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import random
4
+
5
+ # import spaces #[uncomment to use ZeroGPU]
6
+ from diffusers import DiffusionPipeline
7
+ import torch
8
+
9
+ device = "cuda" if torch.cuda.is_available() else "cpu"
10
+ model_repo_id = "black-forest-labs/FLUX.1-dev" # Replace to the model you would like to use
11
+
12
+ if torch.cuda.is_available():
13
+ torch_dtype = torch.float16
14
+ else:
15
+ torch_dtype = torch.float32
16
+
17
+ pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
18
+ pipe = pipe.to(device)
19
+
20
+ MAX_SEED = np.iinfo(np.int32).max
21
+ MAX_IMAGE_SIZE = 1024
22
+
23
+
24
+ # @spaces.GPU #[uncomment to use ZeroGPU]
25
+ def infer(
26
+ prompt,
27
+ negative_prompt,
28
+ seed,
29
+ randomize_seed,
30
+ width,
31
+ height,
32
+ guidance_scale,
33
+ num_inference_steps,
34
+ progress=gr.Progress(track_tqdm=True),
35
+ ):
36
+ if randomize_seed:
37
+ seed = random.randint(0, MAX_SEED)
38
+
39
+ generator = torch.Generator().manual_seed(seed)
40
+
41
+ image = pipe(
42
+ prompt=prompt,
43
+ negative_prompt=negative_prompt,
44
+ guidance_scale=guidance_scale,
45
+ num_inference_steps=num_inference_steps,
46
+ width=width,
47
+ height=height,
48
+ generator=generator,
49
+ ).images[0]
50
+
51
+ return image, seed
52
+
53
+
54
+ examples = [
55
+ "A delicious ceviche cheesecake slice",
56
+ "A cat is flying in the sky",
57
+ ]
58
+
59
+ css = """
60
+ #col-container {
61
+ margin: 0 auto;
62
+ max-width: 640px;
63
+ }
64
+ """
65
+
66
+ with gr.Blocks(css=css) as demo:
67
+ with gr.Column(elem_id="col-container"):
68
+ gr.Markdown("AiaRTIST By AKP.AI")
69
+
70
+ with gr.Row():
71
+ prompt = gr.Text(
72
+ label="Prompt",
73
+ show_label=False,
74
+ max_lines=1,
75
+ placeholder="Enter your prompt",
76
+ container=False,
77
+ )
78
+
79
+ run_button = gr.Button("Run", scale=0, variant="primary")
80
+
81
+ result = gr.Image(label="Result", show_label=False)
82
+
83
+ with gr.Accordion("Advanced Settings", open=False):
84
+ negative_prompt = gr.Text(
85
+ label="Negative prompt",
86
+ max_lines=1,
87
+ placeholder="Enter a negative prompt",
88
+ visible=False,
89
+ )
90
+
91
+ seed = gr.Slider(
92
+ label="Seed",
93
+ minimum=0,
94
+ maximum=MAX_SEED,
95
+ step=1,
96
+ value=0,
97
+ )
98
+
99
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
100
+
101
+ with gr.Row():
102
+ width = gr.Slider(
103
+ label="Width",
104
+ minimum=256,
105
+ maximum=MAX_IMAGE_SIZE,
106
+ step=32,
107
+ value=1024, # Replace with defaults that work for your model
108
+ )
109
+
110
+ height = gr.Slider(
111
+ label="Height",
112
+ minimum=256,
113
+ maximum=MAX_IMAGE_SIZE,
114
+ step=32,
115
+ value=1024, # Replace with defaults that work for your model
116
+ )
117
+
118
+ with gr.Row():
119
+ guidance_scale = gr.Slider(
120
+ label="Guidance scale",
121
+ minimum=0.0,
122
+ maximum=10.0,
123
+ step=0.1,
124
+ value=0.0, # Replace with defaults that work for your model
125
+ )
126
+
127
+ num_inference_steps = gr.Slider(
128
+ label="Number of inference steps",
129
+ minimum=1,
130
+ maximum=50,
131
+ step=1,
132
+ value=2, # Replace with defaults that work for your model
133
+ )
134
+
135
+ gr.Examples(examples=examples, inputs=[prompt])
136
+ gr.on(
137
+ triggers=[run_button.click, prompt.submit],
138
+ fn=infer,
139
+ inputs=[
140
+ prompt,
141
+ negative_prompt,
142
+ seed,
143
+ randomize_seed,
144
+ width,
145
+ height,
146
+ guidance_scale,
147
+ num_inference_steps,
148
+ ],
149
+ outputs=[result, seed],
150
+ )
151
+
152
+ if __name__ == "__main__":
153
+ demo.launch()