amirgame197 commited on
Commit
b25a6ce
1 Parent(s): b03366b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -2,6 +2,7 @@ import spaces
2
  import gradio as gr
3
  import cv2
4
  import numpy as np
 
5
 
6
  from PIL import Image
7
  from transparent_background import Remover
@@ -32,9 +33,15 @@ def doo(video):
32
  print(f"Processing: {processed_frames}")
33
  out = remover.process(img, type='green')
34
  writer.write(cv2.cvtColor(np.array(out), cv2.COLOR_BGR2RGB))
 
 
 
 
 
 
35
  cap.release()
36
  writer.release()
37
  return 'output.mp4'
38
 
39
  iface = gr.Interface(fn=doo, inputs="video", outputs="video")
40
- iface.launch()
 
2
  import gradio as gr
3
  import cv2
4
  import numpy as np
5
+ import gc # For manual garbage collection
6
 
7
  from PIL import Image
8
  from transparent_background import Remover
 
33
  print(f"Processing: {processed_frames}")
34
  out = remover.process(img, type='green')
35
  writer.write(cv2.cvtColor(np.array(out), cv2.COLOR_BGR2RGB))
36
+
37
+ # Release GPU memory after processing a certain number of frames
38
+ if processed_frames % 100 == 0:
39
+ del out # Delete the variable holding the processed frame
40
+ gc.collect() # Perform manual garbage collection to release GPU memory
41
+
42
  cap.release()
43
  writer.release()
44
  return 'output.mp4'
45
 
46
  iface = gr.Interface(fn=doo, inputs="video", outputs="video")
47
+ iface.launch()