File size: 9,468 Bytes
31bd05a
 
0ea4d28
 
 
 
 
 
 
 
31bd05a
 
 
 
 
 
0ea4d28
 
 
 
 
 
31bd05a
 
 
 
 
0ea4d28
 
31bd05a
 
 
 
 
 
0ea4d28
 
31bd05a
 
 
 
 
 
0ea4d28
31bd05a
 
 
 
 
 
 
 
 
 
 
0ea4d28
 
 
 
 
31bd05a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0ea4d28
 
 
31bd05a
 
 
 
 
 
 
 
 
 
 
0ea4d28
 
 
31bd05a
 
0ea4d28
 
 
 
31bd05a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0ea4d28
31bd05a
 
 
0ea4d28
31bd05a
 
0ea4d28
31bd05a
 
0ea4d28
31bd05a
 
0ea4d28
 
31bd05a
 
0ea4d28
 
31bd05a
 
0ea4d28
 
31bd05a
 
 
0ea4d28
 
31bd05a
 
 
 
0ea4d28
31bd05a
 
 
 
0ea4d28
 
31bd05a
 
0ea4d28
 
31bd05a
 
 
 
0ea4d28
 
31bd05a
 
0ea4d28
31bd05a
0ea4d28
31bd05a
 
 
 
 
 
 
0ea4d28
31bd05a
 
0ea4d28
31bd05a
0ea4d28
 
 
 
 
 
31bd05a
0ea4d28
31bd05a
 
 
 
0ea4d28
 
 
 
 
31bd05a
 
 
0ea4d28
31bd05a
 
 
0ea4d28
31bd05a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0ea4d28
 
 
 
 
 
 
31bd05a
0ea4d28
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
import gradio as gr

# 1) Your Hugging Face Space name:
SPACE_USERNAME = "hyungonryu"
SPACE_NAME = "GoeStationaryVFI"

# 2) Base URL for raw MP4 files via "resolve/main":
BASE_URL = f"https://huggingface.co/spaces/{SPACE_USERNAME}/{SPACE_NAME}/resolve/main"

html_code = f"""
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Video Sync with Custom UI</title>
  <style>
    body {{ font-family: sans-serif; margin: 20px; }}
    table {{ margin: 0 auto; }}
    td {{ padding: 5px; vertical-align: middle; }}
    .slider, .timeline-slider {{ }}
    .video-container-wrapper {{ position: relative; display: inline-block; }}
    .video-container {{
      position: relative;
      width: 640px;
      height: 480px;
      background: #000;
      overflow: hidden;
    }}
    .video {{
      position: absolute;
      top: 0;
      left: 0;
      width: 640px;
      height: 480px;
      object-fit: cover;
    }}
    .wipe-line {{
      position: absolute;
      top: 0;
      width: 2px;
      height: 100%;
      background: blue;
      pointer-events: none;
    }}
  </style>
</head>
<body>
  <center>
    <h1>Geostationary Satellite Time Interpolation</h1>
    <h4>Hyun Gon Ryu | NVIDIA AI Technology Center Korea</h4>
  </center>
  <table>
    <tr>
      <td width="700">
        <font size="1">
          This demo video consists of images generated at one-minute intervals from the KMA GK2A satellite's full-disk images,
          originally captured at ten-minute intervals, using the VFI technique.
          By using the wipe scrollbar, you can compare the original video (delineated by a blue line) with the enhanced version.
          You can adjust the zoom and playback speed, and when played at 0.3x speed, the differences between the two videos
          become distinctly apparent.
        </font>
      </td>
    </tr>
  </table>

  <!-- Video set selection -->
  <table id="videoSetTable">
    <tr>
      <td>
        Select Video Set:
        <select id="videoSetSelect">
          <option value="">No</option>
          <option value="0">TongA Case | 20220116 | ir105</option>
          <option value="1">SouthAsia | 20240820 | ir105</option>
          <option value="2">EastAsia | 20240820 | ir105</option>
          <option value="3">SouthWestAsia | 20240820 | ir105</option>
        </select>
      </td>
    </tr>
  </table>

  <table id="controlTable">
    <!-- 1st Row: Play button, Speed, Screen Size -->
    <tr>
      <td>
        <button id="playPauseBtn">PLAY</button>
      </td>
      <td>
        Screen Size:
        <select id="scaleSelect">
          <option value="0.5">0.5</option>
          <option value="1" selected>1</option>
          <option value="1.5">1.5</option>
          <option value="2">2</option>
        </select>
      </td>
      <td>
        Speed:
        <select id="speedSelect">
          <option value="0.1">0.1</option>
          <option value="0.2">0.2</option>
          <option value="0.3">0.3</option>
          <option value="0.4">0.4</option>
          <option value="0.5">0.5</option>
          <option value="0.6">0.6</option>
          <option value="0.7">0.7</option>
          <option value="0.8">0.8</option>
          <option value="0.9">0.9</option>
          <option value="1" selected>1</option>
          <option value="2">2</option>
          <option value="4">4</option>
        </select>
      </td>
    </tr>

    <!-- 2nd Row: Wipe Slider -->
    <tr>
      <td colspan="3">
        <input type="range" id="wipeRange" class="slider" min="0" max="1" step="0.01" value="0.5">
      </td>
    </tr>

    <!-- 3rd Row: Timeline Slider -->
    <tr>
      <td colspan="3">
        <input type="range" id="timelineRange" class="timeline-slider" min="0" max="100" step="0.1" value="0">
      </td>
    </tr>

    <!-- 4th Row: Video Area -->
    <tr>
      <td colspan="3">
        <div class="video-container-wrapper">
          <div class="video-container" id="videoContainer">
            <!-- Default placeholders -->
            <video id="video1" class="video" src="" preload="auto" muted></video>
            <video id="video2" class="video" src="" preload="auto" muted></video>
            <div id="wipeLine" class="wipe-line"></div>
          </div>
        </div>
      </td>
    </tr>
  </table>

  <script>
    // Base width remains constant.
    const baseWidth = 640;

    // We'll store the base "resolve/main" URL from Python as a JS var:
    const BASE_URL = "{BASE_URL}";

    // Predefined video sets.
    const videoSets = [
      {{ label: "TongA Case",    area: "TongaArea", date: "20220116", sensor: "ir105" }},
      {{ label: "SouthAsia",     area: "SouthAsia", date: "20240820", sensor: "ir105" }},
      {{ label: "EastAsia",      area: "EastAsia",  date: "20240820", sensor: "ir105" }},
      {{ label: "SouthWestAsia", area: "WestAsia",  date: "20240820", sensor: "ir105" }},
    ];

    // Get DOM elements.
    const video1 = document.getElementById("video1");
    const video2 = document.getElementById("video2");
    const playPauseBtn = document.getElementById("playPauseBtn");
    const wipeRange = document.getElementById("wipeRange");
    const timelineRange = document.getElementById("timelineRange");
    const scaleSelect = document.getElementById("scaleSelect");
    const speedSelect = document.getElementById("speedSelect");
    const videoContainer = document.getElementById("videoContainer");
    const wipeLine = document.getElementById("wipeLine");
    const controlTable = document.getElementById("controlTable");
    const videoSetSelect = document.getElementById("videoSetSelect");

    let isPlaying = false;

    // Update playback speed.
    function updateSpeed() {{
      const speedValue = parseFloat(speedSelect.value);
      video1.playbackRate = speedValue;
      video2.playbackRate = speedValue;
    }}

    // Update the wipe effect.
    function updateWipe() {{
      const wipeValue = parseFloat(wipeRange.value);
      const rightPercent = (1 - wipeValue) * 100;
      video2.style.clipPath = `inset(0 ${{rightPercent}}% 0 0)`;
      // Calculate position using the base width.
      const lineX = baseWidth * wipeValue - (wipeLine.clientWidth / 2);
      wipeLine.style.left = `${{lineX}}px`;
    }}

    // Update timeline slider based on video progress.
    function updateTimeline() {{
      if (video1.duration) {{
        const percent = (video1.currentTime / video1.duration) * 100;
        timelineRange.value = percent;
      }}
    }}
    video1.addEventListener("timeupdate", updateTimeline);

    // Toggle play/pause.
    function togglePlayPause() {{
      if (!isPlaying) {{
        video1.play();
        video2.play();
        playPauseBtn.textContent = "Pause";
        isPlaying = true;
      }} else {{
        video1.pause();
        video2.pause();
        playPauseBtn.textContent = "Play";
        isPlaying = false;
      }}
    }}

    // Seek both videos.
    function seekTimeline() {{
      if (video1.duration) {{
        const percent = timelineRange.value / 100;
        const newTime = video1.duration * percent;
        video1.currentTime = newTime;
        video2.currentTime = newTime;
      }}
    }}

    // Update scale and adjust related elements.
    function updateScale() {{
      const scaleValue = parseFloat(scaleSelect.value);
      videoContainer.style.transform = `scale(${{scaleValue}})`;
      videoContainer.style.transformOrigin = "top left";
      // Update slider and table widths to the visually scaled size.
      const effectiveWidth = baseWidth * scaleValue;
      wipeRange.style.width = effectiveWidth + "px";
      timelineRange.style.width = effectiveWidth + "px";
      controlTable.style.width = effectiveWidth + "px";
      updateWipe();
    }}

    // Update video sources based on selected video set.
    function updateVideoSet() {{
      const selectedIndex = videoSetSelect.value;
      if (selectedIndex === "") {{
        // "No" selected: clear sources or do nothing.
        video1.removeAttribute("src");
        video2.removeAttribute("src");
        video1.load();
        video2.load();
        return;
      }}
      const videoSet = videoSets[parseInt(selectedIndex)];
      const area = videoSet.area;
      const date = videoSet.date;
      const sensor = videoSet.sensor;

      // Use "resolve/main" URLs:
      const originalFile = `${{BASE_URL}}/${{area}}/video_${{area}}_${{sensor}}um_${{date}}_10min_010fps.mp4`;
      const enhancedFile = `${{BASE_URL}}/${{area}}/video_${{area}}_${{sensor}}um_${{date}}_01min_100fps.mp4`;

      // Update video sources.
      video1.setAttribute("src", originalFile);
      video2.setAttribute("src", enhancedFile);

      // Reload the videos.
      video1.load();
      video2.load();
    }}

    // Event listeners.
    playPauseBtn.addEventListener("click", togglePlayPause);
    wipeRange.addEventListener("input", updateWipe);
    timelineRange.addEventListener("input", seekTimeline);
    scaleSelect.addEventListener("change", updateScale);
    speedSelect.addEventListener("change", updateSpeed);
    videoSetSelect.addEventListener("change", updateVideoSet);

    // Initial setup.
    updateWipe();
    updateScale();
    updateSpeed();
  </script>
</body>
</html>
"""

# Build the Gradio app with just an HTML component.
def build_app():
    with gr.Blocks() as demo:
        gr.HTML(html_code)
    return demo

demo = build_app()

if __name__ == "__main__":
    demo.launch()