import spaces import gradio as gr from huggingface_hub import ModelCard from config import Config from .models import * from .handlers import gen_img # Common def update_model_options(model): for m in Config.IMAGES_MODELS: if m['repo_id'] == model: if m['loader'] == 'flux': return ( gr.update( # negative_prompt visible=False ), gr.update( # lora_gallery value=[(lora['image'], lora['title']) for lora in Config.IMAGES_LORAS_FLUX] ), gr.update( # embeddings_accordion visible=False ), gr.update( # scribble_tab visible=False ), gr.update( # scheduler value='fm_euler' ), gr.update( # image_clip_skip visible=False ), gr.update( # image_guidance_scale value=3.5 ) ) elif m['loader'] == 'sdxl': return ( gr.update( # negative_prompt visible=True ), gr.update( # lora_gallery value=[(lora['image'], lora['title']) for lora in Config.IMAGES_LORAS_SDXL] ), gr.update( # embeddings_accordion visible=True ), gr.update( # scribble_tab visible=True ), gr.update( # scheduler value='dpmpp_2m_sde_k' ), gr.update( # image_clip_skip visible=True ), gr.update( # image_guidance_scale value=7.0 ) ) def update_fast_generation(model, fast_generation): for m in Config.IMAGES_MODELS: if m['repo_id'] == model: if m['loader'] == 'flux': if fast_generation: return ( gr.update( # image_num_inference_steps value=8 ), gr.update( # image_guidance_scale value=3.5 ) ) else: return ( gr.update( # image_num_inference_steps value=20 ), gr.update( # image_guidance_scale value=3.5 ) ) elif m['loader'] == 'sdxl': if fast_generation: return ( gr.update( # image_num_inference_steps value=8 ), gr.update( # image_guidance_scale value=1.0 ) ) else: return ( gr.update( # image_num_inference_steps value=20 ), gr.update( # image_guidance_scale value=7.0 ) ) # Loras def selected_lora_from_gallery(evt: gr.SelectData): return ( gr.update( value=evt.index ) ) def update_selected_lora(custom_lora): link = custom_lora.split("/") if len(link) == 2: model_card = ModelCard.load(custom_lora) trigger_word = model_card.data.get("instance_prompt", "") image_url = f"""https://huggingface.co/{custom_lora}/resolve/main/{model_card.data.get("widget", [{}])[0].get("output", {}).get("url", None)}""" custom_lora_info_css = """ """ custom_lora_info_html = f"""