milkydevs commited on
Commit
e5d17b8
·
verified ·
1 Parent(s): cd4c73a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +100 -105
app.py CHANGED
@@ -1,153 +1,148 @@
1
- from contextlib import nullcontext
2
- from diffusers import EulerAncestralDiscreteScheduler, StableDiffusionXLPipeline
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()
 
1
+ import spaces # <-- DAPAT ITO ANG PINAKAUNANG LINYA BAGO ANG LAHAT!
2
+
3
+ import gc
 
4
  import torch
5
+ import gradio as gr
6
+ from diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
7
 
8
+ # =========================================================================
9
+ # LAHAT NG 8 CHECKPOINT MODELS MULA SA HUGGING FACE
10
+ # =========================================================================
11
  MODELS = {
12
+ "SpatterXL v1.7 (Illustrious x Pony)": {
13
+ "type": "pretrained",
14
+ "path": "John6666/spatterxl-illustriousxl-ponyxl-v15-sdxl"
15
+ },
16
+ "Solmeleon-XL (NoobAI x Illustrious)": {
17
+ "type": "pretrained",
18
+ "path": "John6666/solmeleon-illustriousxl-v10-sdxl"
19
+ },
20
+ "HoneyMix PonyXL (High Contrast Anime)": {
21
+ "type": "pretrained",
22
+ "path": "John6666/honey-mix-xl-high-contrast-anime-checkpoint-v1-sdxl"
23
+ },
24
+ "Pony Diffusion V6 XL (Waifu & NSFW)": {
25
+ "type": "single_file",
26
+ "path": "https://huggingface.co/LyliaEngine/Pony_Diffusion_V6_XL/resolve/main/ponyDiffusionV6XL_v6StartWithThisOne.safetensors"
27
+ },
28
+ "Illustrious-XL v0.1 (Official Base)": {
29
+ "type": "single_file",
30
+ "path": "https://huggingface.co/OnomaAIResearch/Illustrious-xl-early-release-v0/resolve/main/Illustrious-XL-v0.1.safetensors"
31
+ },
32
+ "Hoseki LustrousMix (Vibrant Anime)": {
33
+ "type": "single_file",
34
+ "path": "https://huggingface.co/LyliaEngine/hosekiLustrousmixAnima_animaV10/resolve/main/hosekiLustrousmixAnima_animaV10.safetensors"
35
+ },
36
+ "Initium-XL (NoobAI Epsilon 1.1)": {
37
+ "type": "single_file",
38
+ "path": "https://huggingface.co/John6666/initium-finetune-noobaiepsilon11-v10-sdxl/resolve/main/initium-finetune-noobaiepsilon11-v10-sdxl.safetensors"
39
+ },
40
+ "Tryptophan-666 (Illustrious x Pony XL)": {
41
+ "type": "single_file",
42
+ "path": "https://huggingface.co/John6666/tryptophan-666-illustrious-xl-pony-compatable-v1666-sdxl/resolve/main/tryptophan-666-illustrious-xl-pony-compatable-v1666-sdxl.safetensors"
43
+ }
44
  }
45
 
46
  current_model_name = None
47
  pipe = None
48
 
 
49
  def load_pipeline(model_choice):
50
  global pipe, current_model_name
51
  if pipe is None or current_model_name != model_choice:
52
+ if pipe is not None:
53
+ del pipe
54
+ gc.collect()
55
+ torch.cuda.empty_cache()
56
+
57
+ cfg = MODELS[model_choice]
58
+ print(f"Loading checkpoint: {model_choice}...")
59
+
60
+ if cfg["type"] == "pretrained":
61
+ pipe = StableDiffusionXLPipeline.from_pretrained(
62
+ cfg["path"],
63
+ torch_dtype=torch.float16,
64
+ use_safetensors=True
65
+ )
66
+ else:
67
+ pipe = StableDiffusionXLPipeline.from_single_file(
68
+ cfg["path"],
69
+ torch_dtype=torch.float16,
70
+ use_safetensors=True
71
+ )
72
+
73
+ pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
74
  current_model_name = model_choice
75
  return pipe
76
 
77
+ # ZeroGPU: Dynamic Nvidia A100 GPU Allocation
 
78
  @spaces.GPU(duration=45)
79
+ def generate_image(prompt, negative_prompt, model_choice, width, height, steps, cfg_scale, seed):
 
 
80
  pipeline = load_pipeline(model_choice)
81
  pipeline.to("cuda")
82
+
83
  generator = None
84
  if seed != -1:
85
+ generator = torch.Generator(device="cuda").manual_seed(int(seed))
86
+
87
+ is_pony_family = any(k in model_choice for k in ["Pony", "Spatter", "Honey", "Tryptophan", "Initium"])
88
+ if is_pony_family and "score_9" not in prompt:
89
+ prompt = "score_9, score_8_up, score_7_up, source_anime, " + prompt + ", masterpiece, best quality"
90
+ negative_prompt = "score_4, score_5, score_6, ugly, deformed, blurry, bad anatomy, " + negative_prompt
91
+ elif "masterpiece" not in prompt:
92
+ prompt = "masterpiece, best quality, very aesthetic, " + prompt
93
+ negative_prompt = "ugly, deformed, blurry, bad hands, low quality, " + negative_prompt
 
 
 
 
94
 
95
  image = pipeline(
96
  prompt=prompt,
97
  negative_prompt=negative_prompt,
98
+ width=int(width),
99
+ height=int(height),
100
+ num_inference_steps=int(steps),
101
+ guidance_scale=float(cfg_scale),
102
+ generator=generator
103
  ).images[0]
104
+
105
  return image
106
 
 
 
107
  custom_css = """
108
  body, .gradio-container { background-color: #141414 !important; color: #ffffff !important; }
109
  button.primary { background: linear-gradient(90deg, #E50914 0%, #b80710 100%) !important; border: none !important; color: white !important; font-weight: bold !important; }
110
  """
111
 
112
  with gr.Blocks(css=custom_css, theme=gr.themes.Base()) as demo:
113
+ gr.Markdown("""
114
+ # 👑 QUEENDOM STUDIO — ZeroGPU Backend (8 Models)
 
115
  High-Performance SDXL, Pony, and Illustrious Generator powered by free dynamic Nvidia A100.
116
+ """)
117
+
 
118
  with gr.Row():
119
  with gr.Column(scale=1):
120
  model_dd = gr.Dropdown(
121
  choices=list(MODELS.keys()),
122
+ value="SpatterXL v1.7 (Illustrious x Pony)",
123
+ label="Select Checkpoint Model"
124
  )
125
+ prompt_input = gr.Textbox(label="Positive Prompt", lines=3, value="1girl, solo, silver hair, golden eyes, beautiful anime waifu")
126
+ neg_prompt_input = gr.Textbox(label="Negative Prompt", lines=2, value="ugly, deformed, blurry, bad anatomy")
127
+
 
 
 
 
 
 
 
 
128
  with gr.Row():
129
+ width_slider = gr.Slider(512, 1216, value=832, step=64, label="Width")
130
+ height_slider = gr.Slider(512, 1216, value=1216, step=64, label="Height")
131
+
 
 
 
 
132
  with gr.Row():
133
+ steps_slider = gr.Slider(15, 40, value=26, step=1, label="Steps")
134
+ cfg_slider = gr.Slider(3.0, 10.0, value=6.0, step=0.5, label="CFG Scale")
135
+
 
 
 
 
136
  seed_input = gr.Number(value=-1, label="Seed (-1 for Random)")
137
+ generate_btn = gr.Button("✨ GENERATE ARTWORK", variant="primary", elem_classes=["primary"])
138
+
 
 
139
  with gr.Column(scale=1):
140
  output_img = gr.Image(label="Rendered Artwork", type="pil")
141
+
142
  generate_btn.click(
143
  fn=generate_image,
144
+ inputs=[prompt_input, neg_prompt_input, model_dd, width_slider, height_slider, steps_slider, cfg_slider, seed_input],
145
+ outputs=output_img
 
 
 
 
 
 
 
 
 
146
  )
147
 
148
  demo.queue().launch()