Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -111,6 +111,159 @@ def remove_background(image):
|
|
111 |
|
112 |
return mask_path, reverse_mask_path, foreground_path, background_path
|
113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
iface = gr.Interface(
|
115 |
fn=remove_background,
|
116 |
inputs=gr.Image(type="numpy"),
|
@@ -120,7 +273,10 @@ iface = gr.Interface(
|
|
120 |
gr.Image(type="filepath", label="Foreground"),
|
121 |
gr.Image(type="filepath", label="Background")
|
122 |
],
|
123 |
-
allow_flagging="never"
|
|
|
|
|
|
|
124 |
)
|
125 |
|
126 |
if __name__ == "__main__":
|
|
|
111 |
|
112 |
return mask_path, reverse_mask_path, foreground_path, background_path
|
113 |
|
114 |
+
license_text = """
|
115 |
+
MIT License
|
116 |
+
|
117 |
+
Copyright (c) 2024 ZhengPeng
|
118 |
+
|
119 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
120 |
+
of this software and associated documentation files (the "Software"), to deal
|
121 |
+
in the Software without restriction, including without limitation the rights
|
122 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
123 |
+
copies of the Software, and to permit persons to whom the Software is
|
124 |
+
furnished to do so, subject to the following conditions:
|
125 |
+
|
126 |
+
The above copyright notice and this permission notice shall be included in all
|
127 |
+
copies or substantial portions of the Software.
|
128 |
+
|
129 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
130 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
131 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
132 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
133 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
134 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
135 |
+
SOFTWARE.
|
136 |
+
"""
|
137 |
+
|
138 |
+
css = """
|
139 |
+
body {
|
140 |
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
141 |
+
}
|
142 |
+
.gradio-container {
|
143 |
+
background: white;
|
144 |
+
}
|
145 |
+
#component-0 {
|
146 |
+
max-width: 100% !important;
|
147 |
+
}
|
148 |
+
.remove-background {
|
149 |
+
font-family: inherit !important;
|
150 |
+
font-size: 16px !important;
|
151 |
+
font-weight: bold !important;
|
152 |
+
color: #000000 !important;
|
153 |
+
background: linear-gradient(
|
154 |
+
135deg,
|
155 |
+
#e0f7fa, #e8f5e9, #fff9c4, #ffebee,
|
156 |
+
#f3e5f5, #e1f5fe, #fff3e0, #e8eaf6
|
157 |
+
) !important;
|
158 |
+
background-size: 400% 400% !important;
|
159 |
+
animation: gradient-animation 15s ease infinite !important;
|
160 |
+
border: 2px solid black !important;
|
161 |
+
border-radius: 10px !important;
|
162 |
+
}
|
163 |
+
.remove-background:hover {
|
164 |
+
background: linear-gradient(
|
165 |
+
135deg,
|
166 |
+
#b2ebf2, #c8e6c9, #fff176, #ffcdd2,
|
167 |
+
#e1bee7, #b3e5fc, #ffe0b2, #c5cae9
|
168 |
+
) !important;
|
169 |
+
background-size: 400% 400% !important;
|
170 |
+
animation: gradient-animation 15s ease infinite !important;
|
171 |
+
}
|
172 |
+
@keyframes gradient-animation {
|
173 |
+
0% { background-position: 0% 50%; }
|
174 |
+
50% { background-position: 100% 50%; }
|
175 |
+
100% { background-position: 0% 50%; }
|
176 |
+
}
|
177 |
+
footer {
|
178 |
+
text-align: center;
|
179 |
+
margin-top: 20px;
|
180 |
+
}
|
181 |
+
.license-link {
|
182 |
+
color: #007bff;
|
183 |
+
text-decoration: none;
|
184 |
+
cursor: pointer;
|
185 |
+
}
|
186 |
+
.license-link:hover {
|
187 |
+
text-decoration: underline;
|
188 |
+
}
|
189 |
+
.modal {
|
190 |
+
display: none;
|
191 |
+
position: fixed;
|
192 |
+
z-index: 1000;
|
193 |
+
left: 0;
|
194 |
+
top: 0;
|
195 |
+
width: 100%;
|
196 |
+
height: 100%;
|
197 |
+
overflow: auto;
|
198 |
+
background-color: rgba(0,0,0,0.4);
|
199 |
+
}
|
200 |
+
.modal-content {
|
201 |
+
background-color: #fefefe;
|
202 |
+
margin: 15% auto;
|
203 |
+
padding: 20px;
|
204 |
+
border: 1px solid #888;
|
205 |
+
width: 80%;
|
206 |
+
max-width: 600px;
|
207 |
+
}
|
208 |
+
.close {
|
209 |
+
color: #aaa;
|
210 |
+
float: right;
|
211 |
+
font-size: 28px;
|
212 |
+
font-weight: bold;
|
213 |
+
}
|
214 |
+
.close:hover,
|
215 |
+
.close:focus {
|
216 |
+
color: black;
|
217 |
+
text-decoration: none;
|
218 |
+
cursor: pointer;
|
219 |
+
}
|
220 |
+
"""
|
221 |
+
|
222 |
+
js = """
|
223 |
+
function setupLicenseModal() {
|
224 |
+
var modal = document.createElement('div');
|
225 |
+
modal.className = 'modal';
|
226 |
+
modal.innerHTML = `
|
227 |
+
<div class="modal-content">
|
228 |
+
<span class="close">×</span>
|
229 |
+
<h2>License</h2>
|
230 |
+
<pre>${license_text}</pre>
|
231 |
+
</div>
|
232 |
+
`;
|
233 |
+
document.body.appendChild(modal);
|
234 |
+
|
235 |
+
var link = document.createElement('a');
|
236 |
+
link.href = '#';
|
237 |
+
link.className = 'license-link';
|
238 |
+
link.textContent = 'License';
|
239 |
+
link.onclick = function(e) {
|
240 |
+
e.preventDefault();
|
241 |
+
modal.style.display = 'block';
|
242 |
+
};
|
243 |
+
|
244 |
+
var footer = document.createElement('footer');
|
245 |
+
footer.appendChild(link);
|
246 |
+
document.body.appendChild(footer);
|
247 |
+
|
248 |
+
var span = modal.querySelector('.close');
|
249 |
+
span.onclick = function() {
|
250 |
+
modal.style.display = 'none';
|
251 |
+
};
|
252 |
+
|
253 |
+
window.onclick = function(event) {
|
254 |
+
if (event.target == modal) {
|
255 |
+
modal.style.display = 'none';
|
256 |
+
}
|
257 |
+
};
|
258 |
+
}
|
259 |
+
|
260 |
+
if (window.gradio_config.version.startsWith('3')) {
|
261 |
+
setupLicenseModal();
|
262 |
+
} else {
|
263 |
+
document.addEventListener('DOMContentLoaded', setupLicenseModal);
|
264 |
+
}
|
265 |
+
"""
|
266 |
+
|
267 |
iface = gr.Interface(
|
268 |
fn=remove_background,
|
269 |
inputs=gr.Image(type="numpy"),
|
|
|
273 |
gr.Image(type="filepath", label="Foreground"),
|
274 |
gr.Image(type="filepath", label="Background")
|
275 |
],
|
276 |
+
allow_flagging="never",
|
277 |
+
css=css,
|
278 |
+
js=js,
|
279 |
+
elem_classes={"submit": "remove-background"}
|
280 |
)
|
281 |
|
282 |
if __name__ == "__main__":
|