videopix commited on
Commit
490a080
·
verified ·
1 Parent(s): d37a6e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +164 -63
app.py CHANGED
@@ -147,69 +147,170 @@ async def favicon():
147
  @app.get("/", response_class=HTMLResponse)
148
  async def index():
149
  return """
150
- <!DOCTYPE html>
151
- <html>
152
- <head>
153
- <title>Background Remover API Tester</title>
154
- <style>
155
- body { font-family: Arial; padding: 20px; }
156
- img { max-width: 100%; margin-top: 20px; border-radius: 10px; }
157
- </style>
158
- </head>
159
- <body>
160
- <h2>Background Remover API Test (POST)</h2>
161
-
162
- <h4>Upload Image</h4>
163
- <form id="uploadForm" enctype="multipart/form-data">
164
- <input type="file" id="file" name="file"><br><br>
165
- <label>Resolution:</label>
166
- <input type="number" id="resFile" value="512"><br><br>
167
- <button type="submit">Remove Background</button>
168
- </form>
169
-
170
- <h4>Or use Image URL</h4>
171
- <form id="urlForm">
172
- <input type="text" id="imgUrl" placeholder="https://example.com/image.jpg" size="50"><br><br>
173
- <label>Resolution:</label>
174
- <input type="number" id="resUrl" value="512"><br><br>
175
- <button type="submit">Remove Background</button>
176
- </form>
177
-
178
- <h3>Result:</h3>
179
- <img id="result" />
180
-
181
- <script>
182
- const resultImg = document.getElementById("result");
183
-
184
- document.getElementById("uploadForm").onsubmit = async (e) => {
185
- e.preventDefault();
186
- const file = document.getElementById("file").files[0];
187
- const res = document.getElementById("resFile").value;
188
-
189
- const fd = new FormData();
190
- fd.append("file", file);
191
- fd.append("resolution", res);
192
-
193
- const r = await fetch("/remove-background", { method: "POST", body: fd });
194
- resultImg.src = URL.createObjectURL(await r.blob());
195
- };
196
-
197
- document.getElementById("urlForm").onsubmit = async (e) => {
198
- e.preventDefault();
199
- const url = document.getElementById("imgUrl").value;
200
- const res = document.getElementById("resUrl").value;
201
-
202
- const fd = new FormData();
203
- fd.append("image_url", url);
204
- fd.append("resolution", res);
205
-
206
- const r = await fetch("/remove-background", { method: "POST", body: fd });
207
- resultImg.src = URL.createObjectURL(await r.blob());
208
- };
209
- </script>
210
- </body>
211
- </html>
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