ziqiangao commited on
Commit
e835e58
·
1 Parent(s): 2bf6b73

update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -95,6 +95,11 @@ def stamp_text(draw, text, font, position, align='left'):
95
  def linear_interpolate(start, stop, progress):
96
  return start + progress * (stop - start)
97
 
 
 
 
 
 
98
  def render_frame(params):
99
  n, samples_array, cover_img, title, artist, dominant_color, width, height, fps, name, oscres = params
100
  num_frames = len(samples_array) // (11025 // fps)
@@ -127,8 +132,7 @@ def render_frame(params):
127
  os.makedirs(path+f'out/{name}/', exist_ok=True)
128
  img.save(path+f'out/{name}/{str(n)}.png', 'PNG',)
129
 
130
- progress = (n + 1) / num_frames * 100
131
- gr.Interface.update("Processing frames: {:.2f}%".format(progress))
132
 
133
  def RenderVid(af, n, fps=30):
134
  (ffmpeg
@@ -139,7 +143,7 @@ def RenderVid(af, n, fps=30):
139
  )
140
  gr.Interface.download(f"{n}.mp4")
141
 
142
- def main(file, name, fps=30, res: tuple=(1280,720), oscres = 512):
143
  global iii
144
  iii = 0
145
  # Load the audio file
@@ -165,7 +169,10 @@ def main(file, name, fps=30, res: tuple=(1280,720), oscres = 512):
165
 
166
  try:
167
  with Pool(cpu_count()) as pool:
168
- pool.map(render_frame, params)
 
 
 
169
  except Exception as e:
170
  print('Ended in error: ' + traceback.format_exc())
171
 
@@ -185,13 +192,13 @@ def main(file, name, fps=30, res: tuple=(1280,720), oscres = 512):
185
  subprocess.run(ffmpeg_cmd)
186
  gr.Interface.download(f"{name}.mp4")
187
 
188
- def gradio_interface(audio_file, output_name, fps=30, vidwidth=1280, vidhight=720, oscres=512):
189
- resolution = f"{vidwidth}x{vidhight}"
190
  res = tuple(map(int, resolution.split('x')))
191
  main(audio_file, output_name, fps=fps, res=res, oscres=oscres)
192
  return f"{output_name}.mp4"
193
 
194
- # Define Gradio interface
195
  iface = gr.Interface(
196
  fn=gradio_interface,
197
  inputs=[
 
95
  def linear_interpolate(start, stop, progress):
96
  return start + progress * (stop - start)
97
 
98
+ def filecount(p):
99
+ files = os.listdir()
100
+ file_count = len(files)
101
+ return file_count
102
+
103
  def render_frame(params):
104
  n, samples_array, cover_img, title, artist, dominant_color, width, height, fps, name, oscres = params
105
  num_frames = len(samples_array) // (11025 // fps)
 
132
  os.makedirs(path+f'out/{name}/', exist_ok=True)
133
  img.save(path+f'out/{name}/{str(n)}.png', 'PNG',)
134
 
135
+ return 1 # Indicate one frame processed
 
136
 
137
  def RenderVid(af, n, fps=30):
138
  (ffmpeg
 
143
  )
144
  gr.Interface.download(f"{n}.mp4")
145
 
146
+ def main(file, name, fps=30, res: tuple=(1280,720), oscres=512):
147
  global iii
148
  iii = 0
149
  # Load the audio file
 
169
 
170
  try:
171
  with Pool(cpu_count()) as pool:
172
+ # Use imap to get progress updates
173
+ for _ in pool.imap_unordered(render_frame, params):
174
+ iii += 1 # Increment frame count for progress
175
+
176
  except Exception as e:
177
  print('Ended in error: ' + traceback.format_exc())
178
 
 
192
  subprocess.run(ffmpeg_cmd)
193
  gr.Interface.download(f"{name}.mp4")
194
 
195
+ def gradio_interface(audio_file, output_name, fps=30, vidwidth=1280, vidheight=720, oscres=512):
196
+ resolution = f"{vidwidth}x{vidheight}"
197
  res = tuple(map(int, resolution.split('x')))
198
  main(audio_file, output_name, fps=fps, res=res, oscres=oscres)
199
  return f"{output_name}.mp4"
200
 
201
+ # Define Gradio interface with progress bar
202
  iface = gr.Interface(
203
  fn=gradio_interface,
204
  inputs=[