Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -147,69 +147,170 @@ async def favicon():
|
|
| 147 |
@app.get("/", response_class=HTMLResponse)
|
| 148 |
async def index():
|
| 149 |
return """
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
|
| 214 |
# ---------------------------------------------------------
|
| 215 |
# Run App
|
|
|
|
| 147 |
@app.get("/", response_class=HTMLResponse)
|
| 148 |
async def index():
|
| 149 |
return """
|
| 150 |
+
<!DOCTYPE html>
|
| 151 |
+
<html>
|
| 152 |
+
<head>
|
| 153 |
+
<title>Background Remover API</title>
|
| 154 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 155 |
+
|
| 156 |
+
<style>
|
| 157 |
+
body {
|
| 158 |
+
font-family: Arial, sans-serif;
|
| 159 |
+
padding: 20px;
|
| 160 |
+
margin: 0;
|
| 161 |
+
background: #f5f5f5;
|
| 162 |
+
}
|
| 163 |
+
h2 {
|
| 164 |
+
text-align: center;
|
| 165 |
+
margin-bottom: 25px;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.container {
|
| 169 |
+
max-width: 700px;
|
| 170 |
+
margin: auto;
|
| 171 |
+
background: white;
|
| 172 |
+
padding: 25px;
|
| 173 |
+
border-radius: 12px;
|
| 174 |
+
box-shadow: 0 4px 10px rgba(0,0,0,0.1);
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
.section {
|
| 178 |
+
margin-bottom: 30px;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
label {
|
| 182 |
+
font-weight: bold;
|
| 183 |
+
}
|
| 184 |
+
|
| 185 |
+
input[type="file"],
|
| 186 |
+
input[type="text"],
|
| 187 |
+
input[type="number"] {
|
| 188 |
+
width: 100%;
|
| 189 |
+
padding: 10px;
|
| 190 |
+
margin-top: 6px;
|
| 191 |
+
border-radius: 6px;
|
| 192 |
+
border: 1px solid #ccc;
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
button {
|
| 196 |
+
padding: 12px 18px;
|
| 197 |
+
margin-top: 12px;
|
| 198 |
+
width: 100%;
|
| 199 |
+
border: none;
|
| 200 |
+
background: #007bff;
|
| 201 |
+
color: white;
|
| 202 |
+
border-radius: 6px;
|
| 203 |
+
cursor: pointer;
|
| 204 |
+
font-size: 16px;
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
button:hover {
|
| 208 |
+
background: #005dc4;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
#resultWrapper {
|
| 212 |
+
text-align: center;
|
| 213 |
+
margin-top: 20px;
|
| 214 |
+
}
|
| 215 |
+
|
| 216 |
+
img {
|
| 217 |
+
max-width: 100%;
|
| 218 |
+
border-radius: 10px;
|
| 219 |
+
margin-top: 15px;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
/* Responsive fixes */
|
| 223 |
+
@media (max-width: 600px) {
|
| 224 |
+
.container {
|
| 225 |
+
padding: 15px;
|
| 226 |
+
}
|
| 227 |
+
button {
|
| 228 |
+
font-size: 15px;
|
| 229 |
+
}
|
| 230 |
+
}
|
| 231 |
+
</style>
|
| 232 |
+
|
| 233 |
+
</head>
|
| 234 |
+
<body>
|
| 235 |
+
|
| 236 |
+
<h2>Background Remover API Tester</h2>
|
| 237 |
+
|
| 238 |
+
<div class="container">
|
| 239 |
+
|
| 240 |
+
<!-- Upload Section -->
|
| 241 |
+
<div class="section">
|
| 242 |
+
<label>Upload Image</label>
|
| 243 |
+
<form id="uploadForm" enctype="multipart/form-data">
|
| 244 |
+
<input type="file" id="file" name="file" accept="image/*">
|
| 245 |
+
|
| 246 |
+
<label>Resolution</label>
|
| 247 |
+
<input type="number" id="resFile" value="512" min="64" max="2048">
|
| 248 |
+
|
| 249 |
+
<button type="submit">Remove Background</button>
|
| 250 |
+
</form>
|
| 251 |
+
</div>
|
| 252 |
+
|
| 253 |
+
<hr>
|
| 254 |
+
|
| 255 |
+
<!-- URL Section -->
|
| 256 |
+
<div class="section">
|
| 257 |
+
<label>Image URL</label>
|
| 258 |
+
<form id="urlForm">
|
| 259 |
+
<input type="text" id="imgUrl" placeholder="https://example.com/image.jpg">
|
| 260 |
+
|
| 261 |
+
<label>Resolution</label>
|
| 262 |
+
<input type="number" id="resUrl" value="512" min="64" max="2048">
|
| 263 |
+
|
| 264 |
+
<button type="submit">Remove Background</button>
|
| 265 |
+
</form>
|
| 266 |
+
</div>
|
| 267 |
+
|
| 268 |
+
<div id="resultWrapper">
|
| 269 |
+
<h3>Result</h3>
|
| 270 |
+
<img id="result" />
|
| 271 |
+
</div>
|
| 272 |
+
|
| 273 |
+
</div>
|
| 274 |
+
|
| 275 |
+
<script>
|
| 276 |
+
const resultImg = document.getElementById("result");
|
| 277 |
+
|
| 278 |
+
// Upload File
|
| 279 |
+
document.getElementById("uploadForm").onsubmit = async (e) => {
|
| 280 |
+
e.preventDefault();
|
| 281 |
+
const file = document.getElementById("file").files[0];
|
| 282 |
+
const res = document.getElementById("resFile").value;
|
| 283 |
+
|
| 284 |
+
if (!file) return alert("Please select a file");
|
| 285 |
+
|
| 286 |
+
const fd = new FormData();
|
| 287 |
+
fd.append("file", file);
|
| 288 |
+
fd.append("resolution", res);
|
| 289 |
+
|
| 290 |
+
const r = await fetch("/remove-background", { method: "POST", body: fd });
|
| 291 |
+
resultImg.src = URL.createObjectURL(await r.blob());
|
| 292 |
+
};
|
| 293 |
+
|
| 294 |
+
// URL Mode
|
| 295 |
+
document.getElementById("urlForm").onsubmit = async (e) => {
|
| 296 |
+
e.preventDefault();
|
| 297 |
+
const url = document.getElementById("imgUrl").value;
|
| 298 |
+
const res = document.getElementById("resUrl").value;
|
| 299 |
+
|
| 300 |
+
if (!url.trim()) return alert("Please enter an image URL");
|
| 301 |
+
|
| 302 |
+
const fd = new FormData();
|
| 303 |
+
fd.append("image_url", url);
|
| 304 |
+
fd.append("resolution", res);
|
| 305 |
+
|
| 306 |
+
const r = await fetch("/remove-background", { method: "POST", body: fd });
|
| 307 |
+
resultImg.src = URL.createObjectURL(await r.blob());
|
| 308 |
+
};
|
| 309 |
+
</script>
|
| 310 |
+
|
| 311 |
+
</body>
|
| 312 |
+
</html>
|
| 313 |
+
"""
|
| 314 |
|
| 315 |
# ---------------------------------------------------------
|
| 316 |
# Run App
|