Spaces:
Runtime error
Runtime error
Update app.py
Browse files66 unmodified lines67686970717273747576777879808 unmodified lines899091929394953 unmodified lines991001011021031041058 unmodified lines1141151161171181191203 unmodified lines1241251261271281291302 unmodified lines1331341351361371381391401411421431441451461471481491502 unmodified lines15315415515615715815916066 unmodified lineswidth, height = resolution, int(resolution * 9 / 21)else: # Fallbackwidth, height = resolution, resolution# Ensure dimensions are multiples of 64 for optimal performancewidth = (width // 64) * 64height = (height // 64) * 64return width, heightdef generate_image(prompt_mash, steps, seed, cfg_scale, width, height, progress):"""Generator function for text-to-image with live preview."""# The parent @spaces.GPU function has already allocated a GPUpipe.to(device)generator = torch.Generator(device=device).manual_seed(seed)8 unmodified linesoutput_type="pil",good_vae=good_vae,)# Yield previews and the final imagefinal_image = Nonefor i, image in enumerate(image_generator):final_image = image3 unmodified linesdef update_history(new_image, history):"""Adds the new image to the history gallery."""if new_image is None: # Don't add empty images on errorreturn historyif history is None:history = []8 unmodified linesprompt_mash = f"{KRYPTO_LORA['trigger']}, {prompt}"print("Final prompt:", prompt_mash)# Activate the LoRA adapter with the slider's weightpipe.set_adapters([KRYPTO_LORA['adapter_name']], adapter_weights=[lora_scale])print(f"Adapter '{KRYPTO_LORA['adapter_name']}' activated with weight {lora_scale}.")3 unmodified lineswidth, height = calculate_dimensions(aspect_ratio, base_resolution)print(f"Generating a {width}x{height} image.")# The function now only handles text-to-imagefor image, progress_update in generate_image(prompt_mash, steps, seed, cfg_scale, width, height, progress):yield image, seed, progress_update2 unmodified lines# --- User Interface (Gradio) ---css = '''#title{text-align: center}#title h1{font-size: 3em; display:inline-flex; align-items:center}#title img{width: 80px; margin-right: 0.25em}.progress-container {width: 100%;height: 30px;background-color: #f0f0f0;border-radius: 15px;overflow: hidden;margin-bottom: 20px}.progress-bar {height: 100%;background-color: #4f46e5;width: calc(var(--current) / var(--total) * 100%);transition: width 0.1s ease-in-out}#random_prompt_btn{max-width: 2.5em; min-width: 2.5em !important; height: 100% !important;}'''with gr.Blocks(css=css, theme=gr.themes.Soft()) as app:# --- Header ---with gr.Row():gr.HTML("""<div id='title'><h1><img src="https://huggingface.co/Econogoat/KRYPTO_LORA/resolve/main/krypt0.png" alt="LoRA"> Krypt0 Image Generator</h1><br><span>Generate images with the Krypt0 artistic style</span></div>""")with gr.Row():2 unmodified lines# Prompt and Style Controlswith gr.Group():with gr.Row():random_prompt_btn = gr.Button("🎲", elem_id="random_prompt_btn")prompt = gr.Textbox(label="Prompt", lines=2, placeholder="e.g., a portrait of a warrior queen", scale=8)lora_scale = gr.Slider(label="Krypt0 Style Strength", minimum=0, maximum=2, step=0.05, value=0.9)66 unmodified lines6768697071727374757677788 unmodified lines8788899091923 unmodified lines969798991001011028 unmodified lines1111121131141151163 unmodified lines1201211221231241252 unmodified lines1281291301311321331341351361371381391401411421431441451461471482 unmodified lines15115215315415515615715815916066 unmodified lineswidth, height = resolution, int(resolution * 9 / 21)else: # Fallbackwidth, height = resolution, resolutionwidth = (width // 64) * 64height = (height // 64) * 64return width, heightdef generate_image(prompt_mash, steps, seed, cfg_scale, width, height, progress):"""Generator function for text-to-image with live preview."""pipe.to(device)generator = torch.Generator(device=device).manual_seed(seed)8 unmodified linesoutput_type="pil",good_vae=good_vae,)final_image = Nonefor i, image in enumerate(image_generator):final_image = image3 unmodified linesdef update_history(new_image, history):"""Adds the new image to the history gallery."""if new_image is None:return historyif history is None:history = []8 unmodified linesprompt_mash = f"{KRYPTO_LORA['trigger']}, {prompt}"print("Final prompt:", prompt_mash)pipe.set_adapters([KRYPTO_LORA['adapter_name']], adapter_weights=[lora_scale])print(f"Adapter '{KRYPTO_LORA['adapter_name']}' activated with weight {lora_scale}.")3 unmodified lineswidth, height = calculate_dimensions(aspect_ratio, base_resolution)print(f"Generating a {width}x{height} image.")for image, progress_update in generate_image(prompt_mash, steps, seed, cfg_scale, width, height, progress):yield image, seed, progress_update2 unmodified lines# --- User Interface (Gradio) ---css = '''#title{text-align: center}#title h1{font-size: 3em; display:inline-flex; align-items:center; margin-bottom: 0.2em;}#title img{width: 70px; margin-right: 0.25em}.progress-container {width: 100%;height: 30px;background-color: #f0f0f0;border-radius: 15px;overflow: hidden;margin-bottom: 20px}.progress-bar {height: 100%;background-color: #4f46e5;width: calc(var(--current) / var(--total) * 100%);transition: width 0.1s ease-in-out}#random_prompt_btn { height: 100% !important; }'''with gr.Blocks(css=css, theme=gr.themes.Soft()) as app:# --- Header ---with gr.Row():gr.HTML("""<div id='title'><h1><img src="https://huggingface.co/Econogoat/KRYPTO_LORA/resolve/main/krypt0.png" alt="LoRA"> Krypto Image Generator - beta v1</h1><span>Powered by $Krypto | @Kryptocoinonsol</span></div>""")with gr.Row():2 unmodified lines# Prompt and Style Controlswith gr.Group():with gr.Row():with gr.Column(scale=1, min_width=150):random_prompt_btn = gr.Button("Random Prompt", elem_id="random_prompt_btn")with gr.Column(scale=5):prompt = gr.Textbox(label="Prompt", lines=2, placeholder="e.g., a portrait of a warrior queen")lora_scale = gr.Slider(label="Krypt0 Style Strength", minimum=0, maximum=2, step=0.05, value=0.9)
app.py+12-12