SunderAli17 commited on
Commit
1fbb135
1 Parent(s): 512dfd4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -74
app.py CHANGED
@@ -151,21 +151,39 @@ def generate_image(
151
  img = Image.fromarray((127.5 * (x + 1.0)).cpu().byte().numpy())
152
  return img, str(opts.seed), flux_generator.toonmage_model.debug_img_list
153
 
154
- _HEADER_ = '''
155
- <div style="text-align: center; max-width: 650px; margin: 0 auto;">
156
- <h1 style="font-size: 2.5rem; font-weight: 700; margin-bottom: 1rem; display: contents;">ToonMage for FLUX</h1>
157
- </div>
158
- ❗️❗️❗️**Tips:**
159
- - `timestep to start inserting ID:` The smaller the value, the higher the fidelity, but the lower the editability; the higher the value, the lower the fidelity, but the higher the editability. **The recommended range for this value is between 0 and 4**. For photorealistic scenes, we recommend using 4; for stylized scenes, we recommend using 0-1. If you are not satisfied with the similarity, you can lower this value; conversely, if you are not satisfied with the editability, you can increase this value.
160
- - `true CFG scale:` In most scenarios, it is recommended to use a fake CFG, i.e., setting the true CFG scale to 1, and just adjusting the guidance scale. This is also more efficiency. However, in a few cases, utilizing a true CFG can yield better results.
161
- - we provide some examples in the bottom, you can try these example prompts first
162
- '''
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
 
164
 
165
  def create_demo(args, model_name: str, device: str = "cuda" if torch.cuda.is_available() else "cpu",
166
  offload: bool = False):
167
- with gr.Blocks() as demo:
168
- gr.Markdown(_HEADER_)
169
 
170
  with gr.Row():
171
  with gr.Column():
@@ -195,69 +213,29 @@ def create_demo(args, model_name: str, device: str = "cuda" if torch.cuda.is_ava
195
  output_image = gr.Image(label="Generated Image")
196
  seed_output = gr.Textbox(label="Used Seed")
197
  intermediate_output = gr.Gallery(label='Output', elem_id="gallery", visible=args.dev)
198
- # gr.Markdown(_CITE_)
199
-
200
- # with gr.Row(), gr.Column():
201
- # gr.Markdown("## Examples")
202
- # example_inps = [
203
- # [
204
- # 'a woman holding sign with glowing green text',
205
- # 'example_inputs/liuyifei.png',
206
- # 4, 4, 2680261499100305976, 1
207
- # ],
208
- # [
209
- # 'portrait, side view',
210
- # 'example_inputs/liuyifei.png',
211
- # 4, 4, 1205240166692517553, 1
212
- # ],
213
- # [
214
- # 'white-haired woman with vr technology atmosphere, revolutionary exceptional magnum with remarkable details',
215
- # 'example_inputs/liuyifei.png',
216
- # 4, 4, 6349424134217931066, 1
217
- # ],
218
- # [
219
- # 'a young child is eating Icecream',
220
- # 'example_inputs/liuyifei.png',
221
- # 4, 4, 10606046113565776207, 1
222
- # ],
223
- # [
224
- # 'a man is holding a sign with text, winter, snowing, top of the mountain',
225
- # 'example_inputs/pengwei.jpg',
226
- # 4, 4, 2410129802683836089, 1
227
- # ],
228
- # [
229
- # 'portrait, candle light',
230
- # 'example_inputs/pengwei.jpg',
231
- # 4, 4, 17522759474323955700, 1
232
- # ],
233
- # [
234
- # 'profile shot dark photo of a 25-year-old male with smoke escaping from his mouth, the backlit smoke gives the image an ephemeral quality, natural face, natural eyebrows, natural skin texture, award winning photo, highly detailed face, atmospheric lighting, film grain, monochrome',
235
- # 'example_inputs/pengwei.jpg',
236
- # 4, 4, 17733156847328193625, 1
237
- # ],
238
- # [
239
- # 'American Comics, 1boy',
240
- # 'example_inputs/pengwei.jpg',
241
- # 1, 4, 13223174453874179686, 1
242
- # ],
243
- # [
244
- # 'portrait, pixar',
245
- # 'example_inputs/pengwei.jpg',
246
- # 1, 4, 9445036702517583939, 1
247
- # ],
248
- # ]
249
- # gr.Examples(examples=example_inps, inputs=[prompt, id_image, start_step, guidance, seed, true_cfg],
250
- # label='fake CFG')
251
-
252
- # example_inps = [
253
- # [
254
- # 'portrait, made of ice sculpture',
255
- # 'example_inputs/lecun.jpg',
256
- # 1, 1, 3811899118709451814, 5
257
- # ],
258
- # ]
259
- # gr.Examples(examples=example_inps, inputs=[prompt, id_image, start_step, guidance, seed, true_cfg],
260
- # label='true CFG')
261
 
262
  generate_btn.click(
263
  fn=generate_image,
 
151
  img = Image.fromarray((127.5 * (x + 1.0)).cpu().byte().numpy())
152
  return img, str(opts.seed), flux_generator.toonmage_model.debug_img_list
153
 
154
+ MARKDOWN = """
155
+ This demo utilizes <a href="https://huggingface.co/black-forest-labs/FLUX.1-dev">FLUX Pipeline</a> for Image to Image Translation
156
+
157
+ **Tips**
158
+
159
+ - Smaller value of timestep to start inserting ID would lead to higher fidelity, however, it will reduce the editability; and vice versa.
160
+ Its value range is from 0 - 4. If you want to generate a stylized scene; use the value of 0 - 1. If you want to generate a photorealistic image; use the value of 4.
161
+
162
+ -It is recommended to use fake CFG by setting the true CFG scale value to 1 while you can vary the guidance scale. However, in a few cases, utilizing a true CFG can yield better results.
163
+
164
+ Try out with different prompts using your image and do provide your feedback.
165
+
166
+ **Demo by [Sunder Ali Khowaja](https://sander-ali.github.io) - [X](https://x.com/SunderAKhowaja) -[Github](https://github.com/sander-ali) -[Hugging Face](https://huggingface.co/SunderAli17)**
167
+ """
168
+
169
+ theme = gr.themes.Soft(
170
+ font=[gr.themes.GoogleFont('Source Code Pro'), gr.themes.GoogleFont('Public Sans'), 'system-ui', 'sans-serif'],
171
+ )
172
+ js_func = """
173
+ function refresh() {
174
+ const url = new URL(window.location);
175
+ if (url.searchParams.get('__theme') !== 'dark') {
176
+ url.searchParams.set('__theme', 'dark');
177
+ window.location.href = url.href;
178
+ }
179
+ }
180
+ """
181
 
182
 
183
  def create_demo(args, model_name: str, device: str = "cuda" if torch.cuda.is_available() else "cpu",
184
  offload: bool = False):
185
+ with gr.Blocks(s = js_func, theme = theme) as demo:
186
+ gr.Markdown(MARKDOWN)
187
 
188
  with gr.Row():
189
  with gr.Column():
 
213
  output_image = gr.Image(label="Generated Image")
214
  seed_output = gr.Textbox(label="Used Seed")
215
  intermediate_output = gr.Gallery(label='Output', elem_id="gallery", visible=args.dev)
216
+
217
+
218
+ with gr.Row(), gr.Column():
219
+ gr.Markdown("## Examples")
220
+ example_inps = [
221
+ [
222
+ 'a high quality digital cartoon avatar eating ice cream',
223
+ 'sample_img/image1.png',
224
+ 0, 4, -1, 1
225
+ ],
226
+ [
227
+ 'a high quality anime character with mountains and lakes in the background',
228
+ 'sample_img/test1.jpg',
229
+ 0, 4, -1, 1
230
+ ],
231
+ [
232
+ 'a high quality photorealistic image with VR technology atmosphere, revolutionary exceptional magnum with remarkable details',
233
+ 'sample_img/test24.jpg',
234
+ 0, 4, -1, 1
235
+ ]
236
+ ]
237
+ gr.Examples(examples=example_inps, inputs=[prompt, id_image, start_step, guidance, seed, true_cfg],
238
+ label='fake CFG')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
 
240
  generate_btn.click(
241
  fn=generate_image,