observantdistressed commited on
Commit
15748f3
·
verified ·
1 Parent(s): c80cf4c

UI: move slider JS to gr.Blocks(js=...) — gr.HTML sanitizes <script> tags

Browse files
Files changed (1) hide show
  1. app.py +53 -65
app.py CHANGED
@@ -872,71 +872,59 @@ CSS = """
872
  """
873
 
874
 
875
- with gr.Blocks(delete_cache=(3600, 10800)) as demo:
876
- gr.HTML(
877
- """<script>
878
- (function() {
879
- function styleSlider() {
880
- var inp = document.querySelector('#duration-slider input[data-testid="range-input"]')
881
- || document.querySelector('#duration-slider input[type="range"]');
882
- if (!inp) return false;
883
- /* thumb */
884
- inp.style.setProperty('--thumb-bg', 'linear-gradient(135deg, #00e5c8, #6c5ce7)', '');
885
- inp.style.setProperty('--thumb-shadow', '0 0 8px rgba(0, 229, 200, 0.5)', '');
886
- /* inject a style tag scoped to this input */
887
- var id = 'slider-theme-styles';
888
- if (!document.getElementById(id)) {
889
- var s = document.createElement('style');
890
- s.id = id;
891
- s.textContent = `
892
- #duration-slider input[type="range"]::-webkit-slider-thumb {
893
- -webkit-appearance: none !important;
894
- appearance: none !important;
895
- width: 18px !important;
896
- height: 18px !important;
897
- border-radius: 50% !important;
898
- background: linear-gradient(135deg, #00e5c8, #6c5ce7) !important;
899
- border: 2px solid rgba(255,255,255,0.3) !important;
900
- box-shadow: 0 0 8px rgba(0, 229, 200, 0.5) !important;
901
- cursor: pointer !important;
902
- margin-top: -6px !important;
903
- }
904
- #duration-slider input[type="range"]::-webkit-slider-runnable-track {
905
- background: linear-gradient(90deg, #00d4aa, #6c5ce7) !important;
906
- height: 6px !important;
907
- border-radius: 3px !important;
908
- }
909
- #duration-slider input[type="range"]::-moz-range-thumb {
910
- width: 18px !important;
911
- height: 18px !important;
912
- border-radius: 50% !important;
913
- background: linear-gradient(135deg, #00e5c8, #6c5ce7) !important;
914
- border: 2px solid rgba(255,255,255,0.3) !important;
915
- box-shadow: 0 0 8px rgba(0, 229, 200, 0.5) !important;
916
- cursor: pointer !important;
917
- }
918
- #duration-slider input[type="range"]::-moz-range-track {
919
- background: linear-gradient(90deg, #00d4aa, #6c5ce7) !important;
920
- height: 6px !important;
921
- border-radius: 3px !important;
922
- }
923
- `;
924
- document.head.appendChild(s);
925
- }
926
- return true;
927
- }
928
- /* try immediately, then retry with observer until Gradio renders */
929
- if (!styleSlider()) {
930
- var obs = new MutationObserver(function() {
931
- if (styleSlider()) obs.disconnect();
932
- });
933
- obs.observe(document.body, {childList: true, subtree: true});
934
- setTimeout(function() { obs.disconnect(); }, 15000);
935
- }
936
- })();
937
- </script>""",
938
- visible=False,
939
- )
940
  gr.Markdown(model_title())
941
  gr.Markdown("Run Wan 2.2 in just 4-8 steps, fp8 quantization & AoT compilation - compatible with 🧨 diffusers and ZeroGPU")
942
 
 
872
  """
873
 
874
 
875
+ THEME_JS = r"""
876
+ (function() {
877
+ function styleSlider() {
878
+ var inp = document.querySelector('#duration-slider input[data-testid="range-input"]')
879
+ || document.querySelector('#duration-slider input[type="range"]');
880
+ if (!inp) return false;
881
+ var id = 'slider-theme-styles';
882
+ if (!document.getElementById(id)) {
883
+ var s = document.createElement('style');
884
+ s.id = id;
885
+ s.textContent = [
886
+ '#duration-slider input[type="range"]::-webkit-slider-thumb {',
887
+ ' -webkit-appearance: none !important;',
888
+ ' appearance: none !important;',
889
+ ' width: 18px !important; height: 18px !important;',
890
+ ' border-radius: 50% !important;',
891
+ ' background: linear-gradient(135deg, #00e5c8, #6c5ce7) !important;',
892
+ ' border: 2px solid rgba(255,255,255,0.3) !important;',
893
+ ' box-shadow: 0 0 8px rgba(0,229,200,0.5) !important;',
894
+ ' cursor: pointer !important; margin-top: -6px !important;',
895
+ '}',
896
+ '#duration-slider input[type="range"]::-webkit-slider-runnable-track {',
897
+ ' background: linear-gradient(90deg, #00d4aa, #6c5ce7) !important;',
898
+ ' height: 6px !important; border-radius: 3px !important;',
899
+ '}',
900
+ '#duration-slider input[type="range"]::-moz-range-thumb {',
901
+ ' width: 18px !important; height: 18px !important;',
902
+ ' border-radius: 50% !important;',
903
+ ' background: linear-gradient(135deg, #00e5c8, #6c5ce7) !important;',
904
+ ' border: 2px solid rgba(255,255,255,0.3) !important;',
905
+ ' box-shadow: 0 0 8px rgba(0,229,200,0.5) !important;',
906
+ ' cursor: pointer !important;',
907
+ '}',
908
+ '#duration-slider input[type="range"]::-moz-range-track {',
909
+ ' background: linear-gradient(90deg, #00d4aa, #6c5ce7) !important;',
910
+ ' height: 6px !important; border-radius: 3px !important;',
911
+ '}',
912
+ ].join('\n');
913
+ document.head.appendChild(s);
914
+ }
915
+ return true;
916
+ }
917
+ if (!styleSlider()) {
918
+ var obs = new MutationObserver(function() {
919
+ if (styleSlider()) obs.disconnect();
920
+ });
921
+ obs.observe(document.body, {childList: true, subtree: true});
922
+ setTimeout(function() { obs.disconnect(); }, 15000);
923
+ }
924
+ })();
925
+ """
926
+
927
+ with gr.Blocks(delete_cache=(3600, 10800), js=THEME_JS) as demo:
 
 
 
 
 
 
 
 
 
 
 
 
928
  gr.Markdown(model_title())
929
  gr.Markdown("Run Wan 2.2 in just 4-8 steps, fp8 quantization & AoT compilation - compatible with 🧨 diffusers and ZeroGPU")
930