Spaces:
Running

isahn commited on
Commit
2e7cbcf
Β·
verified Β·
1 Parent(s): 7f822e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -19
app.py CHANGED
@@ -2100,38 +2100,46 @@ with gr.Blocks(title="DenAIGeo β€” Dengue Origin Tracer") as demo:
2100
 
2101
  demo.queue(default_concurrency_limit=1)
2102
 
2103
- # νŽ˜μ΄μ§€ λ‘œλ“œ μ‹œ μ‹€ν–‰λ˜λŠ” JS. μ„Έ κ°€μ§€ 역할을 ν•©λ‹ˆλ‹€.
2104
- # 1) λžœλ”© νŽ˜μ΄μ§€μ˜ μ„Έκ³„μ§€λ„λŠ” μž₯μ‹μš©μ΄λΌ 슀크둀 휠둜 ν™•λŒ€/μΆ•μ†Œλ  ν•„μš”κ°€ μ—†μŠ΅λ‹ˆλ‹€.
2105
- # Python μͺ½μ—μ„œ dragmode=False 둜 클릭+λ“œλž˜κ·Έ ν™•λŒ€/이동은 이미 λ§‰μ•˜κ³ , 슀크둀 휠
2106
- # ν™•λŒ€(scrollZoom)λŠ” Plotly.js 의 config 값이라 Python figure κ°μ²΄μ—λŠ” λ‹΄κΈ°μ§€
2107
- # μ•ŠμœΌλ―€λ‘œ, μ—¬κΈ°μ„œ ν•΄λ‹Ή config λ₯Ό λ‹€μ‹œ μ μš©ν•΄ λ•λ‹ˆλ‹€.
2108
- # 2) Gradio 6.xλŠ” μ „μ—­ 'dark' 클래슀 ν•˜λ‚˜κ°€ μ•„λ‹ˆλΌ, 각 μ»΄ν¬λ„ŒνŠΈκ°€ κ°œλ³„μ μœΌλ‘œ
2109
- # window.matchMedia('(prefers-color-scheme: dark)') λ₯Ό 직접 ν™•μΈν•΄μ„œ 닀크
2110
- # μŠ€νƒ€μΌμ„ μ μš©ν•©λ‹ˆλ‹€. κ·Έλž˜μ„œ 'dark' 클래슀만 μ§€μ›Œμ„œλŠ” λΆ€μ‘±ν•˜κ³ , matchMedia
2111
- # 자체λ₯Ό νŒ¨μΉ˜ν•΄μ„œ 이 νŠΉμ • μ§ˆμ˜μ—λŠ” 항상 "닀크 μ•„λ‹˜"이라고 λ‹΅ν•˜λ„λ‘ λ§Œλ“€μ–΄μ•Ό
2112
- # μ‹œμŠ€ν…œ μ„€μ •κ³Ό λ¬΄κ΄€ν•˜κ²Œ 이 앱이 항상 라이트 λͺ¨λ“œλ‘œ λ³΄μž…λ‹ˆλ‹€. 이 νŒ¨μΉ˜λŠ” κ°€λŠ₯ν•œ
2113
- # ν•œ 빨리(λ‹€λ₯Έ μ–΄λ–€ μ»΄ν¬λ„ŒνŠΈκ°€ matchMedia λ₯Ό ν™•μΈν•˜κΈ° 전에) μ μš©λ˜μ–΄μ•Ό ν•˜λ―€λ‘œ
2114
- # ν•¨μˆ˜ 맨 μ•žμ—μ„œ μ¦‰μ‹œ μ‹€ν–‰ν•©λ‹ˆλ‹€.
2115
- # 3) ν˜Ήμ‹œ 이후에도 'dark' ν΄λž˜μŠ€κ°€ μ–΄λ”˜κ°€μ— λ‚¨μ•„μžˆλ‹€λ©΄ 계속 μ œκ±°ν•©λ‹ˆλ‹€(보쑰 μˆ˜λ‹¨).
2116
- _PAGE_LOAD_JS = """
2117
- function() {
2118
- // --- (2) matchMedia 패치: κ°€μž₯ λ¨Όμ €, ν•œ 번만 ---
2119
  if (window.matchMedia && !window._denaigeoMatchMediaPatched) {
2120
  window._denaigeoMatchMediaPatched = true;
2121
- const _origMatchMedia = window.matchMedia.bind(window);
2122
  window.matchMedia = function(query) {
2123
  if (typeof query === 'string' && query.indexOf('prefers-color-scheme') !== -1 && query.indexOf('dark') !== -1) {
2124
  return {
2125
  matches: false, media: query, onchange: null,
2126
  addListener: function() {}, removeListener: function() {},
2127
  addEventListener: function() {}, removeEventListener: function() {},
2128
- dispatchEvent: function() { return true; },
2129
  };
2130
  }
2131
  return _origMatchMedia(query);
2132
  };
2133
  }
 
 
 
2134
 
 
 
 
 
 
 
 
 
 
2135
  function patchMaps() {
2136
  document.querySelectorAll('#landing-map-plot .js-plotly-plot').forEach(function(gd) {
2137
  if (gd._denaigeoScrollZoomPatched || !gd.data || !gd.layout || !window.Plotly) return;
@@ -2157,4 +2165,4 @@ function() {
2157
  """
2158
 
2159
  if __name__ == "__main__":
2160
- demo.launch(css=_MODERN_UI_CSS, theme=theme, js=_PAGE_LOAD_JS)
 
2100
 
2101
  demo.queue(default_concurrency_limit=1)
2102
 
2103
+ # --- <head> 에 μ‚½μž…λ˜λŠ” 슀크립트: Gradio μ•± λ²ˆλ“€μ΄ λ‘œλ“œ/μ‹€ν–‰λ˜κΈ° '전에' μ‹€ν–‰λ©λ‹ˆλ‹€ ---
2104
+ # Gradio 6.xλŠ” μ „μ—­ 'dark' 클래슀 ν•˜λ‚˜κ°€ μ•„λ‹ˆλΌ, 각 μ»΄ν¬λ„ŒνŠΈκ°€ κ°œλ³„μ μœΌλ‘œ
2105
+ # window.matchMedia('(prefers-color-scheme: dark)') λ₯Ό 직접 ν™•μΈν•΄μ„œ 닀크 μŠ€νƒ€μΌμ„
2106
+ # μ μš©ν•©λ‹ˆλ‹€. 이 확인은 μ»΄ν¬λ„ŒνŠΈκ°€ 처음 λ Œλ”λ§λ  λ•Œ ν•œ 번 μΌμ–΄λ‚˜λ―€λ‘œ, demo.launch()의
2107
+ # js= νŒŒλΌλ―Έν„°(μ»΄ν¬λ„ŒνŠΈκ°€ 이미 마운트된 '이후'에 싀행됨)둜 λ‚˜μ€‘μ— matchMedia λ₯Ό
2108
+ # νŒ¨μΉ˜ν•˜λ©΄ 이미 λŠ¦μŠ΅λ‹ˆλ‹€. κ·Έλž˜μ„œ 이 νŒ¨μΉ˜λŠ” head= 둜 λ„£μ–΄ <head> μ•ˆμ˜ <script> 둜
2109
+ # μ‹€ν–‰μ‹œμΌœ, Gradio μ•± λ²ˆλ“€μ˜ <script> νƒœκ·Έλ³΄λ‹€ λ¨Όμ €(λ¬Έμ„œ μˆœμ„œμƒ μ•žμ΄λ―€λ‘œ) μ‹€ν–‰λ˜κ²Œ
2110
+ # ν•©λ‹ˆλ‹€. 닀크λͺ¨λ“œ κ΄€λ ¨ μ§ˆμ˜μ—λŠ” 항상 "닀크 μ•„λ‹˜"이라고 λ‹΅ν•˜λ„λ‘ λ§Œλ“€μ–΄μ„œ, μ‹œμŠ€ν…œ
2111
+ # μ„€μ •κ³Ό λ¬΄κ΄€ν•˜κ²Œ 이 앱은 항상 라이트 λͺ¨λ“œλ‘œ λ Œλ”λ§λ©λ‹ˆλ‹€.
2112
+ _HEAD_HTML = """
2113
+ <script>
2114
+ (function() {
 
 
 
 
2115
  if (window.matchMedia && !window._denaigeoMatchMediaPatched) {
2116
  window._denaigeoMatchMediaPatched = true;
2117
+ var _origMatchMedia = window.matchMedia.bind(window);
2118
  window.matchMedia = function(query) {
2119
  if (typeof query === 'string' && query.indexOf('prefers-color-scheme') !== -1 && query.indexOf('dark') !== -1) {
2120
  return {
2121
  matches: false, media: query, onchange: null,
2122
  addListener: function() {}, removeListener: function() {},
2123
  addEventListener: function() {}, removeEventListener: function() {},
2124
+ dispatchEvent: function() { return true; }
2125
  };
2126
  }
2127
  return _origMatchMedia(query);
2128
  };
2129
  }
2130
+ })();
2131
+ </script>
2132
+ """
2133
 
2134
+ # --- νŽ˜μ΄μ§€ λ‘œλ“œ ν›„(μ»΄ν¬λ„ŒνŠΈ 마운트 이후) μ‹€ν–‰λ˜λŠ” JS ---
2135
+ # 1) λžœλ”© νŽ˜μ΄μ§€μ˜ μ„Έκ³„μ§€λ„λŠ” μž₯μ‹μš©μ΄λΌ 슀크둀 휠둜 ν™•λŒ€/μΆ•μ†Œλ  ν•„μš”κ°€ μ—†μŠ΅λ‹ˆλ‹€.
2136
+ # Python μͺ½μ—μ„œ dragmode=False 둜 클릭+λ“œλž˜κ·Έ ν™•λŒ€/이동은 이미 λ§‰μ•˜κ³ , 슀크둀 휠
2137
+ # ν™•λŒ€(scrollZoom)λŠ” Plotly.js 의 config 값이라 Python figure κ°μ²΄μ—λŠ” λ‹΄κΈ°μ§€
2138
+ # μ•ŠμœΌλ―€λ‘œ, μ—¬κΈ°μ„œ ν•΄λ‹Ή config λ₯Ό λ‹€μ‹œ μ μš©ν•΄ λ•λ‹ˆλ‹€.
2139
+ # 2) matchMedia νŒ¨μΉ˜λŠ” μœ„ head μŠ€ν¬λ¦½νŠΈκ°€ 이미 μ²˜λ¦¬ν•˜μ§€λ§Œ, ν˜Ήμ‹œλΌλ„ μ–΄λ”˜κ°€μ— 'dark'
2140
+ # ν΄λž˜μŠ€κ°€ λ‚¨μ•„μžˆλŠ” 경우λ₯Ό λŒ€λΉ„ν•œ 보쑰 μˆ˜λ‹¨μœΌλ‘œ 계속 μ œκ±°ν•©λ‹ˆλ‹€.
2141
+ _PAGE_LOAD_JS = """
2142
+ function() {
2143
  function patchMaps() {
2144
  document.querySelectorAll('#landing-map-plot .js-plotly-plot').forEach(function(gd) {
2145
  if (gd._denaigeoScrollZoomPatched || !gd.data || !gd.layout || !window.Plotly) return;
 
2165
  """
2166
 
2167
  if __name__ == "__main__":
2168
+ demo.launch(css=_MODERN_UI_CSS, theme=theme, js=_PAGE_LOAD_JS, head=_HEAD_HTML)