KingNish commited on
Commit
8f6aa89
1 Parent(s): 3d15a76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
app.py CHANGED
@@ -26,7 +26,6 @@ transform_image = transforms.Compose(
26
  ]
27
  )
28
 
29
-
30
  @spaces.GPU
31
  def fn(vid, bg_type="Color", bg_image=None, color="#00FF00", fps=0):
32
  # Load the video using moviepy
@@ -43,9 +42,11 @@ def fn(vid, bg_type="Color", bg_image=None, color="#00FF00", fps=0):
43
  chunk_duration = 1 # seconds
44
  total_duration = video.duration
45
  start_time = 0
 
 
46
 
47
  processed_frames = []
48
- yield gr.update(visible=True), gr.update(visible=False), None
49
 
50
  while start_time < total_duration:
51
  end_time = min(start_time + chunk_duration, total_duration)
@@ -59,7 +60,7 @@ def fn(vid, bg_type="Color", bg_image=None, color="#00FF00", fps=0):
59
  else:
60
  processed_image = process(pil_image, bg_image)
61
  processed_frames.append(np.array(processed_image))
62
- yield processed_image, None, None
63
 
64
  # Save processed frames for the current chunk
65
  temp_dir = "temp"
@@ -71,7 +72,7 @@ def fn(vid, bg_type="Color", bg_image=None, color="#00FF00", fps=0):
71
  processed_frames = []
72
  progress = f'<div class="progress-container"><div class="progress-bar" style="--current: {start_time}; --total: {total_duration};"></div></div>'
73
 
74
- yield None, None, gr.update(value=progress)
75
 
76
  start_time += chunk_duration
77
 
@@ -96,9 +97,9 @@ def fn(vid, bg_type="Color", bg_image=None, color="#00FF00", fps=0):
96
  for filename in os.listdir(temp_dir):
97
  os.remove(os.path.join(temp_dir, filename))
98
 
99
- yield gr.update(visible=False), gr.update(visible=True), gr.update(value=1)
100
  # Return the path to the temporary file
101
- yield processed_image, temp_filepath, None
102
 
103
 
104
  def process(image, bg):
@@ -123,7 +124,12 @@ def process(image, bg):
123
  return image
124
 
125
 
126
- with gr.Blocks() as demo:
 
 
 
 
 
127
  with gr.Row():
128
  in_video = gr.Video(label="Input Video")
129
  stream_image = gr.Image(label="Streaming Output", visible=False)
 
26
  ]
27
  )
28
 
 
29
  @spaces.GPU
30
  def fn(vid, bg_type="Color", bg_image=None, color="#00FF00", fps=0):
31
  # Load the video using moviepy
 
42
  chunk_duration = 1 # seconds
43
  total_duration = video.duration
44
  start_time = 0
45
+
46
+ progress = f'<div class="progress-container"><div class="progress-bar" style="--current: {start_time}; --total: {total_duration};"></div></div>'
47
 
48
  processed_frames = []
49
+ yield gr.update(visible=True), gr.update(visible=False), progress
50
 
51
  while start_time < total_duration:
52
  end_time = min(start_time + chunk_duration, total_duration)
 
60
  else:
61
  processed_image = process(pil_image, bg_image)
62
  processed_frames.append(np.array(processed_image))
63
+ yield processed_image, None, progress
64
 
65
  # Save processed frames for the current chunk
66
  temp_dir = "temp"
 
72
  processed_frames = []
73
  progress = f'<div class="progress-container"><div class="progress-bar" style="--current: {start_time}; --total: {total_duration};"></div></div>'
74
 
75
+ yield None, None, progress
76
 
77
  start_time += chunk_duration
78
 
 
97
  for filename in os.listdir(temp_dir):
98
  os.remove(os.path.join(temp_dir, filename))
99
 
100
+ yield gr.update(visible=False), gr.update(visible=True), progress
101
  # Return the path to the temporary file
102
+ yield processed_image, temp_filepath, progress
103
 
104
 
105
  def process(image, bg):
 
124
  return image
125
 
126
 
127
+ css="""
128
+ .progress-container {width: 100%;height: 30px;background-color: #f0f0f0;border-radius: 15px;overflow: hidden;margin-bottom: 20px}
129
+ .progress-bar {height: 100%;background-color: #4f46e5;width: calc(var(--current) / var(--total) * 100%);transition: width 0.5s ease-in-out}
130
+ """
131
+
132
+ with gr.Blocks(css=css, theme="ocean") as demo:
133
  with gr.Row():
134
  in_video = gr.Video(label="Input Video")
135
  stream_image = gr.Image(label="Streaming Output", visible=False)