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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -15
app.py CHANGED
@@ -66,6 +66,7 @@ def remove_background(image):
66
  raise gr.Error("Please upload an image.")
67
 
68
  image_ori = Image.fromarray(image).convert('RGB')
 
69
 
70
  # Preprocess the image
71
  image_preprocessor = ImagePreprocessor(resolution=(1024, 1024))
@@ -79,8 +80,9 @@ def remove_background(image):
79
 
80
  # Show Results
81
  pred_pil = transforms.ToPILImage()(pred)
 
82
  image_masked = refine_foreground(image_ori, pred_pil)
83
- image_masked.putalpha(pred_pil.resize(image_ori.size))
84
 
85
  torch.cuda.empty_cache()
86
 
@@ -99,6 +101,13 @@ 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,
@@ -106,24 +115,23 @@ body {
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(
@@ -133,8 +141,6 @@ iface = gr.Interface(
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
  )
 
66
  raise gr.Error("Please upload an image.")
67
 
68
  image_ori = Image.fromarray(image).convert('RGB')
69
+ original_size = image_ori.size
70
 
71
  # Preprocess the image
72
  image_preprocessor = ImagePreprocessor(resolution=(1024, 1024))
 
80
 
81
  # Show Results
82
  pred_pil = transforms.ToPILImage()(pred)
83
+ pred_pil = pred_pil.resize(original_size, Image.BICUBIC) # Resize mask to original size
84
  image_masked = refine_foreground(image_ori, pred_pil)
85
+ image_masked.putalpha(pred_pil)
86
 
87
  torch.cuda.empty_cache()
88
 
 
101
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
102
  }
103
  .gradio-container {
104
+ background: white;
105
+ }
106
+ .gradio-button {
107
+ font-family: inherit;
108
+ font-size: 16px;
109
+ font-weight: bold;
110
+ color: #000000;
111
  background: linear-gradient(
112
  135deg,
113
  #e0f7fa, #e8f5e9, #fff9c4, #ffebee,
 
115
  );
116
  background-size: 400% 400%;
117
  animation: gradient-animation 15s ease infinite;
118
+ border: 2px solid black;
119
+ border-radius: 10px;
120
+ }
121
+ .gradio-button:hover {
122
+ background: linear-gradient(
123
+ 135deg,
124
+ #b2ebf2, #c8e6c9, #fff176, #ffcdd2,
125
+ #e1bee7, #b3e5fc, #ffe0b2, #c5cae9
126
+ );
127
+ background-size: 400% 400%;
128
+ animation: gradient-animation 15s ease infinite;
129
  }
130
  @keyframes gradient-animation {
131
  0% { background-position: 0% 50%; }
132
  50% { background-position: 100% 50%; }
133
  100% { background-position: 0% 50%; }
134
  }
 
 
 
 
 
 
 
 
 
 
 
 
135
  """
136
 
137
  iface = gr.Interface(
 
141
  gr.Image(type="filepath", label="Mask"),
142
  gr.Image(type="filepath", label="Output")
143
  ],
 
 
144
  allow_flagging="never",
145
  css=css
146
  )