prithivMLmods commited on
Commit
fc68e5b
·
verified ·
1 Parent(s): 8bc9387

update app [pipe]

Browse files
Files changed (1) hide show
  1. app.py +1189 -144
app.py CHANGED
@@ -5,12 +5,26 @@ import numpy as np
5
  import spaces
6
  import torch
7
  import random
 
 
 
 
8
  from PIL import Image
9
 
 
 
 
10
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
11
 
12
  print("CUDA_VISIBLE_DEVICES=", os.environ.get("CUDA_VISIBLE_DEVICES"))
13
  print("torch.__version__ =", torch.__version__)
 
 
 
 
 
 
 
14
  print("Using device:", device)
15
 
16
  from diffusers import FlowMatchEulerDiscreteScheduler
@@ -25,9 +39,9 @@ pipe = QwenImageEditPlusPipeline.from_pretrained(
25
  transformer=QwenImageTransformer2DModel.from_pretrained(
26
  "prithivMLmods/Qwen-Image-Edit-Rapid-AIO-V19",
27
  torch_dtype=dtype,
28
- device_map='cuda'
29
  ),
30
- torch_dtype=dtype
31
  ).to(device)
32
 
33
  try:
@@ -36,179 +50,1210 @@ try:
36
  except Exception as e:
37
  print(f"Warning: Could not set FA3 processor: {e}")
38
 
39
- MAX_SEED = np.iinfo(np.int32).max
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  def update_dimensions_on_upload(image):
42
  if image is None:
43
  return 1024, 1024
 
 
 
 
 
 
 
 
44
 
45
- original_width, original_height = image.size
46
 
47
- if original_width > original_height:
48
- new_width = 1024
49
- aspect_ratio = original_height / original_width
50
- new_height = int(new_width * aspect_ratio)
51
- else:
52
- new_height = 1024
53
- aspect_ratio = original_width / original_height
54
- new_width = int(new_height * aspect_ratio)
55
-
56
- new_width = (new_width // 8) * 8
57
- new_height = (new_height // 8) * 8
58
-
59
- return new_width, new_height
60
-
61
- @spaces.GPU(size="xlarge")
62
- def infer(
63
- images,
64
- prompt,
65
- seed,
66
- randomize_seed,
67
- guidance_scale,
68
- steps,
69
- progress=gr.Progress(track_tqdm=True)
70
- ):
71
  gc.collect()
72
  torch.cuda.empty_cache()
73
-
74
- if not images:
75
- raise gr.Error("Please upload at least one image to edit.")
76
-
77
- pil_images = []
78
- if images is not None:
79
- for item in images:
80
- try:
81
- if isinstance(item, tuple) or isinstance(item, list):
82
- path_or_img = item[0]
83
- else:
84
- path_or_img = item
85
-
86
- if isinstance(path_or_img, str):
87
- pil_images.append(Image.open(path_or_img).convert("RGB"))
88
- elif isinstance(path_or_img, Image.Image):
89
- pil_images.append(path_or_img.convert("RGB"))
90
- else:
91
- pil_images.append(Image.open(path_or_img.name).convert("RGB"))
92
- except Exception as e:
93
- print(f"Skipping invalid image item: {e}")
94
- continue
95
-
96
  if not pil_images:
97
- raise gr.Error("Could not process uploaded images.")
98
-
 
99
  if randomize_seed:
100
  seed = random.randint(0, MAX_SEED)
101
-
102
  generator = torch.Generator(device=device).manual_seed(seed)
103
  negative_prompt = "worst quality, low quality, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, jpeg artifacts, signature, watermark, username, blurry"
104
-
105
  width, height = update_dimensions_on_upload(pil_images[0])
106
-
107
  try:
108
  result_image = pipe(
109
- image=pil_images,
110
- prompt=prompt,
111
- negative_prompt=negative_prompt,
112
- height=height,
113
- width=width,
114
- num_inference_steps=steps,
115
- generator=generator,
116
- true_cfg_scale=guidance_scale,
117
  ).images[0]
118
-
119
  return result_image, seed
120
-
121
  except Exception as e:
122
  raise e
123
  finally:
124
  gc.collect()
125
  torch.cuda.empty_cache()
126
 
127
- @spaces.GPU(size="xlarge")
128
- def infer_example(images, prompt):
129
- if not images:
130
- return None, 0
131
 
132
- if isinstance(images, str):
133
- images_list = [images]
134
- else:
135
- images_list = images
136
-
137
- result, seed = infer(
138
- images=images_list,
139
- prompt=prompt,
140
- seed=0,
141
- randomize_seed=True,
142
- guidance_scale=1.0,
143
- steps=4
144
- )
145
- return result, seed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
 
147
- css = """
148
- #col-container {
149
- margin: 0 auto;
150
- max-width: 1000px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
151
  }
152
- #main-title h1 {font-size: 2.4em !important;}
153
  """
154
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  with gr.Blocks() as demo:
156
- with gr.Column(elem_id="col-container"):
157
- gr.Markdown("# **FireRed-Image-Edit-1.0-Fast - [v@1.1](https://huggingface.co/FireRedTeam/FireRed-Image-Edit-1.1)**", elem_id="main-title")
158
- gr.Markdown("Perform image edits using [FireRed-Image-Edit-1.0](https://huggingface.co/FireRedTeam/FireRed-Image-Edit-1.0) with 4-step fast inference. Open on [GitHub](https://github.com/PRITHIVSAKTHIUR/FireRed-Image-Edit-1.0-Fast)")
159
-
160
- with gr.Row(equal_height=True):
161
- with gr.Column():
162
- images = gr.Gallery(
163
- label="Upload Images",
164
- type="filepath",
165
- columns=2,
166
- rows=1,
167
- height=300,
168
- allow_preview=True
169
- )
170
-
171
- prompt = gr.Text(
172
- label="Edit Prompt",
173
- show_label=True,
174
- max_lines=2,
175
- placeholder="e.g., transform into anime, upscale, change lighting...",
176
- )
177
-
178
- run_button = gr.Button("Edit Image", variant="primary")
179
-
180
- with gr.Column():
181
- output_image = gr.Image(label="Output Image", interactive=False, format="png", height=395)
182
-
183
- with gr.Accordion("Advanced Settings", open=False, visible=False):
184
- seed = gr.Slider(label="Seed", minimum=0, maximum=MAX_SEED, step=1, value=0)
185
- randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
186
- guidance_scale = gr.Slider(label="Guidance Scale", minimum=1.0, maximum=10.0, step=0.1, value=1.0)
187
- steps = gr.Slider(label="Inference Steps", minimum=1, maximum=50, step=1, value=4)
188
-
189
- gr.Examples(
190
- examples=[
191
- [["examples/1.jpg"], "cinematic polaroid with soft grain subtle vignette gentle lighting white frame handwritten photographed 'Fire-Edit' preserving realistic texture and details."],
192
- [["examples/2.jpg"], "Transform the image into a dotted cartoon style."],
193
- [["examples/3.jpeg"], "Convert it to black and white."],
194
- [["examples/4.jpg", "examples/5.jpg"], "Replace her glasses with the new glasses from image 1."],
195
- [["examples/8.jpg", "examples/9.png"], "Replace the current clothing with the clothing from the reference image 2. Keep the person’s face, hairstyle, body pose, background, lighting, and camera angle unchanged. Ensure the new outfit fits naturally with realistic fabric texture, proper shadows, folds, and accurate proportions. Match the lighting, color tone, and overall style for a seamless and high-quality result."],
196
- [["examples/10.jpg", "examples/11.png"], "Replace the current clothing with the clothing from the reference image 2. Keep the person’s face, hairstyle, body pose, background, lighting, and camera angle unchanged. Ensure the new outfit fits naturally with realistic fabric texture, proper shadows, folds, and accurate proportions. Match the lighting, color tone, and overall style for a seamless and high-quality result."],
197
- ],
198
- inputs=[images, prompt],
199
- outputs=[output_image, seed],
200
- fn=infer_example,
201
- cache_examples=False,
202
- label="Examples"
203
- )
204
-
205
- gr.Markdown("[*](https://huggingface.co/FireRedTeam/FireRed-Image-Edit-1.0)This is still an experimental Space for FireRed-Image-Edit-1.0.")
206
-
207
- run_button.click(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
  fn=infer,
209
- inputs=[images, prompt, seed, randomize_seed, guidance_scale, steps],
210
- outputs=[output_image, seed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
211
  )
212
 
213
  if __name__ == "__main__":
214
- demo.queue(max_size=50).launch(css=css, theme=gr.themes.Origin(), mcp_server=True, ssr_mode=False, show_error=True)
 
 
 
 
 
 
 
5
  import spaces
6
  import torch
7
  import random
8
+ import base64
9
+ import json
10
+ import html as html_lib
11
+ from io import BytesIO
12
  from PIL import Image
13
 
14
+ MAX_SEED = np.iinfo(np.int32).max
15
+ LANCZOS = getattr(Image, "Resampling", Image).LANCZOS
16
+
17
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
18
 
19
  print("CUDA_VISIBLE_DEVICES=", os.environ.get("CUDA_VISIBLE_DEVICES"))
20
  print("torch.__version__ =", torch.__version__)
21
+ print("torch.version.cuda =", torch.version.cuda)
22
+ print("cuda available:", torch.cuda.is_available())
23
+ print("cuda device count:", torch.cuda.device_count())
24
+ if torch.cuda.is_available():
25
+ print("current device:", torch.cuda.current_device())
26
+ print("device name:", torch.cuda.get_device_name(torch.cuda.current_device()))
27
+
28
  print("Using device:", device)
29
 
30
  from diffusers import FlowMatchEulerDiscreteScheduler
 
39
  transformer=QwenImageTransformer2DModel.from_pretrained(
40
  "prithivMLmods/Qwen-Image-Edit-Rapid-AIO-V19",
41
  torch_dtype=dtype,
42
+ device_map="cuda",
43
  ),
44
+ torch_dtype=dtype,
45
  ).to(device)
46
 
47
  try:
 
50
  except Exception as e:
51
  print(f"Warning: Could not set FA3 processor: {e}")
52
 
53
+ EXAMPLES_CONFIG = [
54
+ {
55
+ "images": ["examples/1.jpg"],
56
+ "prompt": "cinematic polaroid with soft grain subtle vignette gentle lighting white frame handwritten photographed 'Fire-Edit' preserving realistic texture and details.",
57
+ },
58
+ {
59
+ "images": ["examples/2.jpg"],
60
+ "prompt": "Transform the image into a dotted cartoon style.",
61
+ },
62
+ {
63
+ "images": ["examples/3.jpeg"],
64
+ "prompt": "Convert it to black and white.",
65
+ },
66
+ {
67
+ "images": ["examples/4.jpg", "examples/5.jpg"],
68
+ "prompt": "Replace her glasses with the new glasses from image 1.",
69
+ },
70
+ {
71
+ "images": ["examples/8.jpg", "examples/9.png"],
72
+ "prompt": "Replace the current clothing with the clothing from the reference image 2. Keep the person's face, hairstyle, body pose, background, lighting, and camera angle unchanged. Ensure the new outfit fits naturally with realistic fabric texture, proper shadows, folds, and accurate proportions. Match the lighting, color tone, and overall style for a seamless and high-quality result.",
73
+ },
74
+ {
75
+ "images": ["examples/10.jpg", "examples/11.png"],
76
+ "prompt": "Replace the current clothing with the clothing from the reference image 2. Keep the person's face, hairstyle, body pose, background, lighting, and camera angle unchanged. Ensure the new outfit fits naturally with realistic fabric texture, proper shadows, folds, and accurate proportions. Match the lighting, color tone, and overall style for a seamless and high-quality result.",
77
+ },
78
+ ]
79
+
80
+
81
+ def make_thumb_b64(path, max_dim=220):
82
+ if not os.path.exists(path):
83
+ return ""
84
+ try:
85
+ img = Image.open(path).convert("RGB")
86
+ img.thumbnail((max_dim, max_dim), LANCZOS)
87
+ buf = BytesIO()
88
+ img.save(buf, format="JPEG", quality=65)
89
+ return f"data:image/jpeg;base64,{base64.b64encode(buf.getvalue()).decode()}"
90
+ except Exception as e:
91
+ print(f"Thumbnail error for {path}: {e}")
92
+ return ""
93
+
94
+
95
+ def encode_full_image(path):
96
+ if not os.path.exists(path):
97
+ return ""
98
+ try:
99
+ with open(path, "rb") as f:
100
+ data = f.read()
101
+ ext = path.rsplit(".", 1)[-1].lower()
102
+ mime = {"jpg": "image/jpeg", "jpeg": "image/jpeg", "png": "image/png", "webp": "image/webp"}.get(ext, "image/jpeg")
103
+ return f"data:{mime};base64,{base64.b64encode(data).decode()}"
104
+ except Exception as e:
105
+ print(f"Encode error for {path}: {e}")
106
+ return ""
107
+
108
+
109
+ def build_example_cards_html():
110
+ cards = ""
111
+ for i, ex in enumerate(EXAMPLES_CONFIG):
112
+ thumbs_html = ""
113
+ for path in ex["images"]:
114
+ thumb = make_thumb_b64(path)
115
+ if thumb:
116
+ thumbs_html += f'<img src="{thumb}" alt="">'
117
+ else:
118
+ thumbs_html += '<div class="example-thumb-placeholder">Preview</div>'
119
+ n = len(ex["images"])
120
+ badge = f'{n} image{"s" if n > 1 else ""}'
121
+ prompt_short = html_lib.escape(ex["prompt"][:90])
122
+ if len(ex["prompt"]) > 90:
123
+ prompt_short += "..."
124
+ cards += f'''<div class="example-card" data-idx="{i}">
125
+ <div class="example-thumbs">{thumbs_html}</div>
126
+ <div class="example-meta"><span class="example-badge">{badge}</span></div>
127
+ <div class="example-prompt-text">{prompt_short}</div>
128
+ </div>'''
129
+ return cards
130
+
131
+
132
+ def load_example_data(idx_str):
133
+ try:
134
+ idx = int(float(idx_str)) if idx_str and idx_str.strip() else -1
135
+ except (ValueError, TypeError):
136
+ idx = -1
137
+ if idx < 0 or idx >= len(EXAMPLES_CONFIG):
138
+ return json.dumps({"images": [], "prompt": "", "names": [], "status": "error"})
139
+ ex = EXAMPLES_CONFIG[idx]
140
+ b64_list, names = [], []
141
+ for path in ex["images"]:
142
+ b64 = encode_full_image(path)
143
+ if b64:
144
+ b64_list.append(b64)
145
+ names.append(os.path.basename(path))
146
+ return json.dumps({"images": b64_list, "prompt": ex["prompt"], "names": names, "status": "ok"})
147
+
148
+
149
+ print("Building example thumbnails...")
150
+ EXAMPLE_CARDS_HTML = build_example_cards_html()
151
+ print(f"Built {len(EXAMPLES_CONFIG)} example cards.")
152
+
153
+
154
+ def b64_to_pil_list(b64_json_str):
155
+ if not b64_json_str or b64_json_str.strip() in ("", "[]"):
156
+ return []
157
+ try:
158
+ b64_list = json.loads(b64_json_str)
159
+ except Exception:
160
+ return []
161
+ pil_images = []
162
+ for b64_str in b64_list:
163
+ if not b64_str or not isinstance(b64_str, str):
164
+ continue
165
+ try:
166
+ if b64_str.startswith("data:image"):
167
+ _, data = b64_str.split(",", 1)
168
+ else:
169
+ data = b64_str
170
+ image_data = base64.b64decode(data)
171
+ pil_images.append(Image.open(BytesIO(image_data)).convert("RGB"))
172
+ except Exception as e:
173
+ print(f"Error decoding image: {e}")
174
+ return pil_images
175
+
176
 
177
  def update_dimensions_on_upload(image):
178
  if image is None:
179
  return 1024, 1024
180
+ w, h = image.size
181
+ if w > h:
182
+ nw = 1024
183
+ nh = int(nw * h / w)
184
+ else:
185
+ nh = 1024
186
+ nw = int(nh * w / h)
187
+ return (nw // 8) * 8, (nh // 8) * 8
188
 
 
189
 
190
+ @spaces.GPU
191
+ def infer(images_b64_json, prompt, seed, randomize_seed, guidance_scale, steps, progress=gr.Progress(track_tqdm=True)):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  gc.collect()
193
  torch.cuda.empty_cache()
194
+ pil_images = b64_to_pil_list(images_b64_json)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  if not pil_images:
196
+ raise gr.Error("Please upload at least one image to edit.")
197
+ if not prompt or prompt.strip() == "":
198
+ raise gr.Error("Please enter an edit prompt.")
199
  if randomize_seed:
200
  seed = random.randint(0, MAX_SEED)
 
201
  generator = torch.Generator(device=device).manual_seed(seed)
202
  negative_prompt = "worst quality, low quality, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, jpeg artifacts, signature, watermark, username, blurry"
 
203
  width, height = update_dimensions_on_upload(pil_images[0])
 
204
  try:
205
  result_image = pipe(
206
+ image=pil_images, prompt=prompt, negative_prompt=negative_prompt,
207
+ height=height, width=width, num_inference_steps=steps,
208
+ generator=generator, true_cfg_scale=guidance_scale,
 
 
 
 
 
209
  ).images[0]
 
210
  return result_image, seed
 
211
  except Exception as e:
212
  raise e
213
  finally:
214
  gc.collect()
215
  torch.cuda.empty_cache()
216
 
 
 
 
 
217
 
218
+ css = r"""
219
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');
220
+ *{box-sizing:border-box;margin:0;padding:0}
221
+ body,.gradio-container{
222
+ background:#0f0f13!important;font-family:'Inter',system-ui,-apple-system,sans-serif!important;
223
+ font-size:14px!important;color:#e4e4e7!important;min-height:100vh;
224
+ }
225
+ .dark body,.dark .gradio-container{background:#0f0f13!important;color:#e4e4e7!important}
226
+ footer{display:none!important}
227
+ .hidden-input{display:none!important;height:0!important;overflow:hidden!important;margin:0!important;padding:0!important}
228
+
229
+ #example-load-btn{
230
+ position:absolute!important;left:-9999px!important;top:-9999px!important;
231
+ width:1px!important;height:1px!important;opacity:0.01!important;
232
+ pointer-events:none!important;overflow:hidden!important;
233
+ }
234
+ #gradio-run-btn{
235
+ position:absolute;left:-9999px;top:-9999px;width:1px;height:1px;
236
+ opacity:0.01;pointer-events:none;overflow:hidden;
237
+ }
238
+
239
+ /* ── App shell ── */
240
+ .app-shell{
241
+ background:#18181b;border:1px solid #27272a;border-radius:16px;
242
+ margin:12px auto;max-width:1400px;overflow:hidden;
243
+ box-shadow:0 25px 50px -12px rgba(0,0,0,.6),0 0 0 1px rgba(255,255,255,.03);
244
+ }
245
+
246
+ /* ── Header ── */
247
+ .app-header{
248
+ background:linear-gradient(135deg,#18181b,#1e1e24);border-bottom:1px solid #27272a;
249
+ padding:14px 24px;display:flex;align-items:center;justify-content:space-between;
250
+ flex-wrap:wrap;gap:12px;
251
+ }
252
+ .app-header-left{display:flex;align-items:center;gap:12px}
253
+ .app-logo{
254
+ width:36px;height:36px;background:linear-gradient(135deg,#1E90FF,#47A3FF,#7CB8FF);
255
+ border-radius:10px;display:flex;align-items:center;justify-content:center;
256
+ box-shadow:0 4px 12px rgba(30,144,255,.35);flex-shrink:0;
257
+ }
258
+ .app-logo svg{width:20px;height:20px;fill:#fff;flex-shrink:0}
259
+ .app-title{
260
+ font-size:18px;font-weight:700;background:linear-gradient(135deg,#e4e4e7,#a1a1aa);
261
+ -webkit-background-clip:text;-webkit-text-fill-color:transparent;letter-spacing:-.3px;
262
+ }
263
+ .app-badge{
264
+ font-size:11px;font-weight:600;padding:3px 10px;border-radius:20px;
265
+ background:rgba(30,144,255,.15);color:#47A3FF;border:1px solid rgba(30,144,255,.25);letter-spacing:.3px;
266
+ }
267
+ .app-badge.fast{background:rgba(34,197,94,.12);color:#4ade80;border:1px solid rgba(34,197,94,.25)}
268
+
269
+ /* ── GitHub button ── */
270
+ .gh-btn{
271
+ display:inline-flex!important;align-items:center!important;gap:7px!important;
272
+ padding:7px 16px!important;border-radius:8px!important;text-decoration:none!important;
273
+ font-family:'Inter',sans-serif!important;font-size:13px!important;font-weight:700!important;
274
+ letter-spacing:.1px!important;background:#1E90FF!important;
275
+ color:#ffffff!important;-webkit-text-fill-color:#ffffff!important;
276
+ border:1px solid rgba(255,255,255,.18)!important;
277
+ box-shadow:0 2px 10px rgba(30,144,255,.45),0 1px 0 rgba(255,255,255,.1) inset!important;
278
+ transition:transform .15s ease,box-shadow .15s ease,background .15s ease!important;
279
+ cursor:pointer!important;flex-shrink:0!important;
280
+ }
281
+ .gh-btn:hover{
282
+ background:#47A3FF!important;color:#ffffff!important;-webkit-text-fill-color:#ffffff!important;
283
+ transform:translateY(-1px)!important;
284
+ box-shadow:0 5px 18px rgba(30,144,255,.6),0 1px 0 rgba(255,255,255,.12) inset!important;
285
+ }
286
+ .gh-btn:active{
287
+ background:#1873CC!important;transform:translateY(0)!important;
288
+ box-shadow:0 1px 5px rgba(30,144,255,.35)!important;
289
+ }
290
+ .gh-btn svg{fill:#ffffff!important;flex-shrink:0;width:15px!important;height:15px!important}
291
+ .gh-btn span{color:#ffffff!important;-webkit-text-fill-color:#ffffff!important}
292
+
293
+ /* ── Toolbar ── */
294
+ .app-toolbar{
295
+ background:#18181b;border-bottom:1px solid #27272a;padding:8px 16px;
296
+ display:flex;gap:4px;align-items:center;flex-wrap:wrap;
297
+ }
298
+ .tb-sep{width:1px;height:28px;background:#27272a;margin:0 8px}
299
+ .modern-tb-btn{
300
+ display:inline-flex;align-items:center;justify-content:center;gap:6px;
301
+ min-width:32px;height:34px;background:transparent;border:1px solid transparent;
302
+ border-radius:8px;cursor:pointer;font-size:13px;font-weight:600;padding:0 12px;
303
+ font-family:'Inter',sans-serif;color:#ffffff!important;-webkit-text-fill-color:#ffffff!important;
304
+ transition:all .15s ease;
305
+ }
306
+ .modern-tb-btn:hover{background:rgba(30,144,255,.15);border-color:rgba(30,144,255,.3)}
307
+ .modern-tb-btn:active,.modern-tb-btn.active{background:rgba(30,144,255,.25);border-color:rgba(30,144,255,.45)}
308
+ .modern-tb-btn .tb-label{font-size:13px;color:#ffffff!important;-webkit-text-fill-color:#ffffff!important;font-weight:600}
309
+ .modern-tb-btn .tb-svg{width:15px;height:15px;flex-shrink:0;color:#ffffff!important}
310
+ .modern-tb-btn .tb-svg,
311
+ .modern-tb-btn .tb-svg *{stroke:#ffffff!important;fill:none!important}
312
+ .tb-info{font-family:'JetBrains Mono',monospace;font-size:12px;color:#71717a;padding:0 8px;display:flex;align-items:center}
313
+
314
+ body:not(.dark) .modern-tb-btn,body:not(.dark) .modern-tb-btn *{color:#ffffff!important;-webkit-text-fill-color:#ffffff!important}
315
+ body:not(.dark) .modern-tb-btn .tb-svg,body:not(.dark) .modern-tb-btn .tb-svg *{stroke:#ffffff!important}
316
+ .dark .modern-tb-btn,.dark .modern-tb-btn *{color:#ffffff!important;-webkit-text-fill-color:#ffffff!important}
317
+ .dark .modern-tb-btn .tb-svg,.dark .modern-tb-btn .tb-svg *{stroke:#ffffff!important}
318
+ .gradio-container .modern-tb-btn,.gradio-container .modern-tb-btn *{color:#ffffff!important;-webkit-text-fill-color:#ffffff!important}
319
+ .gradio-container .modern-tb-btn .tb-svg,.gradio-container .modern-tb-btn .tb-svg *{stroke:#ffffff!important}
320
+
321
+ /* ── Main layout ── */
322
+ .app-main-row{display:flex;gap:0;flex:1;overflow:hidden}
323
+ .app-main-left{flex:1;display:flex;flex-direction:column;min-width:0;border-right:1px solid #27272a}
324
+ .app-main-right{width:420px;display:flex;flex-direction:column;flex-shrink:0;background:#18181b}
325
+
326
+ /* ── Drop zone ── */
327
+ #gallery-drop-zone{position:relative;background:#09090b;min-height:440px;overflow:auto}
328
+ #gallery-drop-zone.drag-over{outline:2px solid #1E90FF;outline-offset:-2px;background:rgba(30,144,255,.04)}
329
+
330
+ .upload-prompt-modern{position:absolute;top:50%;left:50%;transform:translate(-50%,-50%);z-index:20}
331
+ .upload-click-area{
332
+ display:flex;flex-direction:column;align-items:center;justify-content:center;
333
+ cursor:pointer;padding:36px 52px;border:2px dashed #3f3f46;border-radius:16px;
334
+ background:rgba(30,144,255,.03);transition:all .2s ease;gap:8px;
335
+ }
336
+ .upload-click-area:hover{background:rgba(30,144,255,.08);border-color:#1E90FF;transform:scale(1.03)}
337
+ .upload-click-area:active{background:rgba(30,144,255,.12);transform:scale(.98)}
338
+ .upload-click-area svg{width:80px;height:80px}
339
+ .upload-main-text{color:#71717a;font-size:14px;font-weight:500;margin-top:4px}
340
+ .upload-sub-text{color:#52525b;font-size:12px;text-align:center;max-width:280px;line-height:1.5}
341
+
342
+ /* ── Gallery grid ── */
343
+ .image-gallery-grid{
344
+ display:grid;grid-template-columns:repeat(auto-fill,minmax(140px,1fr));
345
+ gap:12px;padding:16px;align-content:start;
346
+ }
347
+ .gallery-thumb{
348
+ position:relative;aspect-ratio:1;border-radius:10px;overflow:hidden;
349
+ cursor:pointer;border:2px solid #27272a;transition:all .2s ease;background:#18181b;
350
+ }
351
+ .gallery-thumb:hover{border-color:#3f3f46;transform:translateY(-2px);box-shadow:0 4px 12px rgba(0,0,0,.4)}
352
+ .gallery-thumb.selected{border-color:#1E90FF!important;box-shadow:0 0 0 3px rgba(30,144,255,.2)}
353
+ .gallery-thumb img{width:100%;height:100%;object-fit:cover}
354
+ .thumb-badge{
355
+ position:absolute;top:6px;left:6px;background:#1E90FF;color:#fff;
356
+ padding:2px 8px;border-radius:4px;font-family:'JetBrains Mono',monospace;font-size:11px;font-weight:600;
357
+ }
358
+ .thumb-remove{
359
+ position:absolute;top:6px;right:6px;width:24px;height:24px;background:rgba(0,0,0,.75);
360
+ color:#fff;border:1px solid rgba(255,255,255,.15);border-radius:50%;cursor:pointer;
361
+ display:none;align-items:center;justify-content:center;font-size:12px;transition:all .15s;line-height:1;
362
+ }
363
+ .gallery-thumb:hover .thumb-remove{display:flex}
364
+ .thumb-remove:hover{background:#1E90FF;border-color:#1E90FF}
365
+ .gallery-add-card{
366
+ aspect-ratio:1;border-radius:10px;border:2px dashed #3f3f46;
367
+ display:flex;flex-direction:column;align-items:center;justify-content:center;
368
+ cursor:pointer;transition:all .2s ease;background:rgba(30,144,255,.03);gap:4px;
369
+ }
370
+ .gallery-add-card:hover{border-color:#1E90FF;background:rgba(30,144,255,.08)}
371
+ .gallery-add-card .add-icon{font-size:28px;color:#71717a;font-weight:300}
372
+ .gallery-add-card .add-text{font-size:12px;color:#71717a;font-weight:500}
373
+
374
+ /* ── Hint bar ── */
375
+ .hint-bar{
376
+ background:rgba(30,144,255,.06);border-top:1px solid #27272a;border-bottom:1px solid #27272a;
377
+ padding:10px 20px;font-size:13px;color:#a1a1aa;line-height:1.7;
378
+ }
379
+ .hint-bar b{color:#7CB8FF;font-weight:600}
380
+ .hint-bar kbd{
381
+ display:inline-block;padding:1px 6px;background:#27272a;border:1px solid #3f3f46;
382
+ border-radius:4px;font-family:'JetBrains Mono',monospace;font-size:11px;color:#a1a1aa;
383
+ }
384
 
385
+ /* ── Suggestions ── */
386
+ .suggestions-section{border-top:1px solid #27272a;padding:12px 16px}
387
+ .suggestions-title,.examples-title{
388
+ font-size:12px;font-weight:600;color:#71717a;text-transform:uppercase;
389
+ letter-spacing:.8px;margin-bottom:10px;
390
+ }
391
+ .suggestions-wrap{display:flex;flex-wrap:wrap;gap:6px}
392
+ .suggestion-chip{
393
+ display:inline-flex;align-items:center;gap:4px;padding:5px 12px;
394
+ background:rgba(30,144,255,.08);border:1px solid rgba(30,144,255,.2);border-radius:20px;
395
+ color:#7CB8FF;font-size:12px;font-weight:500;font-family:'Inter',sans-serif;
396
+ cursor:pointer;transition:all .15s;white-space:nowrap;
397
+ }
398
+ .suggestion-chip:hover{background:rgba(30,144,255,.15);border-color:rgba(30,144,255,.35);color:#47A3FF;transform:translateY(-1px)}
399
+
400
+ /* ── Examples ── */
401
+ .examples-section{border-top:1px solid #27272a;padding:12px 16px}
402
+ .examples-scroll{display:flex;gap:10px;overflow-x:auto;padding-bottom:8px}
403
+ .examples-scroll::-webkit-scrollbar{height:6px}
404
+ .examples-scroll::-webkit-scrollbar-track{background:#09090b;border-radius:3px}
405
+ .examples-scroll::-webkit-scrollbar-thumb{background:#27272a;border-radius:3px}
406
+ .examples-scroll::-webkit-scrollbar-thumb:hover{background:#3f3f46}
407
+ .example-card{
408
+ flex-shrink:0;width:210px;background:#09090b;border:1px solid #27272a;
409
+ border-radius:10px;overflow:hidden;cursor:pointer;transition:all .2s ease;
410
+ }
411
+ .example-card:hover{border-color:#1E90FF;transform:translateY(-2px);box-shadow:0 4px 12px rgba(30,144,255,.15)}
412
+ .example-card.loading{opacity:.5;pointer-events:none}
413
+ .example-thumbs{display:flex;height:110px;overflow:hidden;background:#18181b}
414
+ .example-thumbs img{flex:1;object-fit:cover;min-width:0;border-bottom:1px solid #27272a}
415
+ .example-thumb-placeholder{
416
+ flex:1;display:flex;align-items:center;justify-content:center;
417
+ background:#18181b;color:#3f3f46;font-size:11px;min-width:0;
418
+ }
419
+ .example-meta{padding:6px 10px;display:flex;align-items:center;gap:6px}
420
+ .example-badge{
421
+ display:inline-flex;padding:2px 7px;background:rgba(30,144,255,.1);border-radius:4px;
422
+ font-size:10px;font-weight:600;color:#47A3FF;font-family:'JetBrains Mono',monospace;white-space:nowrap;
423
+ }
424
+ .example-prompt-text{
425
+ padding:0 10px 8px;font-size:11px;color:#a1a1aa;line-height:1.4;
426
+ display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;
427
+ }
428
+
429
+ /* ── Right panel ── */
430
+ .panel-card{border-bottom:1px solid #27272a}
431
+ .panel-card-title{
432
+ padding:12px 20px;font-size:12px;font-weight:600;color:#71717a;
433
+ text-transform:uppercase;letter-spacing:.8px;border-bottom:1px solid rgba(39,39,42,.6);
434
+ }
435
+ .panel-card-body{padding:16px 20px;display:flex;flex-direction:column;gap:8px}
436
+ .modern-label{font-size:13px;font-weight:500;color:#a1a1aa;margin-bottom:4px;display:block}
437
+ .modern-textarea{
438
+ width:100%;background:#09090b;border:1px solid #27272a;border-radius:8px;
439
+ padding:10px 14px;font-family:'Inter',sans-serif;font-size:14px;color:#e4e4e7;
440
+ resize:vertical;outline:none;min-height:42px;transition:border-color .2s;
441
+ }
442
+ .modern-textarea:focus{border-color:#1E90FF;box-shadow:0 0 0 3px rgba(30,144,255,.15)}
443
+ .modern-textarea::placeholder{color:#3f3f46}
444
+ .modern-textarea.error-flash{
445
+ border-color:#ef4444!important;box-shadow:0 0 0 3px rgba(239,68,68,.2)!important;animation:shake .4s ease;
446
+ }
447
+ @keyframes shake{0%,100%{transform:translateX(0)}20%,60%{transform:translateX(-4px)}40%,80%{transform:translateX(4px)}}
448
+
449
+ /* ── Toast ── */
450
+ .toast-notification{
451
+ position:fixed;top:24px;left:50%;transform:translateX(-50%) translateY(-120%);
452
+ z-index:9999;padding:10px 24px;border-radius:10px;font-family:'Inter',sans-serif;
453
+ font-size:14px;font-weight:600;display:flex;align-items:center;gap:8px;
454
+ box-shadow:0 8px 24px rgba(0,0,0,.5);
455
+ transition:transform .35s cubic-bezier(.34,1.56,.64,1),opacity .35s ease;opacity:0;pointer-events:none;
456
+ }
457
+ .toast-notification.visible{transform:translateX(-50%) translateY(0);opacity:1;pointer-events:auto}
458
+ .toast-notification.error{background:linear-gradient(135deg,#dc2626,#b91c1c);color:#fff;border:1px solid rgba(255,255,255,.15)}
459
+ .toast-notification.warning{background:linear-gradient(135deg,#d97706,#b45309);color:#fff;border:1px solid rgba(255,255,255,.15)}
460
+ .toast-notification.info{background:linear-gradient(135deg,#2563eb,#1d4ed8);color:#fff;border:1px solid rgba(255,255,255,.15)}
461
+ .toast-notification .toast-icon{font-size:16px;line-height:1}
462
+ .toast-notification .toast-text{line-height:1.3}
463
+
464
+ /* ── Run button ── */
465
+ .btn-run{
466
+ display:flex;align-items:center;justify-content:center;gap:8px;width:100%;
467
+ background:linear-gradient(135deg,#1E90FF,#1873CC);border:none;border-radius:10px;
468
+ padding:12px 24px;cursor:pointer;font-size:15px;font-weight:600;font-family:'Inter',sans-serif;
469
+ color:#ffffff!important;-webkit-text-fill-color:#ffffff!important;transition:all .2s ease;letter-spacing:-.2px;
470
+ box-shadow:0 4px 16px rgba(30,144,255,.3),inset 0 1px 0 rgba(255,255,255,.1);
471
+ }
472
+ .btn-run:hover{
473
+ background:linear-gradient(135deg,#47A3FF,#1E90FF);transform:translateY(-1px);
474
+ box-shadow:0 6px 24px rgba(30,144,255,.45),inset 0 1px 0 rgba(255,255,255,.15);
475
+ }
476
+ .btn-run:active{transform:translateY(0);box-shadow:0 2px 8px rgba(30,144,255,.3)}
477
+ .btn-run svg{width:18px;height:18px;fill:#ffffff!important}
478
+ .btn-run svg path{fill:#ffffff!important}
479
+ #custom-run-btn,#custom-run-btn *,#custom-run-btn span,#custom-run-btn svg,
480
+ #custom-run-btn svg path,#run-btn-label,.btn-run,.btn-run *{
481
+ color:#ffffff!important;-webkit-text-fill-color:#ffffff!important;fill:#ffffff!important;
482
+ }
483
+ body:not(.dark) .btn-run,body:not(.dark) .btn-run *,body:not(.dark) #custom-run-btn,
484
+ body:not(.dark) #custom-run-btn *{color:#ffffff!important;-webkit-text-fill-color:#ffffff!important;fill:#ffffff!important}
485
+ .dark .btn-run,.dark .btn-run *,.dark #custom-run-btn,.dark #custom-run-btn *{
486
+ color:#ffffff!important;-webkit-text-fill-color:#ffffff!important;fill:#ffffff!important;
487
+ }
488
+ .gradio-container .btn-run,.gradio-container .btn-run *,.gradio-container #custom-run-btn,
489
+ .gradio-container #custom-run-btn *{color:#ffffff!important;-webkit-text-fill-color:#ffffff!important;fill:#ffffff!important}
490
+
491
+ /* ── Output ── */
492
+ .output-frame{border-bottom:1px solid #27272a;display:flex;flex-direction:column;position:relative}
493
+ .output-frame .out-title{
494
+ padding:10px 20px;font-size:13px;font-weight:700;color:#ffffff!important;
495
+ -webkit-text-fill-color:#ffffff!important;text-transform:uppercase;letter-spacing:.8px;
496
+ border-bottom:1px solid rgba(39,39,42,.6);display:flex;align-items:center;justify-content:space-between;
497
+ }
498
+ .output-frame .out-title span{color:#ffffff!important;-webkit-text-fill-color:#ffffff!important}
499
+ .output-frame .out-body{
500
+ flex:1;background:#09090b;display:flex;align-items:center;justify-content:center;
501
+ overflow:hidden;min-height:240px;position:relative;
502
+ }
503
+ .output-frame .out-body img{max-width:100%;max-height:460px;image-rendering:auto}
504
+ .output-frame .out-placeholder{color:#3f3f46;font-size:13px;text-align:center;padding:20px}
505
+ .out-download-btn{
506
+ display:none;align-items:center;justify-content:center;background:rgba(30,144,255,.1);
507
+ border:1px solid rgba(30,144,255,.2);border-radius:6px;cursor:pointer;padding:3px 10px;
508
+ font-size:11px;font-weight:500;color:#7CB8FF!important;gap:4px;height:24px;transition:all .15s;
509
+ }
510
+ .out-download-btn:hover{background:rgba(30,144,255,.2);border-color:rgba(30,144,255,.35);color:#ffffff!important}
511
+ .out-download-btn.visible{display:inline-flex}
512
+ .out-download-btn svg{width:12px;height:12px;fill:#7CB8FF}
513
+
514
+ /* ── Loader ── */
515
+ .modern-loader{
516
+ display:none;position:absolute;top:0;left:0;right:0;bottom:0;background:rgba(9,9,11,.92);
517
+ z-index:15;flex-direction:column;align-items:center;justify-content:center;gap:16px;backdrop-filter:blur(4px);
518
+ }
519
+ .modern-loader.active{display:flex}
520
+ .modern-loader .loader-spinner{
521
+ width:36px;height:36px;border:3px solid #27272a;border-top-color:#1E90FF;
522
+ border-radius:50%;animation:spin .8s linear infinite;
523
+ }
524
+ @keyframes spin{to{transform:rotate(360deg)}}
525
+ .modern-loader .loader-text{font-size:13px;color:#a1a1aa;font-weight:500}
526
+ .loader-bar-track{width:200px;height:4px;background:#27272a;border-radius:2px;overflow:hidden}
527
+ .loader-bar-fill{
528
+ height:100%;background:linear-gradient(90deg,#1E90FF,#47A3FF,#1E90FF);
529
+ background-size:200% 100%;animation:shimmer 1.5s ease-in-out infinite;border-radius:2px;
530
+ }
531
+ @keyframes shimmer{0%{background-position:200% 0}100%{background-position:-200% 0}}
532
+
533
+ /* ── Settings ── */
534
+ .settings-group{border:1px solid #27272a;border-radius:10px;margin:12px 16px;padding:0;overflow:hidden}
535
+ .settings-group-title{
536
+ font-size:12px;font-weight:600;color:#71717a;text-transform:uppercase;letter-spacing:.8px;
537
+ padding:10px 16px;border-bottom:1px solid #27272a;background:rgba(24,24,27,.5);
538
+ }
539
+ .settings-group-body{padding:14px 16px;display:flex;flex-direction:column;gap:12px}
540
+ .slider-row{display:flex;align-items:center;gap:10px;min-height:28px}
541
+ .slider-row label{font-size:13px;font-weight:500;color:#a1a1aa;min-width:72px;flex-shrink:0}
542
+ .slider-row input[type="range"]{
543
+ flex:1;-webkit-appearance:none;appearance:none;height:6px;background:#27272a;
544
+ border-radius:3px;outline:none;min-width:0;
545
+ }
546
+ .slider-row input[type="range"]::-webkit-slider-thumb{
547
+ -webkit-appearance:none;width:16px;height:16px;background:linear-gradient(135deg,#1E90FF,#1873CC);
548
+ border-radius:50%;cursor:pointer;box-shadow:0 2px 6px rgba(30,144,255,.4);transition:transform .15s;
549
+ }
550
+ .slider-row input[type="range"]::-webkit-slider-thumb:hover{transform:scale(1.2)}
551
+ .slider-row input[type="range"]::-moz-range-thumb{
552
+ width:16px;height:16px;background:linear-gradient(135deg,#1E90FF,#1873CC);
553
+ border-radius:50%;cursor:pointer;border:none;box-shadow:0 2px 6px rgba(30,144,255,.4);
554
+ }
555
+ .slider-row .slider-val{
556
+ min-width:52px;text-align:right;font-family:'JetBrains Mono',monospace;font-size:12px;
557
+ font-weight:500;padding:3px 8px;background:#09090b;border:1px solid #27272a;
558
+ border-radius:6px;color:#a1a1aa;flex-shrink:0;
559
+ }
560
+ .checkbox-row{display:flex;align-items:center;gap:8px;font-size:13px;color:#a1a1aa}
561
+ .checkbox-row input[type="checkbox"]{accent-color:#1E90FF;width:16px;height:16px;cursor:pointer}
562
+ .checkbox-row label{color:#a1a1aa;font-size:13px;cursor:pointer}
563
+
564
+ /* ── Status bar ── */
565
+ .app-statusbar{
566
+ background:#18181b;border-top:1px solid #27272a;padding:6px 20px;
567
+ display:flex;gap:12px;height:34px;align-items:center;font-size:12px;
568
+ }
569
+ .app-statusbar .sb-section{
570
+ padding:0 12px;flex:1;display:flex;align-items:center;font-family:'JetBrains Mono',monospace;
571
+ font-size:12px;color:#52525b;overflow:hidden;white-space:nowrap;
572
+ }
573
+ .app-statusbar .sb-section.sb-fixed{
574
+ flex:0 0 auto;min-width:90px;text-align:center;justify-content:center;
575
+ padding:3px 12px;background:rgba(30,144,255,.08);border-radius:6px;color:#47A3FF;font-weight:500;
576
+ }
577
+
578
+ /* ── Footer note ── */
579
+ .exp-note{
580
+ padding:10px 20px;font-size:12px;color:#52525b;
581
+ border-top:1px solid #27272a;text-align:center;font-weight:500;
582
+ background:#18181b;font-family:'Inter',sans-serif;
583
+ }
584
+ .exp-note a{color:#47A3FF;text-decoration:none}
585
+ .exp-note a:hover{text-decoration:underline}
586
+
587
+ /* ── Dark overrides ── */
588
+ .dark .app-shell{background:#18181b}
589
+ .dark .upload-prompt-modern{background:transparent}
590
+ .dark .panel-card{background:#18181b}
591
+ .dark .settings-group{background:#18181b}
592
+ .dark .output-frame .out-title{color:#ffffff!important}
593
+ .dark .output-frame .out-title span{color:#ffffff!important}
594
+ .dark .out-download-btn{color:#7CB8FF!important}
595
+ .dark .out-download-btn:hover{color:#ffffff!important}
596
+
597
+ /* ── Scrollbars ── */
598
+ ::-webkit-scrollbar{width:8px;height:8px}
599
+ ::-webkit-scrollbar-track{background:#09090b}
600
+ ::-webkit-scrollbar-thumb{background:#27272a;border-radius:4px}
601
+ ::-webkit-scrollbar-thumb:hover{background:#3f3f46}
602
+
603
+ /* ── Responsive ── */
604
+ @media(max-width:840px){
605
+ .app-main-row{flex-direction:column}
606
+ .app-main-right{width:100%}
607
+ .app-main-left{border-right:none;border-bottom:1px solid #27272a}
608
  }
 
609
  """
610
 
611
+ gallery_js = r"""
612
+ () => {
613
+ function init() {
614
+ if (window.__fireRedInitDone) return;
615
+
616
+ const galleryGrid = document.getElementById('image-gallery-grid');
617
+ const dropZone = document.getElementById('gallery-drop-zone');
618
+ const uploadPrompt = document.getElementById('upload-prompt');
619
+ const uploadClick = document.getElementById('upload-click-area');
620
+ const fileInput = document.getElementById('custom-file-input');
621
+ const btnUpload = document.getElementById('tb-upload');
622
+ const btnRemove = document.getElementById('tb-remove');
623
+ const btnClear = document.getElementById('tb-clear');
624
+ const promptInput = document.getElementById('custom-prompt-input');
625
+ const runBtnEl = document.getElementById('custom-run-btn');
626
+ const imgCountTb = document.getElementById('tb-image-count');
627
+ const imgCountSb = document.getElementById('sb-image-count');
628
+
629
+ if (!galleryGrid || !fileInput || !dropZone) {
630
+ setTimeout(init, 250);
631
+ return;
632
+ }
633
+
634
+ window.__fireRedInitDone = true;
635
+
636
+ let images = [];
637
+ window.__uploadedImages = images;
638
+ let selectedIdx = -1;
639
+ let toastTimer = null;
640
+
641
+ /* ── GitHub button hover ── */
642
+ function enforceGhBtn() {
643
+ const ghBtn = document.querySelector('.gh-btn');
644
+ if (ghBtn && !ghBtn.__hoverBound) {
645
+ ghBtn.__hoverBound = true;
646
+ ghBtn.addEventListener('mouseenter', () => {
647
+ ghBtn.style.setProperty('background','#47A3FF','important');
648
+ ghBtn.style.setProperty('transform','translateY(-1px)','important');
649
+ ghBtn.style.setProperty('box-shadow','0 5px 18px rgba(30,144,255,.6)','important');
650
+ });
651
+ ghBtn.addEventListener('mouseleave', () => {
652
+ ghBtn.style.setProperty('background','#1E90FF','important');
653
+ ghBtn.style.setProperty('transform','translateY(0)','important');
654
+ ghBtn.style.setProperty('box-shadow','0 2px 10px rgba(30,144,255,.45)','important');
655
+ });
656
+ ghBtn.addEventListener('mousedown', () => ghBtn.style.setProperty('background','#1873CC','important'));
657
+ ghBtn.addEventListener('mouseup', () => ghBtn.style.setProperty('background','#47A3FF','important'));
658
+ }
659
+ }
660
+ enforceGhBtn();
661
+ setInterval(enforceGhBtn, 1000);
662
+
663
+ function showToast(message, type) {
664
+ let toast = document.getElementById('app-toast');
665
+ if (!toast) {
666
+ toast = document.createElement('div');
667
+ toast.id = 'app-toast';
668
+ toast.className = 'toast-notification';
669
+ toast.innerHTML = '<span class="toast-icon"></span><span class="toast-text"></span>';
670
+ document.body.appendChild(toast);
671
+ }
672
+ const icon = toast.querySelector('.toast-icon');
673
+ const text = toast.querySelector('.toast-text');
674
+ toast.className = 'toast-notification ' + (type || 'error');
675
+ if (type === 'warning') icon.textContent = '\u26A0';
676
+ else if (type === 'info') icon.textContent = '\u2139';
677
+ else icon.textContent = '\u2717';
678
+ text.textContent = message;
679
+ if (toastTimer) clearTimeout(toastTimer);
680
+ void toast.offsetWidth;
681
+ toast.classList.add('visible');
682
+ toastTimer = setTimeout(() => toast.classList.remove('visible'), 3500);
683
+ }
684
+ window.__showToast = showToast;
685
+
686
+ function flashPromptError() {
687
+ if (!promptInput) return;
688
+ promptInput.classList.add('error-flash');
689
+ promptInput.focus();
690
+ setTimeout(() => promptInput.classList.remove('error-flash'), 800);
691
+ }
692
+
693
+ function setGradioValue(containerId, value) {
694
+ const container = document.getElementById(containerId);
695
+ if (!container) return;
696
+ container.querySelectorAll('input, textarea').forEach(el => {
697
+ if (el.type === 'file' || el.type === 'range' || el.type === 'checkbox') return;
698
+ const proto = el.tagName === 'TEXTAREA' ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
699
+ const ns = Object.getOwnPropertyDescriptor(proto, 'value');
700
+ if (ns && ns.set) {
701
+ ns.set.call(el, value);
702
+ el.dispatchEvent(new Event('input', {bubbles:true, composed:true}));
703
+ el.dispatchEvent(new Event('change', {bubbles:true, composed:true}));
704
+ }
705
+ });
706
+ }
707
+ window.__setGradioValue = setGradioValue;
708
+
709
+ function syncImagesToGradio() {
710
+ window.__uploadedImages = images;
711
+ const b64Array = images.map(img => img.b64);
712
+ setGradioValue('hidden-images-b64', JSON.stringify(b64Array));
713
+ updateCounts();
714
+ }
715
+
716
+ function syncPromptToGradio() {
717
+ if (promptInput) setGradioValue('prompt-gradio-input', promptInput.value);
718
+ }
719
+
720
+ function updateCounts() {
721
+ const n = images.length;
722
+ const txt = n > 0 ? n + ' image' + (n > 1 ? 's' : '') : 'No images';
723
+ if (imgCountTb) imgCountTb.textContent = txt;
724
+ if (imgCountSb) imgCountSb.textContent = n > 0 ? txt + ' uploaded' : 'No images uploaded';
725
+ }
726
+
727
+ function addImage(b64, name) {
728
+ images.push({id: Date.now() + Math.random(), b64: b64, name: name});
729
+ renderGallery();
730
+ syncImagesToGradio();
731
+ }
732
+ window.__addImage = addImage;
733
+
734
+ function removeImage(idx) {
735
+ images.splice(idx, 1);
736
+ if (selectedIdx === idx) selectedIdx = -1;
737
+ else if (selectedIdx > idx) selectedIdx--;
738
+ renderGallery();
739
+ syncImagesToGradio();
740
+ }
741
+
742
+ function clearAll() {
743
+ images = [];
744
+ window.__uploadedImages = images;
745
+ selectedIdx = -1;
746
+ renderGallery();
747
+ syncImagesToGradio();
748
+ }
749
+ window.__clearAll = clearAll;
750
+
751
+ function selectImage(idx) {
752
+ selectedIdx = (selectedIdx === idx) ? -1 : idx;
753
+ renderGallery();
754
+ }
755
+
756
+ function renderGallery() {
757
+ if (images.length === 0) {
758
+ galleryGrid.innerHTML = '';
759
+ galleryGrid.style.display = 'none';
760
+ if (uploadPrompt) uploadPrompt.style.display = '';
761
+ return;
762
+ }
763
+ if (uploadPrompt) uploadPrompt.style.display = 'none';
764
+ galleryGrid.style.display = 'grid';
765
+
766
+ let html = '';
767
+ images.forEach((img, i) => {
768
+ const sel = i === selectedIdx ? ' selected' : '';
769
+ html += '<div class="gallery-thumb' + sel + '" data-idx="' + i + '">'
770
+ + '<img src="' + img.b64 + '" alt="' + (img.name||'image') + '">'
771
+ + '<span class="thumb-badge">#' + (i+1) + '</span>'
772
+ + '<button class="thumb-remove" data-remove="' + i + '">\u2715</button>'
773
+ + '</div>';
774
+ });
775
+ html += '<div class="gallery-add-card" id="gallery-add-card">'
776
+ + '<span class="add-icon">+</span>'
777
+ + '<span class="add-text">Add</span>'
778
+ + '</div>';
779
+ galleryGrid.innerHTML = html;
780
+
781
+ galleryGrid.querySelectorAll('.gallery-thumb').forEach(thumb => {
782
+ thumb.addEventListener('click', (e) => {
783
+ if (e.target.closest('.thumb-remove')) return;
784
+ selectImage(parseInt(thumb.dataset.idx));
785
+ });
786
+ });
787
+ galleryGrid.querySelectorAll('.thumb-remove').forEach(btn => {
788
+ btn.addEventListener('click', (e) => {
789
+ e.stopPropagation();
790
+ removeImage(parseInt(btn.dataset.remove));
791
+ });
792
+ });
793
+ const addCard = document.getElementById('gallery-add-card');
794
+ if (addCard) addCard.addEventListener('click', () => fileInput.click());
795
+ }
796
+
797
+ function processFiles(files) {
798
+ Array.from(files).forEach(file => {
799
+ if (!file.type.startsWith('image/')) return;
800
+ const reader = new FileReader();
801
+ reader.onload = (e) => addImage(e.target.result, file.name);
802
+ reader.readAsDataURL(file);
803
+ });
804
+ }
805
+
806
+ fileInput.addEventListener('change', (e) => { processFiles(e.target.files); e.target.value = ''; });
807
+ if (uploadClick) uploadClick.addEventListener('click', () => fileInput.click());
808
+ if (btnUpload) btnUpload.addEventListener('click', () => fileInput.click());
809
+ if (btnRemove) btnRemove.addEventListener('click', () => {
810
+ if (selectedIdx >= 0 && selectedIdx < images.length) removeImage(selectedIdx);
811
+ });
812
+ if (btnClear) btnClear.addEventListener('click', clearAll);
813
+
814
+ dropZone.addEventListener('dragover', (e) => { e.preventDefault(); dropZone.classList.add('drag-over'); });
815
+ dropZone.addEventListener('dragleave', (e) => { e.preventDefault(); dropZone.classList.remove('drag-over'); });
816
+ dropZone.addEventListener('drop', (e) => {
817
+ e.preventDefault(); dropZone.classList.remove('drag-over');
818
+ if (e.dataTransfer.files.length) processFiles(e.dataTransfer.files);
819
+ });
820
+
821
+ if (promptInput) promptInput.addEventListener('input', syncPromptToGradio);
822
+
823
+ window.__setPrompt = function(text) {
824
+ if (promptInput) { promptInput.value = text; syncPromptToGradio(); }
825
+ };
826
+
827
+ document.querySelectorAll('.example-card[data-idx]').forEach(card => {
828
+ card.addEventListener('click', () => {
829
+ const idx = card.getAttribute('data-idx');
830
+ document.querySelectorAll('.example-card.loading').forEach(c => c.classList.remove('loading'));
831
+ card.classList.add('loading');
832
+ showToast('Loading example...', 'info');
833
+ setGradioValue('example-result-data', '');
834
+ setGradioValue('example-idx-input', idx);
835
+ setTimeout(() => {
836
+ const btn = document.getElementById('example-load-btn');
837
+ if (btn) {
838
+ const b = btn.querySelector('button');
839
+ if (b) b.click(); else btn.click();
840
+ }
841
+ }, 150);
842
+ setTimeout(() => card.classList.remove('loading'), 12000);
843
+ });
844
+ });
845
+
846
+ function syncSlider(customId, gradioId) {
847
+ const slider = document.getElementById(customId);
848
+ const valSpan = document.getElementById(customId + '-val');
849
+ if (!slider) return;
850
+ slider.addEventListener('input', () => {
851
+ if (valSpan) valSpan.textContent = slider.value;
852
+ const container = document.getElementById(gradioId);
853
+ if (!container) return;
854
+ container.querySelectorAll('input[type="range"],input[type="number"]').forEach(el => {
855
+ const ns = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value');
856
+ if (ns && ns.set) {
857
+ ns.set.call(el, slider.value);
858
+ el.dispatchEvent(new Event('input', {bubbles:true, composed:true}));
859
+ el.dispatchEvent(new Event('change', {bubbles:true, composed:true}));
860
+ }
861
+ });
862
+ });
863
+ }
864
+ syncSlider('custom-seed', 'gradio-seed');
865
+ syncSlider('custom-guidance', 'gradio-guidance');
866
+ syncSlider('custom-steps', 'gradio-steps');
867
+
868
+ const randCheck = document.getElementById('custom-randomize');
869
+ if (randCheck) {
870
+ randCheck.addEventListener('change', () => {
871
+ const container = document.getElementById('gradio-randomize');
872
+ if (!container) return;
873
+ const cb = container.querySelector('input[type="checkbox"]');
874
+ if (cb && cb.checked !== randCheck.checked) cb.click();
875
+ });
876
+ }
877
+
878
+ function showLoader() {
879
+ const l = document.getElementById('output-loader');
880
+ if (l) l.classList.add('active');
881
+ const sb = document.querySelector('.sb-fixed');
882
+ if (sb) sb.textContent = 'Processing...';
883
+ }
884
+ function hideLoader() {
885
+ const l = document.getElementById('output-loader');
886
+ if (l) l.classList.remove('active');
887
+ const sb = document.querySelector('.sb-fixed');
888
+ if (sb) sb.textContent = 'Done';
889
+ }
890
+ window.__showLoader = showLoader;
891
+ window.__hideLoader = hideLoader;
892
+
893
+ function validateBeforeRun() {
894
+ const promptVal = promptInput ? promptInput.value.trim() : '';
895
+ const hasImages = images.length > 0;
896
+ if (!hasImages && !promptVal) { showToast('Please upload an image and enter a prompt', 'error'); flashPromptError(); return false; }
897
+ if (!hasImages) { showToast('Please upload at least one image', 'error'); return false; }
898
+ if (!promptVal) { showToast('Please enter an edit prompt', 'warning'); flashPromptError(); return false; }
899
+ return true;
900
+ }
901
+
902
+ window.__clickGradioRunBtn = function() {
903
+ if (!validateBeforeRun()) return;
904
+ syncPromptToGradio(); syncImagesToGradio(); showLoader();
905
+ setTimeout(() => {
906
+ const gradioBtn = document.getElementById('gradio-run-btn');
907
+ if (!gradioBtn) return;
908
+ const btn = gradioBtn.querySelector('button');
909
+ if (btn) btn.click(); else gradioBtn.click();
910
+ }, 200);
911
+ };
912
+
913
+ if (runBtnEl) runBtnEl.addEventListener('click', () => window.__clickGradioRunBtn());
914
+
915
+ renderGallery();
916
+ updateCounts();
917
+ }
918
+ init();
919
+ }
920
+ """
921
+
922
+ wire_outputs_js = r"""
923
+ () => {
924
+ function watchOutputs() {
925
+ const resultContainer = document.getElementById('gradio-result');
926
+ const outBody = document.getElementById('output-image-container');
927
+ const outPh = document.getElementById('output-placeholder');
928
+ const dlBtn = document.getElementById('dl-btn-output');
929
+
930
+ if (!resultContainer || !outBody) { setTimeout(watchOutputs, 500); return; }
931
+
932
+ if (dlBtn) {
933
+ dlBtn.addEventListener('click', (e) => {
934
+ e.stopPropagation();
935
+ const img = outBody.querySelector('img.modern-out-img');
936
+ if (img && img.src) {
937
+ const a = document.createElement('a');
938
+ a.href = img.src; a.download = 'firered_output.png';
939
+ document.body.appendChild(a); a.click(); document.body.removeChild(a);
940
+ }
941
+ });
942
+ }
943
+
944
+ function syncImage() {
945
+ const resultImg = resultContainer.querySelector('img');
946
+ if (resultImg && resultImg.src) {
947
+ if (outPh) outPh.style.display = 'none';
948
+ let existing = outBody.querySelector('img.modern-out-img');
949
+ if (!existing) {
950
+ existing = document.createElement('img');
951
+ existing.className = 'modern-out-img';
952
+ outBody.appendChild(existing);
953
+ }
954
+ if (existing.src !== resultImg.src) {
955
+ existing.src = resultImg.src;
956
+ if (dlBtn) dlBtn.classList.add('visible');
957
+ if (window.__hideLoader) window.__hideLoader();
958
+ }
959
+ }
960
+ }
961
+ const observer = new MutationObserver(syncImage);
962
+ observer.observe(resultContainer, {childList:true, subtree:true, attributes:true, attributeFilter:['src']});
963
+ setInterval(syncImage, 800);
964
+ }
965
+ watchOutputs();
966
+
967
+ function watchSeed() {
968
+ const seedContainer = document.getElementById('gradio-seed');
969
+ const seedSlider = document.getElementById('custom-seed');
970
+ const seedVal = document.getElementById('custom-seed-val');
971
+ if (!seedContainer || !seedSlider) { setTimeout(watchSeed, 500); return; }
972
+ function sync() {
973
+ const el = seedContainer.querySelector('input[type="range"],input[type="number"]');
974
+ if (el && el.value) { seedSlider.value = el.value; if (seedVal) seedVal.textContent = el.value; }
975
+ }
976
+ const obs = new MutationObserver(sync);
977
+ obs.observe(seedContainer, {childList:true, subtree:true, attributes:true, attributeFilter:['value']});
978
+ setInterval(sync, 1000);
979
+ }
980
+ watchSeed();
981
+
982
+ function watchExampleResults() {
983
+ const container = document.getElementById('example-result-data');
984
+ if (!container) { setTimeout(watchExampleResults, 500); return; }
985
+
986
+ let lastProcessed = '';
987
+
988
+ function checkResult() {
989
+ const el = container.querySelector('textarea') || container.querySelector('input');
990
+ if (!el) return;
991
+ const val = el.value;
992
+ if (!val || val === lastProcessed || val.length < 20) return;
993
+
994
+ try {
995
+ const data = JSON.parse(val);
996
+ if (data.status === 'ok' && data.images && data.images.length > 0) {
997
+ lastProcessed = val;
998
+ if (window.__clearAll) window.__clearAll();
999
+ if (window.__setPrompt && data.prompt) window.__setPrompt(data.prompt);
1000
+ data.images.forEach((b64, i) => {
1001
+ if (b64 && window.__addImage) {
1002
+ const name = (data.names && data.names[i]) ? data.names[i] : ('example_' + (i+1) + '.jpg');
1003
+ window.__addImage(b64, name);
1004
+ }
1005
+ });
1006
+ document.querySelectorAll('.example-card.loading').forEach(c => c.classList.remove('loading'));
1007
+ if (window.__showToast) window.__showToast('Example loaded \u2014 ' + data.images.length + ' image(s)', 'info');
1008
+ } else if (data.status === 'error') {
1009
+ document.querySelectorAll('.example-card.loading').forEach(c => c.classList.remove('loading'));
1010
+ if (window.__showToast) window.__showToast('Could not load example images', 'error');
1011
+ }
1012
+ } catch(e) {
1013
+ console.error('Example parse error:', e);
1014
+ }
1015
+ }
1016
+
1017
+ const obs = new MutationObserver(checkResult);
1018
+ obs.observe(container, {childList:true, subtree:true, characterData:true, attributes:true});
1019
+ setInterval(checkResult, 500);
1020
+ }
1021
+ watchExampleResults();
1022
+ }
1023
+ """
1024
+
1025
+ # ── SVG assets ─────────────────────────────────────────────────────────────────
1026
+ DOWNLOAD_SVG = '<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 16l-5-5h3V4h4v7h3l-5 5z"/><path d="M20 18H4v2h16v-2z"/></svg>'
1027
+
1028
+ UPLOAD_SVG = '<svg class="tb-svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 01-2 2H5a2 2 0 01-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>'
1029
+
1030
+ REMOVE_SVG = '<svg class="tb-svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="15" y1="9" x2="9" y2="15"/><line x1="9" y1="9" x2="15" y2="15"/></svg>'
1031
+
1032
+ CLEAR_SVG = '<svg class="tb-svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"/><line x1="10" y1="11" x2="10" y2="17"/><line x1="14" y1="11" x2="14" y2="17"/></svg>'
1033
+
1034
+ GITHUB_SVG = '<svg width="15" height="15" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path fill="#ffffff" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg>'
1035
+
1036
+ FIRE_LOGO_SVG = '<svg viewBox="0 0 24 24" fill="white" xmlns="http://www.w3.org/2000/svg"><path d="M12 23c-3.6 0-8-2.69-8-7.5 0-3.5 3-6.5 4.5-8 .27-.27.75-.08.75.28v2.44c0 .42.5.63.72.28C12.28 7.5 13 3 13 1c0-.42.48-.64.8-.35C18 4.5 20 9 20 12c0 5.5-3.5 11-8 11z"/></svg>'
1037
+
1038
+ # ── Gradio app ─────────────────────────────────────────────────────────────────
1039
  with gr.Blocks() as demo:
1040
+
1041
+ hidden_images_b64 = gr.Textbox(value="[]", elem_id="hidden-images-b64", elem_classes="hidden-input", container=False)
1042
+ prompt = gr.Textbox(value="", elem_id="prompt-gradio-input", elem_classes="hidden-input", container=False)
1043
+ seed = gr.Slider(minimum=0, maximum=MAX_SEED, step=1, value=0, elem_id="gradio-seed", elem_classes="hidden-input", container=False)
1044
+ randomize_seed = gr.Checkbox(value=True, elem_id="gradio-randomize", elem_classes="hidden-input", container=False)
1045
+ guidance_scale = gr.Slider(minimum=1.0, maximum=10.0, step=0.1, value=1.0, elem_id="gradio-guidance", elem_classes="hidden-input", container=False)
1046
+ steps = gr.Slider(minimum=1, maximum=50, step=1, value=4, elem_id="gradio-steps", elem_classes="hidden-input", container=False)
1047
+ result = gr.Image(elem_id="gradio-result", elem_classes="hidden-input", container=False, format="png")
1048
+
1049
+ example_idx = gr.Textbox(value="", elem_id="example-idx-input", elem_classes="hidden-input", container=False)
1050
+ example_result = gr.Textbox(value="", elem_id="example-result-data", elem_classes="hidden-input", container=False)
1051
+ example_load_btn = gr.Button("Load Example", elem_id="example-load-btn")
1052
+
1053
+ gr.HTML(f"""
1054
+ <div class="app-shell">
1055
+
1056
+ <!-- Header with GitHub top-right -->
1057
+ <div class="app-header">
1058
+ <div class="app-header-left">
1059
+ <div class="app-logo">{FIRE_LOGO_SVG}</div>
1060
+ <span class="app-title">FireRed-Image-Edit</span>
1061
+ <span class="app-badge">v1.1</span>
1062
+ <span class="app-badge fast">4-Step Fast</span>
1063
+ </div>
1064
+ <a href="https://github.com/PRITHIVSAKTHIUR/FireRed-Image-Edit-1.0-Fast"
1065
+ target="_blank" class="gh-btn">
1066
+ {GITHUB_SVG}
1067
+ <span>GitHub</span>
1068
+ </a>
1069
+ </div>
1070
+
1071
+ <!-- Toolbar -->
1072
+ <div class="app-toolbar">
1073
+ <button id="tb-upload" class="modern-tb-btn" title="Upload images">
1074
+ {UPLOAD_SVG}<span class="tb-label">Upload</span>
1075
+ </button>
1076
+ <button id="tb-remove" class="modern-tb-btn" title="Remove selected image">
1077
+ {REMOVE_SVG}<span class="tb-label">Remove</span>
1078
+ </button>
1079
+ <button id="tb-clear" class="modern-tb-btn" title="Clear all images">
1080
+ {CLEAR_SVG}<span class="tb-label">Clear All</span>
1081
+ </button>
1082
+ <div class="tb-sep"></div>
1083
+ <span id="tb-image-count" class="tb-info">No images</span>
1084
+ </div>
1085
+
1086
+ <!-- Main row -->
1087
+ <div class="app-main-row">
1088
+
1089
+ <!-- Left panel -->
1090
+ <div class="app-main-left">
1091
+ <div id="gallery-drop-zone">
1092
+ <div id="upload-prompt" class="upload-prompt-modern">
1093
+ <div id="upload-click-area" class="upload-click-area">
1094
+ <svg viewBox="0 0 80 80" fill="none" xmlns="http://www.w3.org/2000/svg">
1095
+ <rect x="8" y="14" width="64" height="52" rx="6" fill="none"
1096
+ stroke="#1E90FF" stroke-width="2" stroke-dasharray="4 3"/>
1097
+ <polygon points="12,62 30,40 42,50 54,34 68,62"
1098
+ fill="rgba(30,144,255,0.15)" stroke="#1E90FF" stroke-width="1.5"/>
1099
+ <circle cx="28" cy="30" r="6"
1100
+ fill="rgba(30,144,255,0.2)" stroke="#1E90FF" stroke-width="1.5"/>
1101
+ </svg>
1102
+ <span class="upload-main-text">Click or drag images here</span>
1103
+ <span class="upload-sub-text">Supports multiple images for reference-based editing and guided manipulation</span>
1104
+ </div>
1105
+ </div>
1106
+ <input id="custom-file-input" type="file" accept="image/*" multiple style="display:none;" />
1107
+ <div id="image-gallery-grid" class="image-gallery-grid" style="display:none;"></div>
1108
+ </div>
1109
+
1110
+ <div class="hint-bar">
1111
+ <b>Upload:</b> Click or drag to add images &nbsp;&middot;&nbsp;
1112
+ <b>Multi-image:</b> Upload multiple images for reference-based editing &nbsp;&middot;&nbsp;
1113
+ <kbd>Remove</kbd> deletes selected &nbsp;&middot;&nbsp;
1114
+ <kbd>Clear All</kbd> removes everything
1115
+ </div>
1116
+
1117
+ <div class="suggestions-section">
1118
+ <div class="suggestions-title">Quick Prompts</div>
1119
+ <div class="suggestions-wrap">
1120
+ <button class="suggestion-chip" onclick="window.__setPrompt('Transform the image into a dotted cartoon style.')">Cartoon Style</button>
1121
+ <button class="suggestion-chip" onclick="window.__setPrompt('Convert it to black and white.')">Black and White</button>
1122
+ <button class="suggestion-chip" onclick="window.__setPrompt('Add cinematic lighting with warm orange tones and film grain.')">Cinematic</button>
1123
+ <button class="suggestion-chip" onclick="window.__setPrompt('Transform into anime style illustration.')">Anime Style</button>
1124
+ <button class="suggestion-chip" onclick="window.__setPrompt('Apply oil painting effect with visible brush strokes.')">Oil Painting</button>
1125
+ <button class="suggestion-chip" onclick="window.__setPrompt('Enhance and upscale with more detail and clarity.')">Enhance</button>
1126
+ <button class="suggestion-chip" onclick="window.__setPrompt('Make it look like a watercolor painting with soft edges.')">Watercolor</button>
1127
+ <button class="suggestion-chip" onclick="window.__setPrompt('Add dramatic sunset sky and warm lighting.')">Sunset Glow</button>
1128
+ <button class="suggestion-chip" onclick="window.__setPrompt('Convert to detailed pencil sketch with cross-hatching and shading.')">Pencil Sketch</button>
1129
+ <button class="suggestion-chip" onclick="window.__setPrompt('Apply pop art style with bold colors and halftone patterns.')">Pop Art</button>
1130
+ <button class="suggestion-chip" onclick="window.__setPrompt('Apply a vintage retro film look with faded colors and light leaks.')">Vintage Retro</button>
1131
+ <button class="suggestion-chip" onclick="window.__setPrompt('Add neon glow effects with vibrant colors against a dark background.')">Neon Glow</button>
1132
+ <button class="suggestion-chip" onclick="window.__setPrompt('Convert to pixel art style with a retro 16-bit aesthetic.')">Pixel Art</button>
1133
+ <button class="suggestion-chip" onclick="window.__setPrompt('Simplify into a clean minimalist illustration with flat colors.')">Minimalist</button>
1134
+ <button class="suggestion-chip" onclick="window.__setPrompt('Convert to low poly 3D geometric art style.')">Low Poly 3D</button>
1135
+ <button class="suggestion-chip" onclick="window.__setPrompt('Transform into comic book style with bold outlines and cel shading.')">Comic Book</button>
1136
+ </div>
1137
+ </div>
1138
+
1139
+ <div class="examples-section">
1140
+ <div class="examples-title">Quick Examples &mdash; click to load</div>
1141
+ <div class="examples-scroll">
1142
+ {EXAMPLE_CARDS_HTML}
1143
+ </div>
1144
+ </div>
1145
+ </div>
1146
+
1147
+ <!-- Right panel -->
1148
+ <div class="app-main-right">
1149
+ <div class="panel-card">
1150
+ <div class="panel-card-title">Edit Instruction</div>
1151
+ <div class="panel-card-body">
1152
+ <label class="modern-label" for="custom-prompt-input">Prompt</label>
1153
+ <textarea id="custom-prompt-input" class="modern-textarea" rows="3"
1154
+ placeholder="e.g., transform into anime, upscale, change lighting..."></textarea>
1155
+ </div>
1156
+ </div>
1157
+
1158
+ <div style="padding:12px 20px;">
1159
+ <button id="custom-run-btn" class="btn-run">
1160
+ <svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" width="18" height="18">
1161
+ <path d="M12 23c-3.6 0-8-2.69-8-7.5 0-3.5 3-6.5 4.5-8 .27-.27.75-.08.75.28v2.44c0 .42.5.63.72.28C12.28 7.5 13 3 13 1c0-.42.48-.64.8-.35C18 4.5 20 9 20 12c0 5.5-3.5 11-8 11z" fill="white"/>
1162
+ </svg>
1163
+ <span id="run-btn-label">Edit Image</span>
1164
+ </button>
1165
+ </div>
1166
+
1167
+ <div class="output-frame" style="flex:1">
1168
+ <div class="out-title">
1169
+ <span>Output</span>
1170
+ <span id="dl-btn-output" class="out-download-btn" title="Download">
1171
+ {DOWNLOAD_SVG} Save
1172
+ </span>
1173
+ </div>
1174
+ <div class="out-body" id="output-image-container">
1175
+ <div class="modern-loader" id="output-loader">
1176
+ <div class="loader-spinner"></div>
1177
+ <div class="loader-text">Processing image...</div>
1178
+ <div class="loader-bar-track"><div class="loader-bar-fill"></div></div>
1179
+ </div>
1180
+ <div class="out-placeholder" id="output-placeholder">Result will appear here</div>
1181
+ </div>
1182
+ </div>
1183
+
1184
+ <div class="settings-group">
1185
+ <div class="settings-group-title">Advanced Settings</div>
1186
+ <div class="settings-group-body">
1187
+ <div class="slider-row">
1188
+ <label>Seed</label>
1189
+ <input type="range" id="custom-seed" min="0" max="2147483647" step="1" value="0">
1190
+ <span class="slider-val" id="custom-seed-val">0</span>
1191
+ </div>
1192
+ <div class="checkbox-row">
1193
+ <input type="checkbox" id="custom-randomize" checked>
1194
+ <label for="custom-randomize">Randomize seed</label>
1195
+ </div>
1196
+ <div class="slider-row">
1197
+ <label>Guidance</label>
1198
+ <input type="range" id="custom-guidance" min="1" max="10" step="0.1" value="1.0">
1199
+ <span class="slider-val" id="custom-guidance-val">1.0</span>
1200
+ </div>
1201
+ <div class="slider-row">
1202
+ <label>Steps</label>
1203
+ <input type="range" id="custom-steps" min="1" max="50" step="1" value="4">
1204
+ <span class="slider-val" id="custom-steps-val">4</span>
1205
+ </div>
1206
+ </div>
1207
+ </div>
1208
+ </div>
1209
+ </div>
1210
+
1211
+ <!-- Footer: only model credit, no GitHub link -->
1212
+ <div class="exp-note">
1213
+ Experimental Space for
1214
+ <a href="https://huggingface.co/FireRedTeam/FireRed-Image-Edit-1.1" target="_blank">FireRed-Image-Edit-1.1</a>
1215
+ </div>
1216
+
1217
+ <!-- Status bar -->
1218
+ <div class="app-statusbar">
1219
+ <div class="sb-section" id="sb-image-count">No images uploaded</div>
1220
+ <div class="sb-section sb-fixed">Ready</div>
1221
+ </div>
1222
+
1223
+ </div><!-- /app-shell -->
1224
+ """)
1225
+
1226
+ run_btn = gr.Button("Run", elem_id="gradio-run-btn")
1227
+
1228
+ demo.load(fn=None, js=gallery_js)
1229
+ demo.load(fn=None, js=wire_outputs_js)
1230
+
1231
+ run_btn.click(
1232
  fn=infer,
1233
+ inputs=[hidden_images_b64, prompt, seed, randomize_seed, guidance_scale, steps],
1234
+ outputs=[result, seed],
1235
+ js=r"""(imgs, p, s, rs, gs, st) => {
1236
+ const images = window.__uploadedImages || [];
1237
+ const b64Array = images.map(img => img.b64);
1238
+ const imgsJson = JSON.stringify(b64Array);
1239
+ const promptEl = document.getElementById('custom-prompt-input');
1240
+ const promptVal = promptEl ? promptEl.value : p;
1241
+ return [imgsJson, promptVal, s, rs, gs, st];
1242
+ }""",
1243
+ )
1244
+
1245
+ example_load_btn.click(
1246
+ fn=load_example_data,
1247
+ inputs=[example_idx],
1248
+ outputs=[example_result],
1249
+ queue=False,
1250
  )
1251
 
1252
  if __name__ == "__main__":
1253
+ demo.queue(max_size=50).launch(
1254
+ css=css,
1255
+ mcp_server=True,
1256
+ ssr_mode=False,
1257
+ show_error=True,
1258
+ allowed_paths=["examples"],
1259
+ )