TDN-M commited on
Commit
bc76fbb
·
verified ·
1 Parent(s): d655429

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -4,6 +4,10 @@ import numpy as np
4
  import gradio as gr
5
  import base64
6
  import time
 
 
 
 
7
 
8
  # Initialize MediaPipe Selfie Segmentation
9
  mp_selfie_segmentation = mp.solutions.selfie_segmentation
@@ -34,6 +38,9 @@ def process_frame(frame, seg_enabled, blur_bg, set_bg, set_color, bg_color, blur
34
  if custom_image is not None and set_bg:
35
  bg_image = custom_image
36
 
 
 
 
37
  process_start = time.time()
38
  frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
39
  result = segmentation.process(frame_rgb)
@@ -74,7 +81,7 @@ with gr.Blocks() as demo:
74
  gr.Markdown("# AI Background Remover")
75
  with gr.Row():
76
  with gr.Column():
77
- webcam = gr.Webcam(label="Live Video")
78
  output_image = gr.Image(label="Processed Output")
79
  seg_enabled = gr.Checkbox(label="Enable Background Removal", value=True)
80
  blur_bg = gr.Checkbox(label="Blur Background")
 
4
  import gradio as gr
5
  import base64
6
  import time
7
+ import os
8
+
9
+ # Set MPLCONFIGDIR to avoid Matplotlib cache permission issues
10
+ os.environ["MPLCONFIGDIR"] = "/tmp/matplotlib-cache"
11
 
12
  # Initialize MediaPipe Selfie Segmentation
13
  mp_selfie_segmentation = mp.solutions.selfie_segmentation
 
38
  if custom_image is not None and set_bg:
39
  bg_image = custom_image
40
 
41
+ if frame is None:
42
+ return None, "No video frame received"
43
+
44
  process_start = time.time()
45
  frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
46
  result = segmentation.process(frame_rgb)
 
81
  gr.Markdown("# AI Background Remover")
82
  with gr.Row():
83
  with gr.Column():
84
+ webcam = gr.Image(sources="webcam", label="Live Video", streaming=True)
85
  output_image = gr.Image(label="Processed Output")
86
  seg_enabled = gr.Checkbox(label="Enable Background Removal", value=True)
87
  blur_bg = gr.Checkbox(label="Blur Background")