fantaxy commited on
Commit
6f633b9
·
verified ·
1 Parent(s): 5b9d833

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +138 -218
app.py CHANGED
@@ -7,16 +7,14 @@ import time
7
  from PIL import Image
8
  import json
9
 
10
- # Project by Nymbo
11
-
12
- # Base API URL for Hugging Face inference
13
  API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
14
- # Retrieve the API token from environment variables
15
  API_TOKEN = os.getenv("HF_READ_TOKEN")
16
  headers = {"Authorization": f"Bearer {API_TOKEN}"}
17
- # Timeout for requests
18
  timeout = 100
19
 
 
 
20
  def query(prompt, model, custom_lora, is_negative=False, steps=35, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7, width=1024, height=1024):
21
  # Debug log to indicate function start
22
  print("Starting query function...")
@@ -307,231 +305,153 @@ footer {
307
  }
308
  """
309
 
310
- print("Initializing Gradio interface...") # Debug log
311
 
312
  # Define the Gradio interface
313
  with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as dalle:
314
- # Tab for basic settings
315
- with gr.Tab("Basic Settings"):
316
- with gr.Row():
317
- with gr.Column(elem_id="prompt-container"):
318
- with gr.Row():
319
- # Textbox for user to input the prompt
320
- text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=3, elem_id="prompt-text-input")
321
- with gr.Row():
322
- # Textbox for custom LoRA input
323
- custom_lora = gr.Textbox(label="Custom LoRA", info="LoRA Hugging Face path (optional)", placeholder="multimodalart/vintage-ads-flux")
324
- with gr.Row():
325
- # Accordion for selecting the model
326
- with gr.Accordion("Featured Models", open=True):
327
- # Textbox for searching models
328
- model_search = gr.Textbox(label="Filter Models", placeholder="Search for a featured model...", lines=1, elem_id="model-search-input")
329
- models_list = (
330
- "3D Sketchfab",
331
- "90s Anime Art",
332
- "AbsoluteReality 1.8.1",
333
- "Analog",
334
- "Analog Madness Realistic v7",
335
- "Analog Redmond",
336
- "Archfey Anime",
337
- "Ascii Art",
338
- "Brain Melt Acid Art",
339
- "Boreal",
340
- "Caricature",
341
- "Collage Flux",
342
- "Character Design",
343
- "Coloring Book Generator",
344
- "Cyborg Style XL",
345
- "Disney",
346
- "DreamPhotoGASM",
347
- "Duchaiten Real3D NSFW XL",
348
- "EpiCPhotoGasm",
349
- "Fashion Hut Modeling LoRA",
350
- "Filmgrain",
351
- "FLUX.1 [Dev]",
352
- "FLUX.1 [Schnell]",
353
- "Flux Realism LoRA",
354
- "Flux Super Realism LoRA",
355
- "Flux Uncensored",
356
- "Flux Uncensored V2",
357
- "Flux Game Assets V2",
358
- "Flux Ghibsky Illustration",
359
- "Flux Animex V2",
360
- "Flux Animeo V1",
361
- "Flux AestheticAnime",
362
- "Flux SyntheticAnime",
363
- "Flux Stickers",
364
- "Flux Koda",
365
- "Flux Tarot v1",
366
- "Flux Tarot Cards",
367
- "Flux Midjourney Anime",
368
- "Flux Logo Design",
369
- "Flux Product Ad Backdrop",
370
- "Flux Outfit Generator",
371
- "Frosting Lane Flux",
372
- "Half Illustration",
373
- "How2Draw",
374
- "Huggieverse",
375
- "Leonardo AI Style Illustration",
376
- "Little Tinies",
377
- "Lofi Cuties",
378
- "Lustly Flux Uncensored v1",
379
- "Maple Syrup",
380
- "Midjourney",
381
- "Movie Board",
382
- "NSFW Master Flux",
383
- "NSFW XL",
384
- "OpenDalle v1.1",
385
- "Perfect Lewd Fantasy",
386
- "Pixel Art Redmond",
387
- "Pixel Art XL",
388
- "Pixel Art Sprites",
389
- "Product Design",
390
- "Propaganda Poster",
391
- "Purple Dreamy",
392
- "Phantasma Anime",
393
- "PS1 Style Flux",
394
- "Redmond SDXL",
395
- "Retro Comic Flux",
396
- "Softserve Anime",
397
- "SoftPasty Flux",
398
- "Soviet Diffusion XL",
399
- "Sketched Out Manga",
400
- "Selfie Photography",
401
- "Stable Diffusion 2-1",
402
- "Stable Diffusion XL",
403
- "Stable Diffusion 3 Medium",
404
- "Stable Diffusion 3.5 Large",
405
- "Stable Diffusion 3.5 Large Turbo",
406
- "YiffyMix",
407
- )
408
-
409
- # Radio buttons to select the desired model
410
- model = gr.Radio(label="Select a model below", value="FLUX.1 [Schnell]", choices=models_list, interactive=True, elem_id="model-radio")
411
-
412
- # Filtering models based on search input
413
- def filter_models(search_term):
414
- filtered_models = [m for m in models_list if search_term.lower() in m.lower()]
415
- return gr.update(choices=filtered_models)
416
-
417
- # Update model list when search box is used
418
- model_search.change(filter_models, inputs=model_search, outputs=model)
419
-
420
- # Tab for advanced settings
421
- with gr.Tab("Advanced Settings"):
422
- with gr.Row():
423
- # Textbox for specifying elements to exclude from the image
424
- negative_prompt = gr.Textbox(label="Negative Prompt", placeholder="What should not be in the image", value="(deformed, distorted, disfigured), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation, misspellings, typos", lines=3, elem_id="negative-prompt-text-input")
425
- with gr.Row():
426
- # Slider for selecting the image width
427
- width = gr.Slider(label="Width", value=1024, minimum=64, maximum=1216, step=32)
428
- # Slider for selecting the image height
429
- height = gr.Slider(label="Height", value=1024, minimum=64, maximum=1216, step=32)
430
- with gr.Row():
431
- # Slider for setting the number of sampling steps
432
- steps = gr.Slider(label="Sampling steps", value=35, minimum=1, maximum=100, step=1)
433
- with gr.Row():
434
- # Slider for adjusting the CFG scale (guidance scale)
435
- cfg = gr.Slider(label="CFG Scale", value=7, minimum=1, maximum=20, step=1)
436
- with gr.Row():
437
- # Slider for adjusting the transformation strength
438
- strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
439
- with gr.Row():
440
- # Slider for setting the seed for reproducibility
441
- seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
442
- with gr.Row():
443
- # Radio buttons for selecting the sampling method
444
- method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"])
445
 
446
- # Tab for image editing options
447
- with gr.Tab("Image Editor"):
448
- # Function to simulate a delay for processing
449
- def sleep(im):
450
- print("Sleeping for 5 seconds...") # Debug log
451
- time.sleep(5)
452
- return [im["background"], im["layers"][0], im["layers"][1], im["composite"]]
453
 
454
- # Function to return the composite image
455
- def predict(im):
456
- print("Predicting composite image...") # Debug log
457
- return im["composite"]
 
 
 
 
 
 
 
 
 
 
458
 
459
- with gr.Blocks() as demo:
460
- with gr.Row():
461
- # Image editor component for user adjustments
462
- im = gr.ImageEditor(
463
- type="numpy",
464
- crop_size="1:1", # Set crop size to a square aspect ratio
 
465
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
466
 
467
- # Tab to provide information to the user
468
- with gr.Tab("Information"):
469
- with gr.Row():
470
- # Display a sample prompt for guidance
471
- gr.Textbox(label="Sample prompt", value="{prompt} | ultra detail, ultra elaboration, ultra quality, perfect.")
 
472
 
473
- # Accordion displaying featured models
474
- with gr.Accordion("Featured Models (WiP)", open=False):
475
- gr.HTML(
476
- """
477
- <p><a href="https://huggingface.co/models?inference=warm&pipeline_tag=text-to-image&sort=trending">See all available models</a></p>
478
- <table style="width:100%; text-align:center; margin:auto;">
479
- <tr>
480
- <th>Model Name</th>
481
- <th>Typography</th>
482
- <th>Notes</th>
483
- </tr>
484
- <tr>
485
- <td>FLUX.1 Dev</td>
486
- <td>✅</td>
487
- <td></td>
488
- </tr>
489
- <tr>
490
- <td>FLUX.1 Schnell</td>
491
- <td>✅</td>
492
- <td></td>
493
- </tr>
494
- <tr>
495
- <td>Stable Diffusion 3.5 Large</td>
496
- <td>✅</td>
497
- <td></td>
498
- </tr>
499
- </table>
500
- """
501
- )
502
 
503
- # Accordion providing an overview of advanced settings
504
- with gr.Accordion("Advanced Settings Overview", open=False):
505
- gr.Markdown(
506
- """
507
- ## Negative Prompt
508
- ###### This box is for telling the AI what you don't want in your images. Think of it as a way to avoid certain elements. For instance, if you don't want blurry images or extra limbs showing up, this is where you'd mention it.
509
- ## Width & Height
510
- ###### These sliders allow you to specify the resolution of your image. Default value is 1024x1024, and maximum output is 1216x1216.
511
- ## Sampling Steps
512
- ###### Think of this like the number of brushstrokes in a painting. A higher number can give you a more detailed picture, but it also takes a bit longer. Generally, a middle-ground number like 35 is a good balance between quality and speed.
513
- ## CFG Scale
514
- ###### CFG stands for "Control Free Guidance." The scale adjusts how closely the AI follows your prompt. A lower number makes the AI more creative and free-flowing, while a higher number makes it stick closely to what you asked for. If you want the AI to take fewer artistic liberties, slide this towards a higher number. Just think "Control Freak Gauge".
515
- ## Sampling Method
516
- ###### This is the technique the AI uses to create your image. Each option is a different approach, like choosing between pencils, markers, or paint. You don't need to worry too much about this; the default setting is usually the best choice for most users.
517
- ## Strength
518
- ###### This setting is a bit like the 'intensity' knob. It determines how much the AI modifies the base image it starts with. If you're looking to make subtle changes, keep this low. For more drastic transformations, turn it up.
519
- ## Seed
520
- ###### You can think of the seed as a 'recipe' for creating an image. If you find a seed that gives you a result you love, you can use it again to create a similar image. If you leave it at -1, the AI will generate a new seed every time.
521
- ### Remember, these settings are all about giving you control over the image generation process. Feel free to experiment and see what each one does. And if you're ever in doubt, the default settings are a great place to start. Happy creating!
522
- """
523
- )
524
 
525
- # Row containing the 'Run' button to trigger the image generation
526
  with gr.Row():
527
- text_button = gr.Button("Run", variant='primary', elem_id="gen-button")
528
- # Row for displaying the generated image output
529
  with gr.Row():
530
- image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
531
 
532
- # Set up button click event to call the query function
533
- text_button.click(query, inputs=[text_prompt, model, custom_lora, negative_prompt, steps, cfg, method, seed, strength, width, height], outputs=image_output)
 
 
 
 
 
 
 
 
534
 
535
- print("Launching Gradio interface...") # Debug log
536
- # Launch the Gradio interface without showing the API or sharing externally
537
- dalle.launch(show_api=False, share=False)
 
7
  from PIL import Image
8
  import json
9
 
10
+ # Base API URL for Hugging Face inference
 
 
11
  API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev"
 
12
  API_TOKEN = os.getenv("HF_READ_TOKEN")
13
  headers = {"Authorization": f"Bearer {API_TOKEN}"}
 
14
  timeout = 100
15
 
16
+
17
+
18
  def query(prompt, model, custom_lora, is_negative=False, steps=35, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7, width=1024, height=1024):
19
  # Debug log to indicate function start
20
  print("Starting query function...")
 
305
  }
306
  """
307
 
308
+ print("Initializing Gradio interface...")
309
 
310
  # Define the Gradio interface
311
  with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as dalle:
312
+ gr.Markdown("# AI Image Generator")
313
+
314
+ with gr.Row():
315
+ with gr.Column(scale=2):
316
+ # Main prompt input
317
+ text_prompt = gr.Textbox(
318
+ label="Prompt",
319
+ placeholder="Describe what you want to create...",
320
+ lines=3
321
+ )
322
+
323
+ # Negative prompt
324
+ negative_prompt = gr.Textbox(
325
+ label="Negative Prompt",
326
+ placeholder="What should not be in the image",
327
+ value="(deformed, distorted, disfigured), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, (mutated hands and fingers), disconnected limbs, mutation, mutated, ugly, disgusting, blurry, amputation",
328
+ lines=2
329
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
330
 
331
+ # Custom LoRA input
332
+ custom_lora = gr.Textbox(
333
+ label="Custom LoRA Path (Optional)",
334
+ placeholder="e.g., multimodalart/vintage-ads-flux",
335
+ lines=1
336
+ )
 
337
 
338
+ with gr.Column(scale=1):
339
+ # Image dimensions
340
+ with gr.Group():
341
+ gr.Markdown("### Image Settings")
342
+ width = gr.Slider(label="Width", value=1024, minimum=512, maximum=1216, step=64)
343
+ height = gr.Slider(label="Height", value=1024, minimum=512, maximum=1216, step=64)
344
+
345
+ # Generation parameters
346
+ with gr.Group():
347
+ gr.Markdown("### Generation Parameters")
348
+ steps = gr.Slider(label="Steps", value=35, minimum=1, maximum=100, step=1)
349
+ cfg = gr.Slider(label="CFG Scale", value=7, minimum=1, maximum=20, step=0.5)
350
+ strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.1)
351
+ seed = gr.Slider(label="Seed (-1 for random)", value=-1, minimum=-1, maximum=1000000000, step=1)
352
 
353
+ # Model selection
354
+ with gr.Group():
355
+ gr.Markdown("### Model Selection")
356
+ model_search = gr.Textbox(
357
+ label="Search Models",
358
+ placeholder="Type to filter models...",
359
+ lines=1
360
  )
361
+
362
+ # Updated model list (reordered by popularity/recency)
363
+ models_list = [
364
+ "Stable Diffusion 3.5 Large",
365
+ "Stable Diffusion 3.5 Large Turbo",
366
+ "Stable Diffusion XL",
367
+ "FLUX.1 [Schnell]",
368
+ "FLUX.1 [Dev]",
369
+ "Midjourney",
370
+ "DreamPhotoGASM",
371
+ "Disney",
372
+ "Leonardo AI Style Illustration",
373
+ "AbsoluteReality 1.8.1",
374
+ "Analog Redmond",
375
+ "Stable Diffusion 3 Medium",
376
+ "Flux Super Realism LoRA",
377
+ "Flux Realism LoRA",
378
+ "Selfie Photography",
379
+ "Character Design",
380
+ "Pixel Art XL",
381
+ "3D Sketchfab",
382
+ "Anime Collection", # Group of anime-related models
383
+ "Flux Animex V2",
384
+ "Flux Animeo V1",
385
+ "Flux AestheticAnime",
386
+ "90s Anime Art",
387
+ "Softserve Anime",
388
+ "Artistic Styles", # Group of artistic style models
389
+ "Brain Melt Acid Art",
390
+ "Retro Comic Flux",
391
+ "Purple Dreamy",
392
+ "SoftPasty Flux",
393
+ "Specialized", # Group of specialized models
394
+ "Flux Logo Design",
395
+ "Product Design",
396
+ "Propaganda Poster",
397
+ "Movie Board",
398
+ "Collage Flux",
399
+ # Additional models...
400
+ ]
401
 
402
+ model = gr.Radio(
403
+ label="Select Model",
404
+ choices=models_list,
405
+ value="Stable Diffusion 3.5 Large",
406
+ interactive=True
407
+ )
408
 
409
+ def filter_models(search_term):
410
+ filtered_models = [m for m in models_list if search_term.lower() in m.lower()]
411
+ return gr.update(choices=filtered_models)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
412
 
413
+ model_search.change(filter_models, inputs=model_search, outputs=model)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
414
 
415
+ # Generate button and output
416
  with gr.Row():
417
+ generate_btn = gr.Button("Generate Image", variant="primary", size="lg")
418
+
419
  with gr.Row():
420
+ image_output = gr.Image(
421
+ type="pil",
422
+ label="Generated Image",
423
+ show_label=True
424
+ )
425
+
426
+ # Set up the generation event
427
+ generate_btn.click(
428
+ fn=query,
429
+ inputs=[
430
+ text_prompt,
431
+ model,
432
+ custom_lora,
433
+ negative_prompt,
434
+ steps,
435
+ cfg,
436
+ method,
437
+ seed,
438
+ strength,
439
+ width,
440
+ height
441
+ ],
442
+ outputs=image_output
443
+ )
444
 
445
+ # Add some helpful tips
446
+ with gr.Accordion("Tips", open=False):
447
+ gr.Markdown("""
448
+ ### Quick Tips:
449
+ - Use detailed descriptions for better results
450
+ - Adjust CFG Scale to control how closely the AI follows your prompt
451
+ - Higher steps generally mean better quality but slower generation
452
+ - Save seeds of images you like to recreate similar results
453
+ - Use negative prompts to avoid unwanted elements
454
+ """)
455
 
456
+ print("Launching Gradio interface...")
457
+ dalle.launch(show_api=False, share=False)