AIBRUH commited on
Commit
b2e4fa9
Β·
verified Β·
1 Parent(s): 2e6ba46

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +307 -0
app.py ADDED
@@ -0,0 +1,307 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ import time
4
+ import random
5
+ import os
6
+ from diffusers import StableDiffusionXLPipeline, DPMSolverMultistepScheduler
7
+
8
+ # ═══════════════════════════════════════════════════════════════
9
+ # EDEN REALISM ENGINE β€” Juggernaut XL v9 + Six Pillars
10
+ # Beryl AI Labs / The Eden Project
11
+ # ═══════════════════════════════════════════════════════════════
12
+
13
+ EDEN_NEGATIVE = """(worst quality:1.8), (low quality:1.8), (airbrushed:1.6), (plastic:1.6), (shiny skin:1.6),
14
+ (glossy skin:1.5), (waxy:1.5), (porcelain:1.5), (3d render:1.4), (cgi:1.3), (digital art:1.4),
15
+ (bad anatomy:1.5), (deformed:1.6), cartoon, anime, illustration, painting, drawing, sketch,
16
+ doll-like, mannequin, beauty filter, over-retouched, dead eyes, silicone skin, rubber skin,
17
+ uniform skin tone, missing pores, painted skin texture, photoshop skin, facetune skin,
18
+ glossy lips, glowing skin, filtered, beautified, retouched"""
19
+
20
+ EDEN_SKIN_BOOST = """natural skin texture, visible pores, vellus hair, subsurface scattering,
21
+ skin imperfections, matte skin finish, micro-texture detail, pore-level detail,
22
+ natural redness variation, natural sebum balance"""
23
+
24
+ PRESETS = {
25
+ "Maximum Naturalism": {"sampler": "DPM++ SDE Karras", "steps": 50, "cfg": 4.0, "desc": "Most natural skin β€” DPM++ SDE Karras"},
26
+ "Balanced Quality": {"sampler": "DPM++ 2M Karras", "steps": 40, "cfg": 4.5, "desc": "DEFAULT β€” best all-round"},
27
+ "Ultra Detail": {"sampler": "DPM++ SDE Karras", "steps": 60, "cfg": 4.5, "desc": "Face close-ups β€” every pore matters"},
28
+ "Portrait": {"sampler": "DPM++ 2M Karras", "steps": 35, "cfg": 4.0, "desc": "Fast portrait β€” natural skin"},
29
+ "Cinematic": {"sampler": "DPM++ 2M Karras", "steps": 45, "cfg": 5.0, "desc": "Film-grade β€” ARRI/RED look"},
30
+ }
31
+
32
+ RESOLUTIONS = {
33
+ "1024Γ—1024 (1:1)": (1024, 1024),
34
+ "832Γ—1248 (2:3 Portrait)": (832, 1248),
35
+ "1248Γ—832 (3:2 Landscape)": (1248, 832),
36
+ "768Γ—1344 (9:16 Phone)": (768, 1344),
37
+ "1344Γ—768 (16:9 Cinema)": (1344, 768),
38
+ "896Γ—1152 (7:9)": (896, 1152),
39
+ "1152Γ—896 (9:7)": (1152, 896),
40
+ }
41
+
42
+ LIGHTING = {
43
+ "None (manual)": "",
44
+ "Rembrandt": "Rembrandt lighting, triangle of light on shadow-side cheek, warm key at 3200K",
45
+ "Butterfly / Paramount": "butterfly Paramount lighting, light directly above and in front, classic beauty",
46
+ "Golden Hour": "soft golden hour lighting, warm backlight, natural sun flare",
47
+ "Studio Softbox": "professional studio softbox lighting, even illumination, beauty dish",
48
+ "Chiaroscuro": "dramatic chiaroscuro lighting, deep shadows, single hard key light",
49
+ "Neon Noir": "neon-lit environment, cyan and magenta rim lights, noir atmosphere",
50
+ "Natural Window": "soft natural window light, diffused daylight, gentle shadows",
51
+ }
52
+
53
+ CAMERAS = {
54
+ "None (manual)": "",
55
+ "ARRI ALEXA 35 85mm f/1.4": "shot on ARRI ALEXA 35 85mm f1.4, shallow depth of field, film grain, Kodak Vision3 500T",
56
+ "RED V-RAPTOR 8K 50mm f/1.8": "shot on RED V-RAPTOR 8K 50mm f1.8, cinematic depth of field",
57
+ "Canon R5 85mm f/1.4": "shot on Canon R5 85mm f1.4, shallow depth of field, photorealistic",
58
+ "Sony Venice 2 35mm anamorphic": "shot on Sony Venice 2 35mm anamorphic, cinematic aspect ratio, lens flare",
59
+ "Hasselblad X2D 90mm f/2.5": "shot on Hasselblad X2D 90mm f2.5, medium format, extraordinary detail",
60
+ }
61
+
62
+ print("Loading Juggernaut XL v9...")
63
+ pipe = StableDiffusionXLPipeline.from_pretrained(
64
+ "RunDiffusion/Juggernaut-XL-v9",
65
+ torch_dtype=torch.float16,
66
+ variant="fp16",
67
+ use_safetensors=True,
68
+ )
69
+ pipe.to("cuda")
70
+ print("Model loaded on GPU.")
71
+
72
+ def set_scheduler(pipe, sampler_name):
73
+ if "SDE" in sampler_name:
74
+ from diffusers import DPMSolverSDEScheduler
75
+ pipe.scheduler = DPMSolverSDEScheduler.from_config(
76
+ pipe.scheduler.config,
77
+ use_karras_sigmas=True,
78
+ noise_sampler_seed=None,
79
+ )
80
+ else:
81
+ pipe.scheduler = DPMSolverMultistepScheduler.from_config(
82
+ pipe.scheduler.config,
83
+ algorithm_type="dpmsolver++",
84
+ solver_order=2,
85
+ use_karras_sigmas=True,
86
+ )
87
+
88
+ def build_prompt(user_prompt, lighting, camera, skin_boost, enhance_realism):
89
+ parts = [user_prompt.strip()]
90
+ if skin_boost:
91
+ parts.append(EDEN_SKIN_BOOST)
92
+ if lighting != "None (manual)" and LIGHTING.get(lighting):
93
+ parts.append(LIGHTING[lighting])
94
+ if camera != "None (manual)" and CAMERAS.get(camera):
95
+ parts.append(CAMERAS[camera])
96
+ if enhance_realism:
97
+ parts.append("photorealistic, 8k, RAW photo, unretouched")
98
+ return ", ".join(parts)
99
+
100
+ def build_negative(user_negative, use_smart_negative):
101
+ if use_smart_negative:
102
+ if user_negative.strip():
103
+ return f"{EDEN_NEGATIVE}, {user_negative.strip()}"
104
+ return EDEN_NEGATIVE
105
+ return user_negative
106
+
107
+ def generate(
108
+ prompt, negative_prompt, preset, resolution,
109
+ lighting, camera, skin_boost, enhance_realism, smart_negative,
110
+ cfg_override, steps_override, seed, use_overrides
111
+ ):
112
+ if not prompt.strip():
113
+ return None, "Enter a prompt first."
114
+
115
+ p = PRESETS.get(preset, PRESETS["Balanced Quality"])
116
+ cfg = cfg_override if use_overrides else p["cfg"]
117
+ steps = int(steps_override) if use_overrides else p["steps"]
118
+ sampler = p["sampler"]
119
+
120
+ w, h = RESOLUTIONS.get(resolution, (1024, 1024))
121
+
122
+ set_scheduler(pipe, sampler)
123
+
124
+ full_prompt = build_prompt(prompt, lighting, camera, skin_boost, enhance_realism)
125
+ full_negative = build_negative(negative_prompt, smart_negative)
126
+
127
+ if seed == -1:
128
+ seed = random.randint(0, 2**32 - 1)
129
+ generator = torch.Generator(device="cuda").manual_seed(seed)
130
+
131
+ start = time.time()
132
+ image = pipe(
133
+ prompt=full_prompt,
134
+ negative_prompt=full_negative,
135
+ num_inference_steps=steps,
136
+ guidance_scale=cfg,
137
+ height=h,
138
+ width=w,
139
+ generator=generator,
140
+ ).images[0]
141
+ elapsed = time.time() - start
142
+
143
+ info = f"βœ… {elapsed:.1f}s | {w}Γ—{h} | {sampler} | {steps} steps | CFG {cfg} | Seed {seed}"
144
+ return image, info
145
+
146
+ def batch_generate(
147
+ prompts_text, negative_prompt, preset, resolution,
148
+ lighting, camera, skin_boost, enhance_realism, smart_negative,
149
+ cfg_override, steps_override, use_overrides
150
+ ):
151
+ prompts = [p.strip() for p in prompts_text.strip().split("\n") if p.strip()]
152
+ if not prompts:
153
+ return [], "Enter at least one prompt (one per line)."
154
+
155
+ images = []
156
+ infos = []
157
+ for i, prompt in enumerate(prompts):
158
+ seed = random.randint(0, 2**32 - 1)
159
+ img, info = generate(
160
+ prompt, negative_prompt, preset, resolution,
161
+ lighting, camera, skin_boost, enhance_realism, smart_negative,
162
+ cfg_override, steps_override, seed, use_overrides
163
+ )
164
+ if img:
165
+ images.append(img)
166
+ infos.append(f"[{i+1}] {info}")
167
+
168
+ return images, "\n".join(infos)
169
+
170
+ # ═══════════════════════════════════════════════════════════════
171
+ # GRADIO UI
172
+ # ═══════════════════════════════════════════════════════════════
173
+
174
+ THEME = gr.themes.Base(
175
+ primary_hue=gr.themes.Color(c50="#fdf8e8", c100="#f5e6a3", c200="#d4af37", c300="#c5b358", c400="#b8a040", c500="#8b6914", c600="#6b4f0a", c700="#5a4208", c800="#3a2d18", c900="#1a140a", c950="#0a0604"),
176
+ neutral_hue=gr.themes.Color(c50="#e8dcc8", c100="#c5b99a", c200="#8b7355", c300="#6b5b3d", c400="#3a2d18", c500="#2a1f12", c600="#1a140a", c700="#151008", c800="#0d0906", c900="#0a0604", c950="#050302"),
177
+ font=["Cinzel", "serif"],
178
+ font_mono=["DM Mono", "monospace"],
179
+ )
180
+
181
+ CSS = """
182
+ @import url('https://fonts.googleapis.com/css2?family=Cinzel+Decorative:wght@700&family=Cinzel:wght@500;700&family=DM+Mono&display=swap');
183
+ .gradio-container { background: #050302 !important; }
184
+ footer { display: none !important; }
185
+ .gold-header {
186
+ text-align: center; padding: 20px 0 10px 0;
187
+ background: linear-gradient(135deg, #6b4f0a, #c5b358, #f5e6a3, #d4af37, #c5b358, #6b4f0a);
188
+ -webkit-background-clip: text; -webkit-text-fill-color: transparent;
189
+ font-family: 'Cinzel Decorative', serif; font-size: 28px; font-weight: 700; letter-spacing: 4px;
190
+ }
191
+ .eden-sub { text-align: center; color: #8b7355; font-family: 'Cinzel', serif; font-size: 12px; letter-spacing: 3px; margin-bottom: 16px; }
192
+ """
193
+
194
+ with gr.Blocks(theme=THEME, css=CSS, title="EDEN Realism Engine") as app:
195
+ gr.HTML("<div class='gold-header'>πŸ”± EDEN REALISM ENGINE</div>")
196
+ gr.HTML("<div class='eden-sub'>JUGGERNAUT XL v9 Β· SIX PILLARS OF PHOTOREALISM Β· BERYL AI LABS</div>")
197
+
198
+ with gr.Tabs():
199
+ # ─── TAB 1: GENERATE ───
200
+ with gr.Tab("⚑ Generate"):
201
+ with gr.Row():
202
+ with gr.Column(scale=2):
203
+ prompt = gr.Textbox(label="Prompt", placeholder="Describe your scene β€” skin keywords auto-boost if enabled...", lines=4)
204
+ negative = gr.Textbox(label="Custom Negative (added to Smart Negative)", placeholder="Optional extra negatives...", lines=2)
205
+
206
+ with gr.Row():
207
+ preset = gr.Dropdown(choices=list(PRESETS.keys()), value="Balanced Quality", label="Eden Preset")
208
+ resolution = gr.Dropdown(choices=list(RESOLUTIONS.keys()), value="1024Γ—1024 (1:1)", label="Resolution")
209
+
210
+ with gr.Row():
211
+ lighting = gr.Dropdown(choices=list(LIGHTING.keys()), value="None (manual)", label="Lighting Setup")
212
+ camera = gr.Dropdown(choices=list(CAMERAS.keys()), value="None (manual)", label="Camera / Lens")
213
+
214
+ with gr.Row():
215
+ skin_boost = gr.Checkbox(value=True, label="Skin Detail Boost")
216
+ enhance = gr.Checkbox(value=True, label="Enhance Realism")
217
+ smart_neg = gr.Checkbox(value=True, label="Smart Negative Engine")
218
+
219
+ with gr.Accordion("Advanced Overrides", open=False):
220
+ use_overrides = gr.Checkbox(value=False, label="Use Manual Overrides")
221
+ cfg_slider = gr.Slider(1.0, 10.0, value=4.5, step=0.5, label="CFG Scale (Eden Standard: 4.0-4.5)")
222
+ steps_slider = gr.Slider(10, 80, value=40, step=5, label="Steps (Sweet spot: 30-50)")
223
+ seed_input = gr.Number(value=-1, label="Seed (-1 = random)")
224
+
225
+ gen_btn = gr.Button("πŸ”± GENERATE β€” EDEN PROTOCOL", variant="primary", size="lg")
226
+
227
+ with gr.Column(scale=2):
228
+ output_img = gr.Image(label="Output", type="pil", height=600)
229
+ info_box = gr.Textbox(label="Generation Info", interactive=False)
230
+
231
+ gen_btn.click(
232
+ fn=generate,
233
+ inputs=[prompt, negative, preset, resolution, lighting, camera, skin_boost, enhance, smart_neg, cfg_slider, steps_slider, seed_input, use_overrides],
234
+ outputs=[output_img, info_box],
235
+ )
236
+
237
+ # ─── TAB 2: BATCH ───
238
+ with gr.Tab("πŸ“¦ Batch Generate"):
239
+ gr.Markdown("### One prompt per line. Walk away β€” Eden handles the rest.")
240
+ with gr.Row():
241
+ with gr.Column():
242
+ batch_prompts = gr.Textbox(label="Prompts (one per line)", lines=10, placeholder="portrait of a woman in golden hour light\nclose-up beauty shot with Rembrandt lighting\nfull body editorial pose in studio")
243
+ batch_negative = gr.Textbox(label="Shared Negative", lines=2)
244
+
245
+ with gr.Row():
246
+ b_preset = gr.Dropdown(choices=list(PRESETS.keys()), value="Balanced Quality", label="Preset")
247
+ b_resolution = gr.Dropdown(choices=list(RESOLUTIONS.keys()), value="832Γ—1248 (2:3 Portrait)", label="Resolution")
248
+
249
+ with gr.Row():
250
+ b_lighting = gr.Dropdown(choices=list(LIGHTING.keys()), value="None (manual)", label="Lighting")
251
+ b_camera = gr.Dropdown(choices=list(CAMERAS.keys()), value="None (manual)", label="Camera")
252
+
253
+ with gr.Row():
254
+ b_skin = gr.Checkbox(value=True, label="Skin Boost")
255
+ b_enhance = gr.Checkbox(value=True, label="Enhance Realism")
256
+ b_smart = gr.Checkbox(value=True, label="Smart Negatives")
257
+
258
+ with gr.Accordion("Overrides", open=False):
259
+ b_override = gr.Checkbox(value=False, label="Use Overrides")
260
+ b_cfg = gr.Slider(1.0, 10.0, value=4.5, step=0.5, label="CFG")
261
+ b_steps = gr.Slider(10, 80, value=40, step=5, label="Steps")
262
+
263
+ batch_btn = gr.Button("πŸ“¦ BATCH GENERATE", variant="primary", size="lg")
264
+
265
+ with gr.Column():
266
+ batch_gallery = gr.Gallery(label="Results", columns=2, height=600)
267
+ batch_info = gr.Textbox(label="Batch Info", interactive=False, lines=6)
268
+
269
+ batch_btn.click(
270
+ fn=batch_generate,
271
+ inputs=[batch_prompts, batch_negative, b_preset, b_resolution, b_lighting, b_camera, b_skin, b_enhance, b_smart, b_cfg, b_steps, b_override],
272
+ outputs=[batch_gallery, batch_info],
273
+ )
274
+
275
+ # ─── TAB 3: REFERENCE ───
276
+ with gr.Tab("πŸ“– Eden Protocol"):
277
+ gr.Markdown("""
278
+ ## The Six Pillars of Photorealism
279
+
280
+ | Pillar | Setting | Eden Standard |
281
+ |--------|---------|--------------|
282
+ | **1. Sampler** | DPM++ 2M Karras | Preserves skin texture with minimal artifacts |
283
+ | **2. Steps** | 30-50 | 40 = sweet spot. 60 for ultra-detail close-ups |
284
+ | **3. CFG Scale** | 4.0-4.5 | NEVER above 7. #1 cause of AI slop |
285
+ | **4. Negatives** | Smart Negative Engine | 11 trigger categories, auto-activated |
286
+ | **5. Resolution** | 1024Γ—1024 base | Hires Fix 1.5x at 0.38 denoise |
287
+ | **6. Model** | Uncensored ONLY | Safety classifiers bias against melanin-rich skin |
288
+
289
+ ## The 0.3 Deviation Rule
290
+ No output drifts more than 0.3 from reference face texture. Pores stay. Freckles stay. Stretch marks stay.
291
+
292
+ ## Anti-Plastic Formula
293
+ 1. CFG at 4.0-4.5 (NEVER above 7)
294
+ 2. DPM++ Karras samplers (preserve texture)
295
+ 3. Full negative: (plastic:1.6), (shiny skin:1.6), (airbrushed:1.6)
296
+ 4. Skin Detail Boosters auto-appended
297
+ 5. Hires Fix at 0.38 denoise
298
+
299
+ ## The Test
300
+ **"Real as Fuck"** β€” Can you stare at her for 10 minutes and forget she is digital?
301
+
302
+ ---
303
+ *EDEN ALPHA-26 Β· Beryl AI Labs Β· Built for believers. Forged in panic. Deployed with conviction.*
304
+ """)
305
+
306
+ app.queue(max_size=20)
307
+ app.launch(server_name="0.0.0.0", server_port=7860)