ghostsInTheMachine commited on
Commit
8da09d2
·
verified ·
1 Parent(s): cb61e6f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -5
app.py CHANGED
@@ -61,7 +61,7 @@ birefnet.to(device)
61
  birefnet.eval()
62
 
63
  @spaces.GPU
64
- def predict(image):
65
  if image is None:
66
  raise gr.Error("Please upload an image.")
67
 
@@ -84,16 +84,59 @@ def predict(image):
84
 
85
  torch.cuda.empty_cache()
86
 
87
- # Save as PNG
 
 
 
 
88
  output_path = "output.png"
89
  image_masked.save(output_path)
90
 
91
- return output_path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
 
93
  iface = gr.Interface(
94
- fn=predict,
95
  inputs=gr.Image(type="numpy"),
96
- outputs=gr.Image(type="filepath"),
 
 
 
 
 
 
 
97
  )
98
 
99
  if __name__ == "__main__":
 
61
  birefnet.eval()
62
 
63
  @spaces.GPU
64
+ def remove_background(image):
65
  if image is None:
66
  raise gr.Error("Please upload an image.")
67
 
 
84
 
85
  torch.cuda.empty_cache()
86
 
87
+ # Save mask as PNG
88
+ mask_path = "mask.png"
89
+ pred_pil.save(mask_path)
90
+
91
+ # Save output as PNG
92
  output_path = "output.png"
93
  image_masked.save(output_path)
94
 
95
+ return mask_path, output_path
96
+
97
+ css = """
98
+ body {
99
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
100
+ }
101
+ .gradio-container {
102
+ background: linear-gradient(
103
+ 135deg,
104
+ #e0f7fa, #e8f5e9, #fff9c4, #ffebee,
105
+ #f3e5f5, #e1f5fe, #fff3e0, #e8eaf6
106
+ );
107
+ background-size: 400% 400%;
108
+ animation: gradient-animation 15s ease infinite;
109
+ }
110
+ @keyframes gradient-animation {
111
+ 0% { background-position: 0% 50%; }
112
+ 50% { background-position: 100% 50%; }
113
+ 100% { background-position: 0% 50%; }
114
+ }
115
+ .gradio-button {
116
+ font-family: inherit;
117
+ font-size: 16px;
118
+ font-weight: bold;
119
+ color: #000000;
120
+ background: white;
121
+ border: 2px solid black;
122
+ border-radius: 10px;
123
+ }
124
+ .gradio-button:hover {
125
+ background: #f0f0f0;
126
+ }
127
+ """
128
 
129
  iface = gr.Interface(
130
+ fn=remove_background,
131
  inputs=gr.Image(type="numpy"),
132
+ outputs=[
133
+ gr.Image(type="filepath", label="Mask"),
134
+ gr.Image(type="filepath", label="Output")
135
+ ],
136
+ title="<div style='font-size: 36px; font-weight: bold;'>{.Remove Background}</div>",
137
+ description="Upload an image to remove its background using BiRefNet.",
138
+ allow_flagging="never",
139
+ css=css
140
  )
141
 
142
  if __name__ == "__main__":