|
import gradio as gr |
|
import requests |
|
import io |
|
import random |
|
import os |
|
import time |
|
from PIL import Image |
|
import json |
|
from huggingface_hub import InferenceClient |
|
|
|
|
|
|
|
def query_with_auto_routing(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): |
|
""" |
|
Generate images using HF's automatic provider routing |
|
""" |
|
print(f"Starting query with automatic provider routing") |
|
print(f"Prompt: {prompt}") |
|
print(f"Model: {model}") |
|
print(f"Custom LoRA: {custom_lora}") |
|
print(f"Parameters - Steps: {steps}, CFG Scale: {cfg_scale}, Seed: {seed}, Strength: {strength}, Width: {width}, Height: {height}") |
|
|
|
|
|
if prompt == "" or prompt is None: |
|
print("Prompt is empty or None. Exiting query function.") |
|
return None |
|
|
|
|
|
key = random.randint(0, 999) |
|
print(f"Generated key: {key}") |
|
|
|
|
|
enhanced_prompt = f"{prompt} | ultra detail, ultra elaboration, ultra quality, perfect." |
|
print(f'Generation {key}: {enhanced_prompt}') |
|
|
|
try: |
|
|
|
api_key = os.getenv("HF_READ_TOKEN") |
|
if not api_key: |
|
raise gr.Error("HF_READ_TOKEN not found. Please set your Hugging Face API token.") |
|
|
|
|
|
client = InferenceClient(api_key=api_key) |
|
|
|
|
|
if custom_lora.strip() != "": |
|
model_id = custom_lora.strip() |
|
print(f"Using custom LoRA: {model_id}") |
|
else: |
|
model_id = get_model_id_from_name(model) |
|
print(f"Using model: {model_id}") |
|
|
|
|
|
enhanced_prompt = apply_model_prompt_enhancements(model, enhanced_prompt) |
|
|
|
|
|
image = client.text_to_image( |
|
prompt=enhanced_prompt, |
|
model=model_id, |
|
width=width, |
|
height=height, |
|
num_inference_steps=steps, |
|
guidance_scale=cfg_scale, |
|
seed=seed if seed != -1 else None, |
|
) |
|
|
|
print(f'Generation {key} completed with automatic routing!') |
|
return image |
|
|
|
except Exception as e: |
|
print(f"Error with automatic routing: {e}") |
|
raise gr.Error(f"Failed to generate image: {str(e)}") |
|
|
|
def get_model_id_from_name(model_name): |
|
""" |
|
Convert user-friendly model names to actual HuggingFace model IDs |
|
""" |
|
model_mapping = { |
|
'FLUX.1 [Dev]': "black-forest-labs/FLUX.1-dev", |
|
'FLUX.1 [Schnell]': "black-forest-labs/FLUX.1-schnell", |
|
'Stable Diffusion XL': "stabilityai/stable-diffusion-xl-base-1.0", |
|
'Stable Diffusion 3.5 Large': "stabilityai/stable-diffusion-3.5-large", |
|
'Stable Diffusion 3.5 Large Turbo': "stabilityai/stable-diffusion-3.5-large-turbo", |
|
'Stable Diffusion 3 Medium': "stabilityai/stable-diffusion-3-medium-diffusers", |
|
'HiDream-I1-Full': "HiDream-ai/HiDream-I1-Full", |
|
'HiDream-I1-Dev': "HiDream-ai/HiDream-I1-Dev", |
|
'HiDream-I1-Fast': "HiDream-ai/HiDream-I1-Fast", |
|
'Animagine 4.0': "cagliostrolab/animagine-xl-4.0", |
|
'Flux Icon Kit': "strangerzonehf/Flux-Icon-Kit-LoRA", |
|
'Pixel Background': "strangerzonehf/Flux-Pixel-Background-LoRA", |
|
'Meme XD': "prithivMLmods/Flux-Meme-Xd-LoRA", |
|
'Chill Guy': "prithivMLmods/Flux-Chill-Guy-Zone", |
|
'Pepe': "openfree/pepe", |
|
'NSFWmodel': "lexa862/NSFWmodel", |
|
'Claude Art': "strangerzonehf/Flux-Claude-Art", |
|
'Open Genmoji': "EvanZhouDev/open-genmoji", |
|
'EBook Creative Cover': "prithivMLmods/EBook-Creative-Cover-Flux-LoRA", |
|
'Flux Logo Design 2': "prithivMLmods/Logo-Design-Flux-LoRA", |
|
'Isometric 3D': "strangerzonehf/Flux-Isometric-3D-LoRA", |
|
'Flux Condensation': "fofr/flux-condensation", |
|
'Flux Handwriting': "fofr/flux-handwriting", |
|
'Shou Xin': "Datou1111/shou_xin", |
|
'Sketch Smudge': "strangerzonehf/Flux-Sketch-Smudge-LoRA", |
|
'80s Cyberpunk': "fofr/flux-80s-cyberpunk", |
|
'Coloring Book Flux': "renderartist/coloringbookflux", |
|
'Flux Miniature LoRA': "gokaygokay/Flux-Miniature-LoRA", |
|
'Sketch Paint': "strangerzonehf/Sketch-Paint", |
|
'Flux UltraRealism 2.0': "prithivMLmods/Canopus-LoRA-Flux-UltraRealism-2.0", |
|
'Midjourney Mix': "strangerzonehf/Flux-Midjourney-Mix-LoRA", |
|
'Midjourney Mix 2': "strangerzonehf/Flux-Midjourney-Mix2-LoRA", |
|
'Flux Logo Design': "Shakker-Labs/FLUX.1-dev-LoRA-Logo-Design", |
|
'Flux Uncensored': "enhanceaiteam/Flux-uncensored", |
|
'Flux Uncensored V2': "enhanceaiteam/Flux-Uncensored-V2", |
|
'Flux Tarot Cards': "prithivMLmods/Ton618-Tarot-Cards-Flux-LoRA", |
|
'Pixel Art Sprites': "sWizad/pokemon-trainer-sprites-pixelart-flux", |
|
'3D Sketchfab': "prithivMLmods/Castor-3D-Sketchfab-Flux-LoRA", |
|
'Retro Comic Flux': "renderartist/retrocomicflux", |
|
'Caricature': "TheAwakenOne/caricature", |
|
'Huggieverse': "Chunte/flux-lora-Huggieverse", |
|
'Propaganda Poster': "AlekseyCalvin/Propaganda_Poster_Schnell_by_doctor_diffusion", |
|
'Flux Game Assets V2': "gokaygokay/Flux-Game-Assets-LoRA-v2", |
|
'SDXL HS Card Style': "Norod78/sdxl-hearthstone-card-style-lora", |
|
'SLDR FLUX NSFW v2 Studio': "xey/sldr_flux_nsfw_v2-studio", |
|
'SoftPasty Flux': "alvdansen/softpasty-flux-dev", |
|
'Flux Stickers': "diabolic6045/Flux_Sticker_Lora", |
|
'Flux Animex V2': "strangerzonehf/Flux-Animex-v2-LoRA", |
|
'Flux Animeo V1': "strangerzonehf/Flux-Animeo-v1-LoRA", |
|
'Movie Board': "prithivMLmods/Flux.1-Dev-Movie-Boards-LoRA", |
|
'Purple Dreamy': "prithivMLmods/Purple-Dreamy-Flux-LoRA", |
|
'PS1 Style Flux': "veryVANYA/ps1-style-flux", |
|
'Softserve Anime': "alvdansen/softserve_anime", |
|
'Flux Tarot v1': "multimodalart/flux-tarot-v1", |
|
'Half Illustration': "davisbro/half_illustration", |
|
'OpenDalle v1.1': "dataautogpt3/OpenDalleV1.1", |
|
'Flux Ghibsky Illustration': "aleksa-codes/flux-ghibsky-illustration", |
|
'Flux Koda': "alvdansen/flux-koda", |
|
'Soviet Diffusion XL': "openskyml/soviet-diffusion-xl", |
|
'Flux Realism LoRA': "XLabs-AI/flux-RealismLora", |
|
'Frosting Lane Flux': "alvdansen/frosting_lane_flux", |
|
'Phantasma Anime': "alvdansen/phantasma-anime", |
|
'Boreal': "kudzueye/Boreal", |
|
'How2Draw': "glif/how2draw", |
|
'Flux AestheticAnime': "dataautogpt3/FLUX-AestheticAnime", |
|
'Fashion Hut Modeling LoRA': "prithivMLmods/Fashion-Hut-Modeling-LoRA", |
|
'Flux SyntheticAnime': "dataautogpt3/FLUX-SyntheticAnime", |
|
'Flux Midjourney Anime': "brushpenbob/flux-midjourney-anime", |
|
'Coloring Book Generator': "robert123231/coloringbookgenerator", |
|
'Collage Flux': "prithivMLmods/Castor-Collage-Dim-Flux-LoRA", |
|
'Flux Product Ad Backdrop': "prithivMLmods/Flux-Product-Ad-Backdrop", |
|
'Product Design': "multimodalart/product-design", |
|
'90s Anime Art': "glif/90s-anime-art", |
|
'Brain Melt Acid Art': "glif/Brain-Melt-Acid-Art", |
|
'Lustly Flux Uncensored v1': "lustlyai/Flux_Lustly.ai_Uncensored_nsfw_v1", |
|
'NSFW Master Flux': "Keltezaa/NSFW_MASTER_FLUX", |
|
'Flux Outfit Generator': "tryonlabs/FLUX.1-dev-LoRA-Outfit-Generator", |
|
'Midjourney': "Jovie/Midjourney", |
|
'DreamPhotoGASM': "Yntec/DreamPhotoGASM", |
|
'Flux Super Realism LoRA': "strangerzonehf/Flux-Super-Realism-LoRA", |
|
'Stable Diffusion 2-1': "stabilityai/stable-diffusion-2-1-base", |
|
'Duchaiten Real3D NSFW XL': "stablediffusionapi/duchaiten-real3d-nsfw-xl", |
|
'Pixel Art XL': "nerijs/pixel-art-xl", |
|
'Character Design': "KappaNeuro/character-design", |
|
'Sketched Out Manga': "alvdansen/sketchedoutmanga", |
|
'Archfey Anime': "alvdansen/archfey_anime", |
|
'Lofi Cuties': "alvdansen/lofi-cuties", |
|
'YiffyMix': "Yntec/YiffyMix", |
|
'Analog Madness Realistic v7': "digiplay/AnalogMadness-realistic-model-v7", |
|
'Selfie Photography': "artificialguybr/selfiephotographyredmond-selfie-photography-lora-for-sdxl", |
|
'Filmgrain': "artificialguybr/filmgrain-redmond-filmgrain-lora-for-sdxl", |
|
'Leonardo AI Style Illustration': "goofyai/Leonardo_Ai_Style_Illustration", |
|
'Cyborg Style XL': "goofyai/cyborg_style_xl", |
|
'Little Tinies': "alvdansen/littletinies", |
|
'NSFW XL': "Dremmar/nsfw-xl", |
|
'Analog Redmond': "artificialguybr/analogredmond", |
|
'Pixel Art Redmond': "artificialguybr/PixelArtRedmond", |
|
'Ascii Art': "CiroN2022/ascii-art", |
|
'Analog': "Yntec/Analog", |
|
'Maple Syrup': "Yntec/MapleSyrup", |
|
'Perfect Lewd Fantasy': "digiplay/perfectLewdFantasy_v1.01", |
|
'AbsoluteReality 1.8.1': "digiplay/AbsoluteReality_v1.8.1", |
|
'Disney': "goofyai/disney_style_xl", |
|
'Redmond SDXL': "artificialguybr/LogoRedmond-LogoLoraForSDXL-V2", |
|
'epiCPhotoGasm': "Yntec/epiCPhotoGasm" |
|
} |
|
|
|
|
|
return model_mapping.get(model_name, "black-forest-labs/FLUX.1-schnell") |
|
|
|
def apply_model_prompt_enhancements(model_name, prompt): |
|
""" |
|
Apply model-specific prompt enhancements |
|
""" |
|
if model_name == 'Animagine 4.0': |
|
return f"masterpiece, high score, great score, absurdres, {prompt}" |
|
elif model_name == 'Flux Icon Kit': |
|
return f"Icon Kit, {prompt}" |
|
elif model_name == 'Pixel Background': |
|
return f"Pixel Background, {prompt}" |
|
elif model_name == 'Meme XD': |
|
return f"meme, {prompt}" |
|
elif model_name == 'Chill Guy': |
|
return f"chill guy, {prompt}" |
|
elif model_name == 'Pepe': |
|
return f"pepe, {prompt}" |
|
elif model_name == 'NSFWmodel': |
|
return f"nude, {prompt}" |
|
elif model_name == 'Claude Art': |
|
return f"claude art, {prompt}" |
|
elif model_name == 'Open Genmoji': |
|
return f"emoji, {prompt}" |
|
elif model_name == 'EBook Creative Cover': |
|
return f"EBook Cover, {prompt}" |
|
elif model_name == 'Flux Logo Design 2': |
|
return f"Logo Design, {prompt}" |
|
elif model_name == 'Isometric 3D': |
|
return f"Isometric 3D, {prompt}" |
|
elif model_name == 'Flux Condensation': |
|
return f"CONDENSATION, {prompt}" |
|
elif model_name == 'Flux Handwriting': |
|
return f"HWRIT handwriting, {prompt}" |
|
elif model_name == 'Shou Xin': |
|
return f"shou_xin, pencil sketch, {prompt}" |
|
elif model_name == 'Sketch Smudge': |
|
return f"Sketch Smudge, {prompt}" |
|
elif model_name == '80s Cyberpunk': |
|
return f"80s cyberpunk, {prompt}" |
|
elif model_name == 'Coloring Book Flux': |
|
return f"c0l0ringb00k, coloring book, coloring book page, {prompt}" |
|
elif model_name == 'Flux Miniature LoRA': |
|
return f"MNTR, miniature drawing, {prompt}" |
|
elif model_name == 'Sketch Paint': |
|
return f"Sketch paint, {prompt}" |
|
elif model_name == 'Flux UltraRealism 2.0': |
|
return f"Ultra realistic, {prompt}" |
|
elif model_name == 'Midjourney Mix': |
|
return f"midjourney mix, {prompt}" |
|
elif model_name == 'Midjourney Mix 2': |
|
return f"MJ v6, {prompt}" |
|
elif model_name == 'Flux Logo Design': |
|
return f"wablogo, logo, Minimalist, {prompt}" |
|
elif model_name == 'Flux Tarot Cards': |
|
return f"Tarot card, {prompt}" |
|
elif model_name == 'Pixel Art Sprites': |
|
return f"a pixel image, {prompt}" |
|
elif model_name == '3D Sketchfab': |
|
return f"3D Sketchfab, {prompt}" |
|
elif model_name == 'Retro Comic Flux': |
|
return f"c0m1c, comic book panel, {prompt}" |
|
elif model_name == 'Caricature': |
|
return f"CCTUR3, {prompt}" |
|
elif model_name == 'Huggieverse': |
|
return f"HGGRE, {prompt}" |
|
elif model_name == 'Stable Diffusion 3 Medium': |
|
return f"A, {prompt}" |
|
elif model_name == 'Propaganda Poster': |
|
return f"propaganda poster, {prompt}" |
|
elif model_name == 'Flux Game Assets V2': |
|
return f"wbgmsst, white background, {prompt}" |
|
elif model_name == 'SDXL HS Card Style': |
|
return f"Hearthstone Card, {prompt}" |
|
elif model_name == 'SoftPasty Flux': |
|
return f"araminta_illus illustration style, {prompt}" |
|
elif model_name == 'Flux Stickers': |
|
return f"5t1cker 5ty1e, {prompt}" |
|
elif model_name == 'Flux Animex V2': |
|
return f"Animex, {prompt}" |
|
elif model_name == 'Flux Animeo V1': |
|
return f"Animeo, {prompt}" |
|
elif model_name == 'Movie Board': |
|
return f"movieboard, {prompt}" |
|
elif model_name == 'Purple Dreamy': |
|
return f"Purple Dreamy, {prompt}" |
|
elif model_name == 'PS1 Style Flux': |
|
return f"ps1 game screenshot, {prompt}" |
|
elif model_name == 'Softserve Anime': |
|
return f"sftsrv style illustration, {prompt}" |
|
elif model_name == 'Flux Tarot v1': |
|
return f"in the style of TOK a trtcrd tarot style, {prompt}" |
|
elif model_name == 'Half Illustration': |
|
return f"in the style of TOK, {prompt}" |
|
elif model_name == 'Flux Ghibsky Illustration': |
|
return f"GHIBSKY style, {prompt}" |
|
elif model_name == 'Flux Koda': |
|
return f"flmft style, {prompt}" |
|
elif model_name == 'Soviet Diffusion XL': |
|
return f"soviet poster, {prompt}" |
|
elif model_name == 'Frosting Lane Flux': |
|
return f"frstingln illustration, {prompt}" |
|
elif model_name == 'Boreal': |
|
return f"photo, {prompt}" |
|
elif model_name == 'How2Draw': |
|
return f"How2Draw, {prompt}" |
|
elif model_name == 'Fashion Hut Modeling LoRA': |
|
return f"Modeling of, {prompt}" |
|
elif model_name == 'Flux SyntheticAnime': |
|
return f"1980s anime screengrab, VHS quality, syntheticanime, {prompt}" |
|
elif model_name == 'Flux Midjourney Anime': |
|
return f"egmid, {prompt}" |
|
elif model_name == 'Collage Flux': |
|
return f"collage, {prompt}" |
|
elif model_name == 'Flux Product Ad Backdrop': |
|
return f"Product Ad, {prompt}" |
|
elif model_name == 'Product Design': |
|
return f"product designed by prdsgn, {prompt}" |
|
elif model_name == 'Brain Melt Acid Art': |
|
return f"maximalism, in an acid surrealism style, {prompt}" |
|
elif model_name == 'NSFW Master Flux': |
|
return f"NSFW, {prompt}" |
|
elif model_name == 'Pixel Art XL': |
|
return f"pixel art, {prompt}" |
|
elif model_name == 'Character Design': |
|
return f"Character Design, {prompt}" |
|
elif model_name == 'Sketched Out Manga': |
|
return f"daiton, {prompt}" |
|
elif model_name == 'Selfie Photography': |
|
return f"instagram model, discord profile picture, {prompt}" |
|
elif model_name == 'Filmgrain': |
|
return f"Film Grain, FilmGrainAF, {prompt}" |
|
elif model_name == 'Leonardo AI Style Illustration': |
|
return f"leonardo style, illustration, vector art, {prompt}" |
|
elif model_name == 'Cyborg Style XL': |
|
return f"cyborg style, {prompt}" |
|
elif model_name == 'Analog Redmond': |
|
return f"timeless style, {prompt}" |
|
elif model_name == 'Pixel Art Redmond': |
|
return f"Pixel Art, {prompt}" |
|
elif model_name == 'Ascii Art': |
|
return f"ascii art, {prompt}" |
|
elif model_name == 'Disney': |
|
return f"Disney style, {prompt}" |
|
|
|
return prompt |
|
|
|
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): |
|
""" |
|
Main query function - now uses automatic provider routing |
|
""" |
|
return query_with_auto_routing(prompt, model, custom_lora, is_negative, steps, cfg_scale, sampler, seed, strength, width, height) |
|
|
|
|
|
css = """ |
|
* {} |
|
footer {visibility: hidden !important;} |
|
""" |
|
|
|
print("Initializing Gradio interface...") |
|
|
|
|
|
with gr.Blocks(theme='Nymbo/Alyx_Theme') as dalle: |
|
|
|
with gr.Tab("Basic Settings"): |
|
with gr.Row(): |
|
with gr.Column(elem_id="prompt-container"): |
|
with gr.Row(): |
|
|
|
text_prompt = gr.Textbox(label="Prompt", placeholder="Enter a prompt here", lines=3, elem_id="prompt-text-input") |
|
with gr.Row(): |
|
|
|
custom_lora = gr.Textbox(label="Custom LoRA", info="LoRA Hugging Face path (optional)", placeholder="multimodalart/vintage-ads-flux") |
|
with gr.Row(): |
|
|
|
with gr.Accordion("Featured Models", open=False): |
|
|
|
model_search = gr.Textbox(label="Filter Models", placeholder="Search for a featured model...", lines=1, elem_id="model-search-input") |
|
models_list = ( |
|
"3D Sketchfab", |
|
"80s Cyberpunk", |
|
"90s Anime Art", |
|
"AbsoluteReality 1.8.1", |
|
"Analog", |
|
"Analog Madness Realistic v7", |
|
"Analog Redmond", |
|
"Animagine 4.0", |
|
"Archfey Anime", |
|
"Ascii Art", |
|
"Brain Melt Acid Art", |
|
"Boreal", |
|
"Caricature", |
|
"Collage Flux", |
|
"Coloring Book Flux", |
|
"Character Design", |
|
"Chill Guy", |
|
"Claude Art", |
|
"Coloring Book Generator", |
|
"Cyborg Style XL", |
|
"Disney", |
|
"DreamPhotoGASM", |
|
"Duchaiten Real3D NSFW XL", |
|
"EBook Creative Cover", |
|
"EpiCPhotoGasm", |
|
"Fashion Hut Modeling LoRA", |
|
"Filmgrain", |
|
"FLUX.1 [Dev]", |
|
"FLUX.1 [Schnell]", |
|
"FLux Condensation", |
|
"Flux Handwriting", |
|
"Flux Realism LoRA", |
|
"Flux Super Realism LoRA", |
|
"Flux Uncensored", |
|
"Flux Uncensored V2", |
|
"Flux Game Assets V2", |
|
"Flux Icon Kit", |
|
"Flux Ghibsky Illustration", |
|
"Flux Animex V2", |
|
"Flux Animeo V1", |
|
"Flux AestheticAnime", |
|
"Flux SyntheticAnime", |
|
"Flux Stickers", |
|
"Flux Koda", |
|
"Flux Tarot v1", |
|
"Flux Tarot Cards", |
|
"Flux UltraRealism 2.0", |
|
"Flux Midjourney Anime", |
|
"Flux Miniature LoRA", |
|
"Flux Logo Design", |
|
"Flux Logo Design 2", |
|
"Flux Product Ad Backdrop", |
|
"Flux Outfit Generator", |
|
"Frosting Lane Flux", |
|
"Half Illustration", |
|
"HiDream-I1-Full", |
|
"HiDream-I1-Dev", |
|
"HiDream-I1-Fast", |
|
"How2Draw", |
|
"Huggieverse", |
|
"Isometric 3D", |
|
"Leonardo AI Style Illustration", |
|
"Little Tinies", |
|
"Lofi Cuties", |
|
"Lustly Flux Uncensored v1", |
|
"Maple Syrup", |
|
"Meme XD", |
|
"Midjourney", |
|
"Midjourney Mix", |
|
"Midjourney Mix 2", |
|
"Movie Board", |
|
"NSFWmodel", |
|
"NSFW Master Flux", |
|
"NSFW XL", |
|
"OpenDalle v1.1", |
|
"Open Genmoji", |
|
"Pepe", |
|
"Perfect Lewd Fantasy", |
|
"Pixel Art Redmond", |
|
"Pixel Art XL", |
|
"Pixel Art Sprites", |
|
"Pixel Background", |
|
"Product Design", |
|
"Propaganda Poster", |
|
"Purple Dreamy", |
|
"Phantasma Anime", |
|
"PS1 Style Flux", |
|
"Redmond SDXL", |
|
"Retro Comic Flux", |
|
"SDXL HS Card Style", |
|
"Sketch Smudge", |
|
"Shou Xin", |
|
"Softserve Anime", |
|
"SoftPasty Flux", |
|
"Soviet Diffusion XL", |
|
"Sketched Out Manga", |
|
"Sketch Paint", |
|
"SLDR FLUX NSFW v2 Studio", |
|
"Selfie Photography", |
|
"Stable Diffusion 2-1", |
|
"Stable Diffusion XL", |
|
"Stable Diffusion 3 Medium", |
|
"Stable Diffusion 3.5 Large", |
|
"Stable Diffusion 3.5 Large Turbo", |
|
"YiffyMix", |
|
) |
|
|
|
|
|
model = gr.Radio(label="Select a model below", value="FLUX.1 [Schnell]", choices=models_list, interactive=True, elem_id="model-radio") |
|
|
|
|
|
def filter_models(search_term): |
|
filtered_models = [m for m in models_list if search_term.lower() in m.lower()] |
|
return gr.update(choices=filtered_models) |
|
|
|
|
|
model_search.change(filter_models, inputs=model_search, outputs=model) |
|
|
|
|
|
with gr.Tab("Advanced Settings"): |
|
with gr.Row(): |
|
|
|
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") |
|
with gr.Row(): |
|
|
|
width = gr.Slider(label="Width", value=1024, minimum=64, maximum=1216, step=32) |
|
|
|
height = gr.Slider(label="Height", value=1024, minimum=64, maximum=1216, step=32) |
|
with gr.Row(): |
|
|
|
steps = gr.Slider(label="Sampling steps", value=35, minimum=1, maximum=100, step=1) |
|
with gr.Row(): |
|
|
|
cfg = gr.Slider(label="CFG Scale", value=7, minimum=1, maximum=20, step=1) |
|
with gr.Row(): |
|
|
|
strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001) |
|
with gr.Row(): |
|
|
|
seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1) |
|
with gr.Row(): |
|
|
|
method = gr.Radio(label="Sampling method", value="DPM++ 2M Karras", choices=["DPM++ 2M Karras", "DPM++ SDE Karras", "Euler", "Euler a", "Heun", "DDIM"]) |
|
|
|
|
|
with gr.Tab("Image Editor"): |
|
|
|
def sleep(im): |
|
print("Sleeping for 5 seconds...") |
|
time.sleep(5) |
|
return [im["background"], im["layers"][0], im["layers"][1], im["composite"]] |
|
|
|
|
|
def predict(im): |
|
print("Predicting composite image...") |
|
return im["composite"] |
|
|
|
with gr.Blocks() as demo: |
|
with gr.Row(): |
|
|
|
im = gr.ImageEditor( |
|
type="numpy", |
|
crop_size="1:1", |
|
) |
|
|
|
|
|
with gr.Tab("Information"): |
|
with gr.Row(): |
|
|
|
gr.Textbox(label="Sample prompt", value="{prompt} | ultra detail, ultra elaboration, ultra quality, perfect.") |
|
|
|
|
|
with gr.Accordion("Featured Models (WiP)", open=False): |
|
gr.HTML( |
|
""" |
|
<p><a href="https://huggingface.co/models?inference=warm&pipeline_tag=text-to-image&sort=trending">See all available models</a></p> |
|
<table style="width:100%; text-align:center; margin:auto;"> |
|
<tr> |
|
<th>Model Name</th> |
|
<th>Typography</th> |
|
<th>Notes</th> |
|
</tr> |
|
<tr> |
|
<td>FLUX.1 Dev</td> |
|
<td>✅</td> |
|
<td></td> |
|
</tr> |
|
<tr> |
|
<td>FLUX.1 Schnell</td> |
|
<td>✅</td> |
|
<td></td> |
|
</tr> |
|
<tr> |
|
<td>Stable Diffusion 3.5 Large</td> |
|
<td>✅</td> |
|
<td></td> |
|
</tr> |
|
</table> |
|
""" |
|
) |
|
|
|
|
|
with gr.Accordion("Advanced Settings Overview", open=False): |
|
gr.Markdown( |
|
""" |
|
## Negative Prompt |
|
###### 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. |
|
|
|
## Width & Height |
|
###### These sliders allow you to specify the resolution of your image. Default value is 1024x1024, and maximum output is 1216x1216. |
|
|
|
## Sampling Steps |
|
###### 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. |
|
|
|
## CFG Scale |
|
###### 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". |
|
|
|
## Sampling Method |
|
###### 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. |
|
|
|
## Strength |
|
###### 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. |
|
|
|
## Seed |
|
###### 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. |
|
|
|
### 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! |
|
""" |
|
) |
|
|
|
|
|
with gr.Row(): |
|
text_button = gr.Button("Run", variant='primary', elem_id="gen-button") |
|
|
|
with gr.Row(): |
|
image_output = gr.Image(type="pil", label="Image Output", elem_id="gallery") |
|
|
|
|
|
text_button.click(query, inputs=[text_prompt, model, custom_lora, negative_prompt, steps, cfg, method, seed, strength, width, height], outputs=image_output) |
|
|
|
print("Launching Gradio interface...") |
|
|
|
dalle.launch(show_api=False, share=False) |