RafaG commited on
Commit
d0d86a9
·
verified ·
1 Parent(s): 1464745

Upload 3 files

Browse files
webui/app.py CHANGED
The diff for this file is too large to render. See raw diff
 
webui/subtitle_editor.py CHANGED
@@ -255,6 +255,7 @@ def render_specific_video(json_full_path):
255
  config_path = None
256
 
257
  config = main_improved.get_subtitle_config(config_path)
 
258
  # Ensure 'uppercase' exists as it's not in default config of main_improved
259
  config['uppercase'] = config.get('uppercase', False)
260
 
 
255
  config_path = None
256
 
257
  config = main_improved.get_subtitle_config(config_path)
258
+ # print(f"DEBUG: Loaded subt config: H={config.get('highlight_color')} B={config.get('base_color')}")
259
  # Ensure 'uppercase' exists as it's not in default config of main_improved
260
  config['uppercase'] = config.get('uppercase', False)
261
 
webui/subtitle_handler.py CHANGED
@@ -88,7 +88,7 @@ SUBTITLE_PRESETS = {
88
  "Word Killer (TikTok)": {
89
  "font_name": "Impact",
90
  "font_size": 38,
91
- "base_color": "#FFFFFF",
92
  "highlight_color": "#FF0000",
93
  "outline_color": "#000000",
94
  "outline_thickness": 3,
@@ -112,7 +112,7 @@ SUBTITLE_PRESETS = {
112
  "Rapid Fire (Sprint)": {
113
  "font_name": "Impact",
114
  "font_size": 36,
115
- "base_color": "#FFFFFF",
116
  "highlight_color": "#FFFF00",
117
  "outline_color": "#000000",
118
  "outline_thickness": 2,
@@ -257,7 +257,7 @@ SUBTITLE_PRESETS = {
257
  "font_name": "Consolas",
258
  "font_size": 26,
259
  "base_color": "#00FF00",
260
- "highlight_color": "#FFFFFF",
261
  "outline_color": "#000000",
262
  "outline_thickness": 2,
263
  "shadow_color": "#000000",
@@ -266,7 +266,7 @@ SUBTITLE_PRESETS = {
266
  "italic": False,
267
  "uppercase": True,
268
  "highlight_size": 26,
269
- "words_per_block": 3,
270
  "gap_limit": 0.5,
271
  "mode": "word_by_word",
272
  "underline": False,
@@ -279,6 +279,44 @@ SUBTITLE_PRESETS = {
279
 
280
  def generate_preview_html(font, size, color, highlight, outline, outline_thick, shadow, shadow_sz, bold, italic, upper,
281
  h_size, w_block, gap, mode, under, strike, border_s, vert_pos, align, remove_punc):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
282
  weight = "bold" if bold else "normal"
283
  style = "italic" if italic else "normal"
284
  transform = "uppercase" if upper else "none"
@@ -373,11 +411,38 @@ def render_preview_video(font, size, color, highlight, outline, outline_thick, s
373
  h_size, w_block, gap, mode, under, strike, border_s, vert_pos, align, remove_punc):
374
  # Helper to convert HEX to ASS color &HBBGGRR&
375
  def hex_to_ass(h):
376
- if not h: return "&H00FFFFFF"
377
- h = h.lstrip('#')
378
- if len(h) == 6:
379
- return f"&H00{h[4:6]}{h[2:4]}{h[0:2]}"
380
- return "&H00FFFFFF"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
381
 
382
  base_c = hex_to_ass(color)
383
  high_c = hex_to_ass(highlight)
@@ -450,7 +515,23 @@ def render_preview_video(font, size, color, highlight, outline, outline_thick, s
450
  subprocess.run(cmd, cwd=WORKING_DIR, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
451
 
452
  if os.path.exists(out_vid_path):
453
- return out_vid_path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
454
 
455
  except Exception as e:
456
  print(f"Preview Gen Error: {e}")
 
88
  "Word Killer (TikTok)": {
89
  "font_name": "Impact",
90
  "font_size": 38,
91
+ "base_color": "#FF0000",
92
  "highlight_color": "#FF0000",
93
  "outline_color": "#000000",
94
  "outline_thickness": 3,
 
112
  "Rapid Fire (Sprint)": {
113
  "font_name": "Impact",
114
  "font_size": 36,
115
+ "base_color": "#FFFF00",
116
  "highlight_color": "#FFFF00",
117
  "outline_color": "#000000",
118
  "outline_thickness": 2,
 
257
  "font_name": "Consolas",
258
  "font_size": 26,
259
  "base_color": "#00FF00",
260
+ "highlight_color": "#00FF00",
261
  "outline_color": "#000000",
262
  "outline_thickness": 2,
263
  "shadow_color": "#000000",
 
266
  "italic": False,
267
  "uppercase": True,
268
  "highlight_size": 26,
269
+ "words_per_block": 1,
270
  "gap_limit": 0.5,
271
  "mode": "word_by_word",
272
  "underline": False,
 
279
 
280
  def generate_preview_html(font, size, color, highlight, outline, outline_thick, shadow, shadow_sz, bold, italic, upper,
281
  h_size, w_block, gap, mode, under, strike, border_s, vert_pos, align, remove_punc):
282
+
283
+ # Debug inputs
284
+ #print(f"DEBUG_HTML: Inputs - Color: {color}, Highlight: {highlight}, Outline: {outline}")
285
+
286
+ def sanitize_color(c):
287
+ if not c: return "#FFFFFF"
288
+ clean = c.lstrip('#').strip()
289
+ # Handle RGB/RGBA
290
+ if clean.lower().startswith("rgb"):
291
+ try:
292
+ nums = re.findall(r"[\d\.]+", clean)
293
+ if len(nums) >= 3:
294
+ r = int(float(nums[0]))
295
+ g = int(float(nums[1]))
296
+ b = int(float(nums[2]))
297
+ r = max(0, min(255, r))
298
+ g = max(0, min(255, g))
299
+ b = max(0, min(255, b))
300
+ ret = f"#{r:02X}{g:02X}{b:02X}"
301
+ # print(f"DEBUG_HTML: Sanitized {c} -> {ret}")
302
+ return ret
303
+ except Exception as e:
304
+ print(f"DEBUG_HTML: Sanitize Error: {e}")
305
+ pass
306
+
307
+ # Ensure # prefix for standard hex if missing
308
+ if not c.startswith("#") and not c.startswith("rgb"):
309
+ return f"#{c}"
310
+
311
+ return c
312
+
313
+ color = sanitize_color(color)
314
+ highlight = sanitize_color(highlight)
315
+ outline = sanitize_color(outline)
316
+ shadow = sanitize_color(shadow)
317
+
318
+ #print(f"DEBUG_HTML: Final Colors - Color: {color}, Highlight: {highlight}")
319
+
320
  weight = "bold" if bold else "normal"
321
  style = "italic" if italic else "normal"
322
  transform = "uppercase" if upper else "none"
 
411
  h_size, w_block, gap, mode, under, strike, border_s, vert_pos, align, remove_punc):
412
  # Helper to convert HEX to ASS color &HBBGGRR&
413
  def hex_to_ass(h):
414
+ try:
415
+ with open("debug_preview.log", "a") as f:
416
+ f.write(f"PREVIEW INPUT: '{h}'\n")
417
+ except: pass
418
+
419
+ if not h: return "&H00FFFFFF&"
420
+
421
+ hex_clean = h.lstrip('#').strip()
422
+
423
+ # Handle rgb/rgba
424
+ if hex_clean.lower().startswith("rgb"):
425
+ try:
426
+ # regex to capture numbers including floats
427
+ nums = re.findall(r"[\d\.]+", hex_clean)
428
+ if len(nums) >= 3:
429
+ r = int(float(nums[0]))
430
+ g = int(float(nums[1]))
431
+ b = int(float(nums[2]))
432
+ # Clamp just in case
433
+ r = max(0, min(255, r))
434
+ g = max(0, min(255, g))
435
+ b = max(0, min(255, b))
436
+ return f"&H00{b:02X}{g:02X}{r:02X}&".upper()
437
+ except: pass
438
+
439
+ if len(hex_clean) == 3:
440
+ hex_clean = "".join([c*2 for c in hex_clean])
441
+
442
+ if len(hex_clean) == 6:
443
+ return f"&H00{hex_clean[4:6]}{hex_clean[2:4]}{hex_clean[0:2]}&".upper()
444
+
445
+ return "&H00FFFFFF&"
446
 
447
  base_c = hex_to_ass(color)
448
  high_c = hex_to_ass(highlight)
 
515
  subprocess.run(cmd, cwd=WORKING_DIR, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
516
 
517
  if os.path.exists(out_vid_path):
518
+ import shutil
519
+ # Create a timestamped copy to force browser cache refresh
520
+ import time
521
+ timestamp = int(time.time())
522
+ cache_bust_path = os.path.join(preview_dir, f"preview_render_{timestamp}.mp4")
523
+ shutil.copy(out_vid_path, cache_bust_path)
524
+
525
+ # Clean old files
526
+ try:
527
+ for f in os.listdir(preview_dir):
528
+ if f.startswith("preview_render_") and f.endswith(".mp4") and f != os.path.basename(cache_bust_path):
529
+ try:
530
+ os.remove(os.path.join(preview_dir, f))
531
+ except: pass
532
+ except: pass
533
+
534
+ return gr.update(value=cache_bust_path, autoplay=True)
535
 
536
  except Exception as e:
537
  print(f"Preview Gen Error: {e}")