Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -111,156 +111,6 @@ def remove_background(image):
|
|
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;
|
141 |
-
}
|
142 |
-
.gradio-container {
|
143 |
-
background: white;
|
144 |
-
}
|
145 |
-
#component-0 button {
|
146 |
-
font-family: inherit !important;
|
147 |
-
font-size: 16px !important;
|
148 |
-
font-weight: bold !important;
|
149 |
-
color: #000000 !important;
|
150 |
-
background: linear-gradient(
|
151 |
-
135deg,
|
152 |
-
#e0f7fa, #e8f5e9, #fff9c4, #ffebee,
|
153 |
-
#f3e5f5, #e1f5fe, #fff3e0, #e8eaf6
|
154 |
-
) !important;
|
155 |
-
background-size: 400% 400% !important;
|
156 |
-
animation: gradient-animation 15s ease infinite !important;
|
157 |
-
border: 2px solid black !important;
|
158 |
-
border-radius: 10px !important;
|
159 |
-
}
|
160 |
-
#component-0 button:hover {
|
161 |
-
background: linear-gradient(
|
162 |
-
135deg,
|
163 |
-
#b2ebf2, #c8e6c9, #fff176, #ffcdd2,
|
164 |
-
#e1bee7, #b3e5fc, #ffe0b2, #c5cae9
|
165 |
-
) !important;
|
166 |
-
background-size: 400% 400% !important;
|
167 |
-
animation: gradient-animation 15s ease infinite !important;
|
168 |
-
}
|
169 |
-
@keyframes gradient-animation {
|
170 |
-
0% { background-position: 0% 50%; }
|
171 |
-
50% { background-position: 100% 50%; }
|
172 |
-
100% { background-position: 0% 50%; }
|
173 |
-
}
|
174 |
-
footer {
|
175 |
-
text-align: center;
|
176 |
-
margin-top: 20px;
|
177 |
-
}
|
178 |
-
.license-link {
|
179 |
-
color: #007bff;
|
180 |
-
text-decoration: none;
|
181 |
-
cursor: pointer;
|
182 |
-
}
|
183 |
-
.license-link:hover {
|
184 |
-
text-decoration: underline;
|
185 |
-
}
|
186 |
-
.modal {
|
187 |
-
display: none;
|
188 |
-
position: fixed;
|
189 |
-
z-index: 1000;
|
190 |
-
left: 0;
|
191 |
-
top: 0;
|
192 |
-
width: 100%;
|
193 |
-
height: 100%;
|
194 |
-
overflow: auto;
|
195 |
-
background-color: rgba(0,0,0,0.4);
|
196 |
-
}
|
197 |
-
.modal-content {
|
198 |
-
background-color: #fefefe;
|
199 |
-
margin: 15% auto;
|
200 |
-
padding: 20px;
|
201 |
-
border: 1px solid #888;
|
202 |
-
width: 80%;
|
203 |
-
max-width: 600px;
|
204 |
-
}
|
205 |
-
.close {
|
206 |
-
color: #aaa;
|
207 |
-
float: right;
|
208 |
-
font-size: 28px;
|
209 |
-
font-weight: bold;
|
210 |
-
}
|
211 |
-
.close:hover,
|
212 |
-
.close:focus {
|
213 |
-
color: black;
|
214 |
-
text-decoration: none;
|
215 |
-
cursor: pointer;
|
216 |
-
}
|
217 |
-
"""
|
218 |
-
|
219 |
-
js = """
|
220 |
-
function setupLicenseModal() {
|
221 |
-
var modal = document.createElement('div');
|
222 |
-
modal.className = 'modal';
|
223 |
-
modal.innerHTML = `
|
224 |
-
<div class="modal-content">
|
225 |
-
<span class="close">×</span>
|
226 |
-
<h2>License</h2>
|
227 |
-
<pre>${license_text}</pre>
|
228 |
-
</div>
|
229 |
-
`;
|
230 |
-
document.body.appendChild(modal);
|
231 |
-
|
232 |
-
var link = document.createElement('a');
|
233 |
-
link.href = '#';
|
234 |
-
link.className = 'license-link';
|
235 |
-
link.textContent = 'License';
|
236 |
-
link.onclick = function(e) {
|
237 |
-
e.preventDefault();
|
238 |
-
modal.style.display = 'block';
|
239 |
-
};
|
240 |
-
|
241 |
-
var footer = document.createElement('footer');
|
242 |
-
footer.appendChild(link);
|
243 |
-
document.body.appendChild(footer);
|
244 |
-
|
245 |
-
var span = modal.querySelector('.close');
|
246 |
-
span.onclick = function() {
|
247 |
-
modal.style.display = 'none';
|
248 |
-
};
|
249 |
-
|
250 |
-
window.onclick = function(event) {
|
251 |
-
if (event.target == modal) {
|
252 |
-
modal.style.display = 'none';
|
253 |
-
}
|
254 |
-
};
|
255 |
-
}
|
256 |
-
|
257 |
-
if (window.gradio_config.version.startsWith('3')) {
|
258 |
-
setupLicenseModal();
|
259 |
-
} else {
|
260 |
-
document.addEventListener('DOMContentLoaded', setupLicenseModal);
|
261 |
-
}
|
262 |
-
"""
|
263 |
-
|
264 |
iface = gr.Interface(
|
265 |
fn=remove_background,
|
266 |
inputs=gr.Image(type="numpy"),
|
@@ -270,10 +120,7 @@ iface = gr.Interface(
|
|
270 |
gr.Image(type="filepath", label="Foreground"),
|
271 |
gr.Image(type="filepath", label="Background")
|
272 |
],
|
273 |
-
allow_flagging="never"
|
274 |
-
css=css,
|
275 |
-
js=js,
|
276 |
-
elem_id="remove-background"
|
277 |
)
|
278 |
|
279 |
if __name__ == "__main__":
|
|
|
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 |
gr.Image(type="filepath", label="Foreground"),
|
121 |
gr.Image(type="filepath", label="Background")
|
122 |
],
|
123 |
+
allow_flagging="never"
|
|
|
|
|
|
|
124 |
)
|
125 |
|
126 |
if __name__ == "__main__":
|