salomonsky commited on
Commit
ccd05c2
·
verified ·
1 Parent(s): 20ffdd2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -45
app.py CHANGED
@@ -33,6 +33,26 @@ def enable_lora(lora_add):
33
  else:
34
  return lora_add
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  async def generate_image(
37
  prompt:str,
38
  model:str,
@@ -41,7 +61,8 @@ async def generate_image(
41
  height:int=1024,
42
  scales:float=3.5,
43
  steps:int=24,
44
- seed:int=-1):
 
45
 
46
  if seed == -1:
47
  seed = random.randint(0, MAX_SEED)
@@ -74,19 +95,28 @@ async def gen(
74
  scales:float=3.5,
75
  steps:int=24,
76
  seed:int=-1,
77
- progress=gr.Progress(track_tqdm=True)
 
78
  ):
79
  model = enable_lora(lora_add)
80
  print(model)
81
  image, seed = await generate_image(prompt,model,lora_word,width,height,scales,steps,seed)
82
- return image, seed
83
-
 
 
 
 
 
 
 
 
84
  with gr.Blocks(css=CSS, js=JS, theme="Nymbo/Nymbo_Theme") as demo:
85
  gr.HTML("<h1><center>Flux Lab Light</center></h1>")
86
  with gr.Row():
87
  with gr.Column(scale=4):
88
  with gr.Row():
89
- img = gr.Image(type="filepath", label='flux Generated Image', height=600)
90
  with gr.Row():
91
  prompt = gr.Textbox(label='Enter Your Prompt (Multi-Languages)', placeholder="Enter prompt...", scale=6)
92
  sendBtn = gr.Button(scale=1, variant='primary')
@@ -120,44 +150,57 @@ with gr.Blocks(css=CSS, js=JS, theme="Nymbo/Nymbo_Theme") as demo:
120
  step=1,
121
  value=24,
122
  )
123
- seed = gr.Slider(
124
- label="Seeds",
125
- minimum=-1,
126
- maximum=MAX_SEED,
127
- step=1,
128
- value=-1,
129
- )
130
- lora_add = gr.Textbox(
131
- label="Add Flux LoRA",
132
- info="Copy the HF LoRA model name here",
133
- lines=1,
134
- placeholder="Please use Warm status model",
135
- )
136
- lora_word = gr.Textbox(
137
- label="Add Flux LoRA Trigger Word",
138
- info="Add the Trigger Word",
139
- lines=1,
140
- value="",
141
- )
 
 
 
 
 
 
 
 
 
 
 
 
142
 
143
- gr.on(
144
- triggers=[
145
- prompt.submit,
146
- sendBtn.click,
147
- ],
148
- fn=gen,
149
- inputs=[
150
- prompt,
151
- lora_add,
152
- lora_word,
153
- width,
154
- height,
155
- scales,
156
- steps,
157
- seed
158
- ],
159
- outputs=[img, seed]
160
- )
161
-
162
- if __name__ == "__main__":
163
- demo.queue(api_open=False).launch(show_api=False, share=False)
 
 
33
  else:
34
  return lora_add
35
 
36
+ def get_upscale_finegrain(prompt, img_path, upscale_factor):
37
+ client = Client("finegrain/finegrain-image-enhancer")
38
+ result = client.predict(
39
+ input_image=handle_file(img_path),
40
+ prompt=prompt,
41
+ negative_prompt="",
42
+ seed=42,
43
+ upscale_factor=upscale_factor,
44
+ controlnet_scale=0.6,
45
+ controlnet_decay=1,
46
+ condition_scale=6,
47
+ tile_width=112,
48
+ tile_height=144,
49
+ denoise_strength=0.35,
50
+ num_inference_steps=18,
51
+ solver="DDIM",
52
+ api_name="/process"
53
+ )
54
+ return result[1]
55
+
56
  async def generate_image(
57
  prompt:str,
58
  model:str,
 
61
  height:int=1024,
62
  scales:float=3.5,
63
  steps:int=24,
64
+ seed:int=-1
65
+ ):
66
 
67
  if seed == -1:
68
  seed = random.randint(0, MAX_SEED)
 
95
  scales:float=3.5,
96
  steps:int=24,
97
  seed:int=-1,
98
+ progress=gr.Progress(track_tqdm=True),
99
+ upscale_factor:int=0
100
  ):
101
  model = enable_lora(lora_add)
102
  print(model)
103
  image, seed = await generate_image(prompt,model,lora_word,width,height,scales,steps,seed)
104
+ if upscale_factor != 0:
105
+ image = get_upscale_finegrain(prompt, image, upscale_factor)
106
+ return image, seed, image
107
+
108
+ def upscale_image(img_path, upscale_factor, prompt):
109
+ if upscale_factor == 0:
110
+ return img_path
111
+ else:
112
+ return get_upscale_finegrain(prompt, img_path, upscale_factor)
113
+
114
  with gr.Blocks(css=CSS, js=JS, theme="Nymbo/Nymbo_Theme") as demo:
115
  gr.HTML("<h1><center>Flux Lab Light</center></h1>")
116
  with gr.Row():
117
  with gr.Column(scale=4):
118
  with gr.Row():
119
+ img = gr.Image(type="filepath", label='Flux Generated Image', height=600)
120
  with gr.Row():
121
  prompt = gr.Textbox(label='Enter Your Prompt (Multi-Languages)', placeholder="Enter prompt...", scale=6)
122
  sendBtn = gr.Button(scale=1, variant='primary')
 
150
  step=1,
151
  value=24,
152
  )
153
+ seed = gr.Slider(
154
+ label="Seeds",
155
+ minimum=-1,
156
+ maximum=MAX_SEED,
157
+ step=1,
158
+ value=-1,
159
+ )
160
+ lora_add = gr.Textbox(
161
+ label="Add Flux LoRA",
162
+ info="Copy the HF LoRA model name here",
163
+ lines=1,
164
+ placeholder="Please use Warm status model",
165
+ )
166
+ lora_word = gr.Textbox(
167
+ label="Add Flux LoRA Trigger Word",
168
+ info="Add the Trigger Word",
169
+ lines=1,
170
+ value="",
171
+ )
172
+ upscale_factor = gr.Radio(
173
+ label="UpScale Factor",
174
+ choices=[
175
+ 0,
176
+ 2,
177
+ 3,
178
+ 4
179
+ ],
180
+ value=0,
181
+ scale=2
182
+ )
183
+ output_res = gr.Image(label="Upscaled Image")
184
 
185
+ gr.on(
186
+ triggers=[
187
+ prompt.submit,
188
+ sendBtn.click,
189
+ ],
190
+ fn=gen,
191
+ inputs=[
192
+ prompt,
193
+ lora_add,
194
+ lora_word,
195
+ width,
196
+ height,
197
+ scales,
198
+ steps,
199
+ seed,
200
+ upscale_factor
201
+ ],
202
+ outputs=[img, seed, output_res]
203
+ )
204
+
205
+ if name == "main":
206
+ demo.queue(api_open=False).launch(show_api=False, share=False)