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XLPipeline
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import spaces
|
| 5 |
+
import torch
|
| 6 |
+
|
| 7 |
+
# Listahan ng models (Hugging Face Repositories)
|
| 8 |
+
MODELS = {
|
| 9 |
+
"Pony Diffusion V6 XL": (
|
| 10 |
+
"LyliaEngine/Pony_Diffusion_V6_XL",
|
| 11 |
+
"ponyDiffusionV6XL_v6StartWithThisOne.safetensors",
|
| 12 |
+
),
|
| 13 |
+
"Illustrious-XL v0.1": (
|
| 14 |
+
"OnomaAIResearch/Illustrious-xl-early-release-v0",
|
| 15 |
+
"Illustrious-XL-v0.1.safetensors",
|
| 16 |
+
),
|
| 17 |
+
"HolyMix Illustrious": (
|
| 18 |
+
"John6666/holy-mix-illustriousxl-vibrant-anime-checkpoint-v1-sdxl",
|
| 19 |
+
"holy-mix-illustriousxl-vibrant-anime-checkpoint-v1-sdxl.safetensors",
|
| 20 |
+
),
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
current_model_name = None
|
| 24 |
+
pipe = None
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def load_pipeline(model_choice):
|
| 28 |
+
global pipe, current_model_name
|
| 29 |
+
if pipe is None or current_model_name != model_choice:
|
| 30 |
+
repo_id, filename = MODELS[model_choice]
|
| 31 |
+
print(f"Loading {model_choice}...")
|
| 32 |
+
|
| 33 |
+
pipe = StableDiffusionXLPipeline.from_single_file(
|
| 34 |
+
f"https://huggingface.co/{repo_id}/resolve/main/{filename}",
|
| 35 |
+
torch_dtype=torch.float16,
|
| 36 |
+
use_safetensors=True,
|
| 37 |
+
)
|
| 38 |
+
pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(
|
| 39 |
+
pipe.scheduler.config
|
| 40 |
+
)
|
| 41 |
+
current_model_name = model_choice
|
| 42 |
+
return pipe
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
# ZeroGPU: Inilalaan lamang ang Nvidia A100 habang tumatakbo ang function na ito
|
| 46 |
+
@spaces.GPU(duration=45)
|
| 47 |
+
def generate_image(
|
| 48 |
+
prompt, negative_prompt, model_choice, width, height, steps, cfg_scale, seed
|
| 49 |
+
):
|
| 50 |
+
pipeline = load_pipeline(model_choice)
|
| 51 |
+
pipeline.to("cuda")
|
| 52 |
+
|
| 53 |
+
generator = None
|
| 54 |
+
if seed != -1:
|
| 55 |
+
generator = torch.Generator(device="cuda").manual_seed(seed)
|
| 56 |
+
|
| 57 |
+
# Siguraduhin ang kalidad para sa Anime / Pony tags
|
| 58 |
+
if "score_9" not in prompt and "Pony" in model_choice:
|
| 59 |
+
prompt = (
|
| 60 |
+
"score_9, score_8_up, score_7_up, source_anime, "
|
| 61 |
+
+ prompt
|
| 62 |
+
+ ", masterpiece, best quality"
|
| 63 |
+
)
|
| 64 |
+
negative_prompt = (
|
| 65 |
+
"score_4, score_5, score_6, ugly, deformed, blurry, bad anatomy, "
|
| 66 |
+
+ negative_prompt
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
image = pipeline(
|
| 70 |
+
prompt=prompt,
|
| 71 |
+
negative_prompt=negative_prompt,
|
| 72 |
+
width=width,
|
| 73 |
+
height=height,
|
| 74 |
+
num_inference_steps=steps,
|
| 75 |
+
guidance_scale=cfg_scale,
|
| 76 |
+
generator=generator,
|
| 77 |
+
).images[0]
|
| 78 |
+
|
| 79 |
+
return image
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
# Custom Netflix Dark CSS na tugma sa website mo
|
| 83 |
+
custom_css = """
|
| 84 |
+
body, .gradio-container { background-color: #141414 !important; color: #ffffff !important; }
|
| 85 |
+
button.primary { background: linear-gradient(90deg, #E50914 0%, #b80710 100%) !important; border: none !important; color: white !important; font-weight: bold !important; }
|
| 86 |
+
"""
|
| 87 |
+
|
| 88 |
+
with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as demo:
|
| 89 |
+
gr.Markdown(
|
| 90 |
+
"""
|
| 91 |
+
# 👑 QUEENDOM STUDIO — ZeroGPU Backend
|
| 92 |
+
High-Performance SDXL, Pony, and Illustrious Generator powered by free dynamic Nvidia A100.
|
| 93 |
+
"""
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
with gr.Row():
|
| 97 |
+
with gr.Column(scale=1):
|
| 98 |
+
model_dd = gr.Dropdown(
|
| 99 |
+
choices=list(MODELS.keys()),
|
| 100 |
+
value="Pony Diffusion V6 XL",
|
| 101 |
+
label="Checkpoint Model",
|
| 102 |
+
)
|
| 103 |
+
prompt_input = gr.Textbox(
|
| 104 |
+
label="Positive Prompt",
|
| 105 |
+
lines=3,
|
| 106 |
+
value="1girl, solo, silver hair, golden eyes, beautiful anime waifu",
|
| 107 |
+
)
|
| 108 |
+
neg_prompt_input = gr.Textbox(
|
| 109 |
+
label="Negative Prompt",
|
| 110 |
+
lines=2,
|
| 111 |
+
value="ugly, deformed, low quality",
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
with gr.Row():
|
| 115 |
+
width_slider = gr.Slider(
|
| 116 |
+
512, 1216, value=832, step=64, label="Width"
|
| 117 |
+
)
|
| 118 |
+
height_slider = gr.Slider(
|
| 119 |
+
512, 1216, value=1216, step=64, label="Height"
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
with gr.Row():
|
| 123 |
+
steps_slider = gr.Slider(
|
| 124 |
+
15, 40, value=25, step=1, label="Steps"
|
| 125 |
+
)
|
| 126 |
+
cfg_slider = gr.Slider(
|
| 127 |
+
3.0, 10.0, value=6.5, step=0.5, label="CFG Scale"
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
seed_input = gr.Number(value=-1, label="Seed (-1 for Random)")
|
| 131 |
+
generate_btn = gr.Button(
|
| 132 |
+
"✨ GENERATE ARTWORK", variant="primary", elem_classes=["primary"]
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
with gr.Column(scale=1):
|
| 136 |
+
output_img = gr.Image(label="Rendered Artwork", type="pil")
|
| 137 |
+
|
| 138 |
+
generate_btn.click(
|
| 139 |
+
fn=generate_image,
|
| 140 |
+
inputs=[
|
| 141 |
+
prompt_input,
|
| 142 |
+
neg_prompt_input,
|
| 143 |
+
model_dd,
|
| 144 |
+
width_slider,
|
| 145 |
+
height_slider,
|
| 146 |
+
steps_slider,
|
| 147 |
+
cfg_slider,
|
| 148 |
+
seed_input,
|
| 149 |
+
],
|
| 150 |
+
outputs=output_img,
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
demo.queue().launch()
|