|
@@ -9,331 +9,465 @@
|
|
|
<script src="https://unpkg.com/xlsx/dist/xlsx.full.min.js"></script>
|
|
<script src="https://unpkg.com/xlsx/dist/xlsx.full.min.js"></script>
|
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource/source-sans-3@5.0.12/index.css"
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource/source-sans-3@5.0.12/index.css"
|
|
|
integrity="sha256-tXJfXfp6Ewt1ilPzLDtQnJV4hclT9XuaZUKyUvmyr+Q=" crossorigin="anonymous">
|
|
integrity="sha256-tXJfXfp6Ewt1ilPzLDtQnJV4hclT9XuaZUKyUvmyr+Q=" crossorigin="anonymous">
|
|
|
- <!--end::Fonts--><!--begin::Third Party Plugin(OverlayScrollbars)-->
|
|
|
|
|
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/overlayscrollbars@2.3.0/styles/overlayscrollbars.min.css"
|
|
|
|
|
|
|
+<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/overlayscrollbars@2.3.0/styles/overlayscrollbars.min.css"
|
|
|
integrity="sha256-dSokZseQNT08wYEWiz5iLI8QPlKxG+TswNRD8k35cpg=" crossorigin="anonymous">
|
|
integrity="sha256-dSokZseQNT08wYEWiz5iLI8QPlKxG+TswNRD8k35cpg=" crossorigin="anonymous">
|
|
|
- <!--end::Third Party Plugin(OverlayScrollbars)--><!--begin::Third Party Plugin(Bootstrap Icons)-->
|
|
|
|
|
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.min.css"
|
|
|
|
|
|
|
+<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.min.css"
|
|
|
integrity="sha256-Qsx5lrStHZyR9REqhUF8iQt73X06c8LGIUPzpOhwRrI=" crossorigin="anonymous">
|
|
integrity="sha256-Qsx5lrStHZyR9REqhUF8iQt73X06c8LGIUPzpOhwRrI=" crossorigin="anonymous">
|
|
|
- <!--end::Third Party Plugin(Bootstrap Icons)--><!--begin::Required Plugin(AdminLTE)-->
|
|
|
|
|
- <link rel="stylesheet" href="{% static './css/adminlte.css' %}"><!--end::Required Plugin(AdminLTE)--><!-- apexcharts -->
|
|
|
|
|
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/apexcharts@3.37.1/dist/apexcharts.css"
|
|
|
|
|
|
|
+<link rel="stylesheet" href="{% static './css/adminlte.css' %}">
|
|
|
|
|
+<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/apexcharts@3.37.1/dist/apexcharts.css"
|
|
|
integrity="sha256-4MX+61mt9NVvvuPjUWdUdyfZfxSB1/Rf9WtqRHgG5S0=" crossorigin="anonymous">
|
|
integrity="sha256-4MX+61mt9NVvvuPjUWdUdyfZfxSB1/Rf9WtqRHgG5S0=" crossorigin="anonymous">
|
|
|
- <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
|
|
|
|
|
- <link rel="stylesheet" href="{% static './css/select2-bootstrap4.min.css' %}">
|
|
|
|
|
- <link rel="stylesheet" href="{% static './css/custom.css' %}">
|
|
|
|
|
- <script src="https://cdn.tailwindcss.com"></script>
|
|
|
|
|
- <!-- <link href="https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;600;800&display=swap" rel="stylesheet"> -->
|
|
|
|
|
- <style>
|
|
|
|
|
- .bg-remover-container .nav-pills .nav-link { color: #64748b; font-weight: 600; border-radius: 12px; padding: 10px 25px; transition: all 0.3s; border: none; background: none; }
|
|
|
|
|
- .bg-remover-container .nav-pills .nav-link.active { background-color: #3b82f6 !important; color: white !important; box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3); }
|
|
|
|
|
- .bg-remover-container .upload-card { transition: all 0.3s ease; border: 2px dashed #cbd5e1; background: #ffffff; }
|
|
|
|
|
- .upload-card:hover { border-color: #3b82f6; background-color: #f8fafc; transform: translateY(-2px); }
|
|
|
|
|
- .preview-box { background: #ffffff; border-radius: 12px; padding: 15px; box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1); }
|
|
|
|
|
- .checkerboard-bg {
|
|
|
|
|
- background-image: linear-gradient(45deg, #eee 25%, transparent 25%), linear-gradient(-45deg, #eee 25%, transparent 25%),
|
|
|
|
|
- linear-gradient(45deg, transparent 75%, #eee 75%), linear-gradient(-45deg, transparent 75%, #eee 75%);
|
|
|
|
|
- background-size: 20px 20px; background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
|
|
|
|
|
- }
|
|
|
|
|
- </style>
|
|
|
|
|
|
|
+<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
|
|
|
|
|
+<link rel="stylesheet" href="{% static './css/select2-bootstrap4.min.css' %}">
|
|
|
|
|
+<link rel="stylesheet" href="{% static './css/custom.css' %}">
|
|
|
|
|
+<script src="https://cdn.tailwindcss.com"></script>
|
|
|
|
|
+
|
|
|
|
|
+<style>
|
|
|
|
|
+ .bg-remover-container .nav-pills .nav-link { color: #64748b; font-weight: 600; border-radius: 12px; padding: 10px 25px; transition: all 0.3s; border: none; background: none; }
|
|
|
|
|
+ .bg-remover-container .nav-pills .nav-link.active { background-color: #3b82f6 !important; color: white !important; box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3); }
|
|
|
|
|
+ .bg-remover-container .upload-card { transition: all 0.3s ease; border: 2px dashed #cbd5e1; background: #ffffff; }
|
|
|
|
|
+ .upload-card:hover { border-color: #3b82f6; background-color: #f8fafc; transform: translateY(-2px); }
|
|
|
|
|
+ .preview-box { background: #ffffff; border-radius: 12px; padding: 15px; box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1); }
|
|
|
|
|
+ .checkerboard-bg {
|
|
|
|
|
+ background-image: linear-gradient(45deg, #eee 25%, transparent 25%), linear-gradient(-45deg, #eee 25%, transparent 25%),
|
|
|
|
|
+ linear-gradient(45deg, transparent 75%, #eee 75%), linear-gradient(-45deg, transparent 75%, #eee 75%);
|
|
|
|
|
+ background-size: 20px 20px; background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
|
|
|
|
|
+ }
|
|
|
|
|
+</style>
|
|
|
</head>
|
|
</head>
|
|
|
|
|
|
|
|
-<!-- <body class="layout-fixed sidebar-expand-lg bg-body-tertiary"> -->
|
|
|
|
|
<body class="layout-fixed sidebar-expand-lg sidebar-mini app-loaded sidebar-collapse">
|
|
<body class="layout-fixed sidebar-expand-lg sidebar-mini app-loaded sidebar-collapse">
|
|
|
- <div class="app-wrapper">
|
|
|
|
|
- {% include 'header.html' %}
|
|
|
|
|
- {% include 'sidebar.html' %}
|
|
|
|
|
-
|
|
|
|
|
- <main class="app-main">
|
|
|
|
|
- <div class="app-content-header"> <!--begin::Container-->
|
|
|
|
|
- <div class="container-fluid"> <!--begin::Row-->
|
|
|
|
|
- <div class="row">
|
|
|
|
|
- <div class="col-sm-6">
|
|
|
|
|
- <h3 class="mb-0">🪄 Image Background Remover
|
|
|
|
|
-
|
|
|
|
|
- </h3>
|
|
|
|
|
-
|
|
|
|
|
- </div>
|
|
|
|
|
- <div class="col-sm-6">
|
|
|
|
|
- <ol class="breadcrumb float-sm-end">
|
|
|
|
|
- <li class="breadcrumb-item"><a href="{% url 'file-upload' %}">Home</a></li>
|
|
|
|
|
- <li class="breadcrumb-item active" aria-current="page"><a href="{% url 'product-attributes' %}"></a>
|
|
|
|
|
- 🪄 Image Background Remover</a>
|
|
|
|
|
- </li>
|
|
|
|
|
- </ol>
|
|
|
|
|
- </div>
|
|
|
|
|
- </div> <!--end::Row-->
|
|
|
|
|
- </div> <!--end::Container-->
|
|
|
|
|
|
|
+<div class="app-wrapper">
|
|
|
|
|
+ {% include 'header.html' %}
|
|
|
|
|
+ {% include 'sidebar.html' %}
|
|
|
|
|
+
|
|
|
|
|
+ <main class="app-main">
|
|
|
|
|
+ <div class="app-content-header">
|
|
|
|
|
+ <div class="container-fluid">
|
|
|
|
|
+ <div class="row">
|
|
|
|
|
+ <div class="col-sm-6">
|
|
|
|
|
+ <h3 class="mb-0">🪄 Image Background Remover</h3>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div class="col-sm-6">
|
|
|
|
|
+ <ol class="breadcrumb float-sm-end">
|
|
|
|
|
+ <li class="breadcrumb-item"><a href="{% url 'file-upload' %}">Home</a></li>
|
|
|
|
|
+ <li class="breadcrumb-item active" aria-current="page"><a href="{% url 'product-attributes' %}"></a>
|
|
|
|
|
+ 🪄 Image Background Remover</a>
|
|
|
|
|
+ </li>
|
|
|
|
|
+ </ol>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
- <div class="app-content pt-10 bg-remover-container">
|
|
|
|
|
- <div class=" mx-auto px-4">
|
|
|
|
|
- <div class="mb-10 flex flex-col md:flex-row md:items-end md:justify-between gap-4 border-b border-gray-100 pb-6">
|
|
|
|
|
- <div class="text-left">
|
|
|
|
|
- <h1 class="text-4xl font-black text-gray-900 tracking-tight mb-2">
|
|
|
|
|
- Image <span class="text-blue-600">Background</span> Remover
|
|
|
|
|
- </h1>
|
|
|
|
|
- <p class="text-gray-500 font-medium ">
|
|
|
|
|
- Professional-grade background removal. Process single images or
|
|
|
|
|
- <span class="text-gray-800 font-semibold">batch process ZIP archives </span> instantly.
|
|
|
|
|
- </p>
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ </div>
|
|
|
|
|
|
|
|
- <div class="flex items-center">
|
|
|
|
|
- <a href="/bg-remover/tasks/history/"
|
|
|
|
|
- class="inline-flex items-center gap-2 px-5 py-2.5 bg-white border border-gray-200 text-gray-700 text-sm font-bold rounded-xl shadow-sm hover:shadow-md hover:border-blue-300 hover:text-blue-600 transition-all duration-200 group">
|
|
|
|
|
- <i class="bi bi-clock-history text-gray-400 group-hover:text-blue-500 transition-colors"></i>
|
|
|
|
|
- Task History
|
|
|
|
|
- <span class="flex h-2 w-2 rounded-full bg-blue-500 ml-1"></span>
|
|
|
|
|
- </a>
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ <div class="app-content pt-10 bg-remover-container">
|
|
|
|
|
+ <div class="mx-auto px-4">
|
|
|
|
|
+ <div class="mb-10 flex flex-col md:flex-row md:items-end md:justify-between gap-4 border-b border-gray-100 pb-6">
|
|
|
|
|
+ <div class="text-left">
|
|
|
|
|
+ <h1 class="text-4xl font-black text-gray-900 tracking-tight mb-2">
|
|
|
|
|
+ Image <span class="text-blue-600">Background</span> Remover
|
|
|
|
|
+ </h1>
|
|
|
|
|
+ <p class="text-gray-500 font-medium ">
|
|
|
|
|
+ Professional-grade background removal. Process single images or
|
|
|
|
|
+ <span class="text-gray-800 font-semibold">batch process ZIP archives </span> instantly.
|
|
|
|
|
+ </p>
|
|
|
</div>
|
|
</div>
|
|
|
- <!-- <div class="text-center mb-8">
|
|
|
|
|
- <h1 class="text-4xl font-extrabold text-gray-900 mb-2">AI Background Remover</h1>
|
|
|
|
|
- <p class="text-gray-500 font-medium">Remove image backgrounds instantly for single images, bulk uploads, or ZIP files.</p>
|
|
|
|
|
- <div class="flex justify-end mb-4">
|
|
|
|
|
- <a href="/bg-remover/tasks/history/"
|
|
|
|
|
- class="flex items-center gap-2 px-6 py-2.5 bg-white border border-gray-200 text-gray-700 font-bold rounded-xl shadow-sm hover:bg-gray-50 hover:border-blue-400 transition-all">
|
|
|
|
|
- <i class="bi bi-clock-history text-blue-600"></i>
|
|
|
|
|
- View Task History
|
|
|
|
|
- </a>
|
|
|
|
|
- </div>
|
|
|
|
|
- </div> -->
|
|
|
|
|
-
|
|
|
|
|
- <ul class="nav nav-pills justify-content-center mb-8 gap-3" id="pills-tab" role="tablist">
|
|
|
|
|
- <li class="nav-item" role="presentation">
|
|
|
|
|
- <button class="nav-link active" id="pills-single-tab" data-bs-toggle="pill" data-bs-target="#pills-single" type="button" role="tab">
|
|
|
|
|
- <i class="bi bi-image mr-2"></i> Single Image
|
|
|
|
|
- </button>
|
|
|
|
|
- </li>
|
|
|
|
|
- <li class="nav-item" role="presentation">
|
|
|
|
|
- <button class="nav-link" id="pills-bulk-tab" data-bs-toggle="pill" data-bs-target="#pills-bulk" type="button" role="tab">
|
|
|
|
|
- <i class="bi bi-images mr-2"></i> Bulk & ZIP Process
|
|
|
|
|
- </button>
|
|
|
|
|
- </li>
|
|
|
|
|
- </ul>
|
|
|
|
|
-
|
|
|
|
|
- <div class="tab-content" id="pills-tabContent">
|
|
|
|
|
- <div class="tab-pane fade show active" id="pills-single" role="tabpanel">
|
|
|
|
|
- <div id="uploadContainer" class="bg-white p-8 rounded-3xl shadow-sm border border-gray-200 mb-8">
|
|
|
|
|
- <div id="drop-zone" class="upload-card flex flex-col items-center justify-center rounded-2xl p-12 cursor-pointer" onclick="document.getElementById('file-input').click()">
|
|
|
|
|
- <input type="file" id="file-input" class="hidden" accept="image/*">
|
|
|
|
|
- <div class="bg-blue-50 p-5 rounded-full mb-4 text-blue-600">
|
|
|
|
|
- <i class="bi bi-cloud-arrow-up text-4xl"></i>
|
|
|
|
|
- </div>
|
|
|
|
|
- <p class="text-lg font-semibold text-gray-700">Click or Drag & Drop Image</p>
|
|
|
|
|
- <p class="text-sm text-gray-400 mt-1">Supports PNG, JPG, WEBP</p>
|
|
|
|
|
|
|
+
|
|
|
|
|
+ <div class="flex items-center">
|
|
|
|
|
+ <a href="/bg-remover/tasks/history/"
|
|
|
|
|
+ class="inline-flex items-center gap-2 px-5 py-2.5 bg-white border border-gray-200 text-gray-700 text-sm font-bold rounded-xl shadow-sm hover:shadow-md hover:border-blue-300 hover:text-blue-600 transition-all duration-200 group">
|
|
|
|
|
+ <i class="bi bi-clock-history text-gray-400 group-hover:text-blue-500 transition-colors"></i>
|
|
|
|
|
+ Task History
|
|
|
|
|
+ <span class="flex h-2 w-2 rounded-full bg-blue-500 ml-1"></span>
|
|
|
|
|
+ </a>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <ul class="nav nav-pills justify-content-center mb-8 gap-3" id="pills-tab" role="tablist">
|
|
|
|
|
+ <li class="nav-item" role="presentation">
|
|
|
|
|
+ <button class="nav-link active" id="pills-single-tab" data-bs-toggle="pill" data-bs-target="#pills-single" type="button" role="tab">
|
|
|
|
|
+ <i class="bi bi-image mr-2"></i> Single Image
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </li>
|
|
|
|
|
+ <li class="nav-item" role="presentation">
|
|
|
|
|
+ <button class="nav-link" id="pills-bulk-tab" data-bs-toggle="pill" data-bs-target="#pills-bulk" type="button" role="tab">
|
|
|
|
|
+ <i class="bi bi-images mr-2"></i> Bulk & ZIP Process
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </li>
|
|
|
|
|
+ </ul>
|
|
|
|
|
+
|
|
|
|
|
+ <div class="tab-content" id="pills-tabContent">
|
|
|
|
|
+ <!-- NEW: Choose Action -->
|
|
|
|
|
+
|
|
|
|
|
+ <!-- SINGLE IMAGE TAB -->
|
|
|
|
|
+ <div class="tab-pane fade show active" id="pills-single" role="tabpanel">
|
|
|
|
|
+ <div class="mt-6 flex justify-center gap-6">
|
|
|
|
|
+ <label class="inline-flex items-center gap-2">
|
|
|
|
|
+ <input type="radio" name="action" value="remove_bg" checked>
|
|
|
|
|
+ <span>Remove Background</span>
|
|
|
|
|
+ </label>
|
|
|
|
|
+ <label class="inline-flex items-center gap-2">
|
|
|
|
|
+ <input type="radio" name="action" value="caption">
|
|
|
|
|
+ <span>Generate Caption</span>
|
|
|
|
|
+ </label>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div id="uploadContainer" class="bg-white p-8 rounded-3xl shadow-sm border border-gray-200 mb-8">
|
|
|
|
|
+ <div id="drop-zone" class="upload-card flex flex-col items-center justify-center rounded-2xl p-12 cursor-pointer" onclick="document.getElementById('file-input').click()">
|
|
|
|
|
+ <input type="file" id="file-input" class="hidden" accept="image/*">
|
|
|
|
|
+ <div class="bg-blue-50 p-5 rounded-full mb-4 text-blue-600">
|
|
|
|
|
+ <i class="bi bi-cloud-arrow-up text-4xl"></i>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
+ <p class="text-lg font-semibold text-gray-700">Click or Drag & Drop Image</p>
|
|
|
|
|
+ <p class="text-sm text-gray-400 mt-1">Supports PNG, JPG, WEBP</p>
|
|
|
</div>
|
|
</div>
|
|
|
- <div id="result-container" class="hidden space-y-8 pb-20">
|
|
|
|
|
- <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
|
|
|
|
|
- <div class="space-y-3">
|
|
|
|
|
- <span class="text-xs font-bold uppercase text-gray-400 tracking-wider">Original</span>
|
|
|
|
|
- <div class="preview-box"><img id="original-preview" class="rounded-lg w-full h-auto object-contain max-h-[400px]"></div>
|
|
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ <!-- RESULTS -->
|
|
|
|
|
+ <div id="result-container" class="hidden space-y-8 pb-20">
|
|
|
|
|
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
|
|
|
|
|
+ <div class="space-y-3">
|
|
|
|
|
+ <span class="text-xs font-bold uppercase text-gray-400 tracking-wider">Original</span>
|
|
|
|
|
+ <div class="preview-box"><img id="original-preview" class="rounded-lg w-full h-auto object-contain max-h-[400px]"></div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div class="space-y-3">
|
|
|
|
|
+ <div class="flex justify-between items-center px-1">
|
|
|
|
|
+ <span class="text-xs font-bold uppercase text-gray-400 tracking-wider">Processed</span>
|
|
|
|
|
+ <span id="processing-badge" class="hidden animate-pulse bg-blue-100 text-blue-700 px-2 py-0.5 rounded text-[10px] font-bold">PROCESSING...</span>
|
|
|
</div>
|
|
</div>
|
|
|
- <div class="space-y-3">
|
|
|
|
|
- <div class="flex justify-between items-center px-1">
|
|
|
|
|
- <span class="text-xs font-bold uppercase text-gray-400 tracking-wider">Processed</span>
|
|
|
|
|
- <span id="processing-badge" class="hidden animate-pulse bg-blue-100 text-blue-700 px-2 py-0.5 rounded text-[10px] font-bold">PROCESSING...</span>
|
|
|
|
|
- </div>
|
|
|
|
|
- <div class="preview-box relative min-h-[200px] flex items-center justify-center checkerboard-bg rounded-lg">
|
|
|
|
|
- <div id="result-loader" class="absolute inset-0 bg-white/60 backdrop-blur-sm flex flex-col items-center justify-center rounded-lg z-10 hidden">
|
|
|
|
|
- <div class="w-10 h-10 border-4 border-blue-600 border-t-transparent rounded-full animate-spin"></div>
|
|
|
|
|
- </div>
|
|
|
|
|
- <img id="processed-preview" class="rounded-lg w-full h-auto object-contain max-h-[400px]">
|
|
|
|
|
|
|
+ <div class="preview-box relative min-h-[200px] flex items-center justify-center checkerboard-bg rounded-lg p-4">
|
|
|
|
|
+ <div id="result-loader" class="absolute inset-0 bg-white/60 backdrop-blur-sm flex flex-col items-center justify-center rounded-lg z-10 hidden">
|
|
|
|
|
+ <div class="w-10 h-10 border-4 border-blue-600 border-t-transparent rounded-full animate-spin"></div>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- Image element -->
|
|
|
|
|
+ <img id="processed-preview" class="rounded-lg w-full h-auto object-contain max-h-[400px]">
|
|
|
|
|
+
|
|
|
|
|
+ <!-- Caption element -->
|
|
|
|
|
+ <div id="caption-text" class="hidden text-center text-gray-800 font-semibold text-lg"></div>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
- <div class="flex gap-3 justify-center">
|
|
|
|
|
- <button onclick="location.reload()" class="px-6 py-2 bg-gray-100 rounded-xl font-bold hover:bg-gray-200">New Upload</button>
|
|
|
|
|
- <a id="download-btn" class="hidden px-8 py-2 bg-green-600 text-white rounded-xl font-bold shadow-lg hover:bg-green-700">Download PNG</a>
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+
|
|
|
|
|
+ <!-- <div class="space-y-3">
|
|
|
|
|
+ <div class="flex justify-between items-center px-1">
|
|
|
|
|
+ <span class="text-xs font-bold uppercase text-gray-400 tracking-wider">Processed</span>
|
|
|
|
|
+ <span id="processing-badge" class="hidden animate-pulse bg-blue-100 text-blue-700 px-2 py-0.5 rounded text-[10px] font-bold">PROCESSING...</span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div class="preview-box relative min-h-[200px] flex items-center justify-center checkerboard-bg rounded-lg">
|
|
|
|
|
+ <div id="result-loader" class="absolute inset-0 bg-white/60 backdrop-blur-sm flex flex-col items-center justify-center rounded-lg z-10 hidden">
|
|
|
|
|
+ <div class="w-10 h-10 border-4 border-blue-600 border-t-transparent rounded-full animate-spin"></div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <img id="processed-preview" class="rounded-lg w-full h-auto object-contain max-h-[400px]">
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div> -->
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- NEW CAPTION SECTION -->
|
|
|
|
|
+ <div id="caption-container" class="hidden mt-4 text-center">
|
|
|
|
|
+ <h3 class="text-lg font-semibold text-gray-700">AI Generated Caption:</h3>
|
|
|
|
|
+ <p id="caption-text-below" class="text-blue-600 font-bold text-xl mt-1"></p>
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <div class="flex gap-3 justify-center mt-4">
|
|
|
|
|
+ <button onclick="location.reload()" class="px-6 py-2 bg-gray-100 rounded-xl font-bold hover:bg-gray-200">New Upload</button>
|
|
|
|
|
+ <a id="download-btn" class="hidden px-8 py-2 bg-green-600 text-white rounded-xl font-bold shadow-lg hover:bg-green-700">Download PNG</a>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
- <div class="tab-pane fade" id="pills-bulk" role="tabpanel">
|
|
|
|
|
- <div class="bg-white p-8 rounded-3xl shadow-sm border border-gray-200 mb-8">
|
|
|
|
|
- <div id="bulk-drop-zone" class="upload-card flex flex-col items-center justify-center rounded-2xl p-12 cursor-pointer transition-all border-indigo-200" onclick="document.getElementById('bulk-file-input').click()">
|
|
|
|
|
- <input type="file" id="bulk-file-input" class="hidden" accept="image/*,.zip" multiple>
|
|
|
|
|
- <div class="bg-indigo-50 p-5 rounded-full mb-4 text-indigo-600">
|
|
|
|
|
- <i class="bi bi-file-earmark-zip text-4xl"></i>
|
|
|
|
|
- </div>
|
|
|
|
|
- <h3 class="text-xl font-bold text-gray-800">Bulk & ZIP Upload</h3>
|
|
|
|
|
- <p class="text-gray-500 mt-1 text-center">Upload multiple images or a <b>single ZIP file</b></p>
|
|
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- BULK TAB -->
|
|
|
|
|
+ <div class="tab-pane fade" id="pills-bulk" role="tabpanel">
|
|
|
|
|
+ <div class="mb-6 flex justify-center gap-6">
|
|
|
|
|
+ <label class="inline-flex items-center gap-2">
|
|
|
|
|
+ <input type="radio" name="bulk-action" value="remove_bg" checked>
|
|
|
|
|
+ <span class="font-semibold text-gray-700">Bulk Remove Background</span>
|
|
|
|
|
+ </label>
|
|
|
|
|
+ <label class="inline-flex items-center gap-2">
|
|
|
|
|
+ <input type="radio" name="bulk-action" value="caption">
|
|
|
|
|
+ <span class="font-semibold text-gray-700">Bulk Generate Caption</span>
|
|
|
|
|
+ </label>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div class="bg-white p-8 rounded-3xl shadow-sm border border-gray-200 mb-8">
|
|
|
|
|
+ <div id="bulk-drop-zone" class="upload-card flex flex-col items-center justify-center rounded-2xl p-12 cursor-pointer transition-all border-indigo-200" onclick="document.getElementById('bulk-file-input').click()">
|
|
|
|
|
+ <input type="file" id="bulk-file-input" class="hidden" accept="image/*,.zip" multiple>
|
|
|
|
|
+ <div class="bg-indigo-50 p-5 rounded-full mb-4 text-indigo-600">
|
|
|
|
|
+ <i class="bi bi-file-earmark-zip text-4xl"></i>
|
|
|
</div>
|
|
</div>
|
|
|
- <div id="bulk-list-container" class="hidden mt-8 border-t pt-8">
|
|
|
|
|
- <div class="flex justify-between items-center mb-6">
|
|
|
|
|
- <div>
|
|
|
|
|
- <h3 class="font-extrabold text-gray-900 text-lg">Batch Queue</h3>
|
|
|
|
|
- <p class="text-xs text-gray-400 uppercase font-bold tracking-widest"><span id="file-count">0</span> Items Ready</p>
|
|
|
|
|
- </div>
|
|
|
|
|
- <button id="start-bulk-btn" class="bg-indigo-600 text-white px-8 py-3 rounded-xl font-bold hover:bg-indigo-700 shadow-lg">Start Processing</button>
|
|
|
|
|
|
|
+ <h3 class="text-xl font-bold text-gray-800">Bulk & ZIP Upload</h3>
|
|
|
|
|
+ <p class="text-gray-500 mt-1 text-center">Upload multiple images or a <b>single ZIP file</b></p>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div id="bulk-list-container" class="hidden mt-8 border-t pt-8">
|
|
|
|
|
+ <div class="flex justify-between items-center mb-6">
|
|
|
|
|
+ <div>
|
|
|
|
|
+ <h3 class="font-extrabold text-gray-900 text-lg">Batch Queue</h3>
|
|
|
|
|
+ <p class="text-xs text-gray-400 uppercase font-bold tracking-widest"><span id="file-count">0</span> Items Ready</p>
|
|
|
</div>
|
|
</div>
|
|
|
- <div id="file-queue" class="grid grid-cols-2 sm:grid-cols-4 md:grid-cols-6 gap-4"></div>
|
|
|
|
|
|
|
+ <button id="start-bulk-btn" class="bg-indigo-600 text-white px-8 py-3 rounded-xl font-bold hover:bg-indigo-700 shadow-lg">Start Processing</button>
|
|
|
</div>
|
|
</div>
|
|
|
|
|
+ <div id="file-queue" class="grid grid-cols-2 sm:grid-cols-4 md:grid-cols-6 gap-4"></div>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
</div>
|
|
</div>
|
|
|
- <div id="bulk-loader" class="hidden fixed inset-0 bg-black/60 backdrop-blur-md z-[9999] flex flex-col items-center justify-center text-white">
|
|
|
|
|
- <div class="flex flex-col items-center p-8 bg-gray-900/80 rounded-3xl border border-white/10 shadow-2xl">
|
|
|
|
|
- <div class="w-16 h-16 border-4 border-indigo-500 border-t-transparent rounded-full animate-spin mb-4"></div>
|
|
|
|
|
- <h2 class="text-2xl font-bold">Processing Batch...</h2>
|
|
|
|
|
- <p class="text-gray-400 mt-2">AI is removing backgrounds and preparing your ZIP.</p>
|
|
|
|
|
- <p class="text-xs text-indigo-400 mt-4 uppercase tracking-widest font-bold">Please do not refresh the page</p>
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ </div>
|
|
|
|
|
+
|
|
|
|
|
+ <div id="bulk-loader" class="hidden fixed inset-0 bg-black/60 backdrop-blur-md z-[9999] flex flex-col items-center justify-center text-white">
|
|
|
|
|
+ <div class="flex flex-col items-center p-8 bg-gray-900/80 rounded-3xl border border-white/10 shadow-2xl">
|
|
|
|
|
+ <div class="w-16 h-16 border-4 border-indigo-500 border-t-transparent rounded-full animate-spin mb-4"></div>
|
|
|
|
|
+ <h2 class="text-2xl font-bold">Processing Batch...</h2>
|
|
|
|
|
+ <p class="text-gray-400 mt-2">AI is removing backgrounds and preparing your ZIP.</p>
|
|
|
|
|
+ <p class="text-xs text-indigo-400 mt-4 uppercase tracking-widest font-bold">Please do not refresh the page</p>
|
|
|
</div>
|
|
</div>
|
|
|
- </main>
|
|
|
|
|
- {% include 'footer.html' %}
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </main>
|
|
|
|
|
|
|
|
- <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
|
|
|
- <script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js"></script>
|
|
|
|
|
- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.min.js"></script>
|
|
|
|
|
- <script src="https://cdn.jsdelivr.net/npm/overlayscrollbars@2.3.0/browser/overlayscrollbars.browser.es6.min.js"></script>
|
|
|
|
|
- <script src="{% static './js/adminlte.js' %}"></script>
|
|
|
|
|
|
|
+ {% include 'footer.html' %}
|
|
|
|
|
+</div>
|
|
|
|
|
|
|
|
- <script>
|
|
|
|
|
-
|
|
|
|
|
|
|
+<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
|
|
|
|
+<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.11.8/dist/umd/popper.min.js"></script>
|
|
|
|
|
+<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.min.js"></script>
|
|
|
|
|
+<script src="https://cdn.jsdelivr.net/npm/overlayscrollbars@2.3.0/browser/overlayscrollbars.browser.es6.min.js"></script>
|
|
|
|
|
+<script src="{% static './js/adminlte.js' %}"></script>
|
|
|
|
|
|
|
|
- // --- PRESERVED SINGLE UPLOAD LOGIC ---
|
|
|
|
|
- const fileInput = document.getElementById('file-input');
|
|
|
|
|
- if (fileInput) {
|
|
|
|
|
- fileInput.onchange = (e) => handleSingleUpload(e.target.files[0]);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+<script>
|
|
|
|
|
+ // SINGLE IMAGE UPLOAD + CAPTION
|
|
|
|
|
+ const fileInput = document.getElementById('file-input');
|
|
|
|
|
+ if (fileInput) {
|
|
|
|
|
+ fileInput.onchange = (e) => handleSingleUpload(e.target.files[0]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // async function handleSingleUpload(file) {
|
|
|
|
|
+ // if (!file) return;
|
|
|
|
|
+ // document.getElementById('uploadContainer').classList.add('hidden');
|
|
|
|
|
+ // document.getElementById('result-container').classList.remove('hidden');
|
|
|
|
|
+ // document.getElementById('result-loader').classList.remove('hidden');
|
|
|
|
|
+ // document.getElementById('original-preview').src = URL.createObjectURL(file);
|
|
|
|
|
+
|
|
|
|
|
+ // const formData = new FormData();
|
|
|
|
|
+ // formData.append('image', file);
|
|
|
|
|
+
|
|
|
|
|
+ // try {
|
|
|
|
|
+ // // --- REMOVE BG ---
|
|
|
|
|
+ // const response = await fetch('/bg-remover/remove-bg/', {
|
|
|
|
|
+ // method: 'POST',
|
|
|
|
|
+ // body: formData,
|
|
|
|
|
+ // headers: {'X-CSRFToken': '{{ csrf_token }}'}
|
|
|
|
|
+ // });
|
|
|
|
|
+ // if (!response.ok) throw new Error("Processing failed");
|
|
|
|
|
+ // const blob = await response.blob();
|
|
|
|
|
+ // const url = URL.createObjectURL(blob);
|
|
|
|
|
+ // document.getElementById('processed-preview').src = url;
|
|
|
|
|
+ // const btn = document.getElementById('download-btn');
|
|
|
|
|
+ // btn.href = url;
|
|
|
|
|
+ // btn.download = `cleared_${file.name.split('.')[0]}.png`;
|
|
|
|
|
+ // btn.classList.remove('hidden');
|
|
|
|
|
+
|
|
|
|
|
+ // // --- GET CAPTION ---
|
|
|
|
|
+ // const captionResp = await fetch('/bg-remover/caption/', {
|
|
|
|
|
+ // method: 'POST',
|
|
|
|
|
+ // body: formData,
|
|
|
|
|
+ // headers: {'X-CSRFToken': '{{ csrf_token }}'}
|
|
|
|
|
+ // });
|
|
|
|
|
+ // if (captionResp.ok) {
|
|
|
|
|
+ // const data = await captionResp.json();
|
|
|
|
|
+ // document.getElementById('caption-text').innerText = data.caption;
|
|
|
|
|
+ // document.getElementById('caption-container').classList.remove('hidden');
|
|
|
|
|
+ // }
|
|
|
|
|
|
|
|
- async function handleSingleUpload(file) {
|
|
|
|
|
- if (!file) return;
|
|
|
|
|
- document.getElementById('uploadContainer').classList.add('hidden');
|
|
|
|
|
- document.getElementById('result-container').classList.remove('hidden');
|
|
|
|
|
- document.getElementById('result-loader').classList.remove('hidden');
|
|
|
|
|
- document.getElementById('original-preview').src = URL.createObjectURL(file);
|
|
|
|
|
|
|
+ // } catch (err) {
|
|
|
|
|
+ // alert("Error processing image: " + err.message);
|
|
|
|
|
+ // location.reload();
|
|
|
|
|
+ // } finally {
|
|
|
|
|
+ // document.getElementById('result-loader').classList.add('hidden');
|
|
|
|
|
+ // }
|
|
|
|
|
+ // }
|
|
|
|
|
|
|
|
- const formData = new FormData();
|
|
|
|
|
- formData.append('image', file);
|
|
|
|
|
|
|
+ async function handleSingleUpload(file) {
|
|
|
|
|
+ if (!file) return;
|
|
|
|
|
|
|
|
- try {
|
|
|
|
|
|
|
+ const selectedAction = document.querySelector('input[name="action"]:checked').value;
|
|
|
|
|
+
|
|
|
|
|
+ document.getElementById('uploadContainer').classList.add('hidden');
|
|
|
|
|
+ document.getElementById('result-container').classList.remove('hidden');
|
|
|
|
|
+ document.getElementById('result-loader').classList.remove('hidden');
|
|
|
|
|
+ document.getElementById('original-preview').src = URL.createObjectURL(file);
|
|
|
|
|
+
|
|
|
|
|
+ const formData = new FormData();
|
|
|
|
|
+ formData.append('image', file);
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (selectedAction === 'remove_bg') {
|
|
|
|
|
+ // --- REMOVE BG ---
|
|
|
const response = await fetch('/bg-remover/remove-bg/', {
|
|
const response = await fetch('/bg-remover/remove-bg/', {
|
|
|
method: 'POST',
|
|
method: 'POST',
|
|
|
body: formData,
|
|
body: formData,
|
|
|
headers: {'X-CSRFToken': '{{ csrf_token }}'}
|
|
headers: {'X-CSRFToken': '{{ csrf_token }}'}
|
|
|
});
|
|
});
|
|
|
- if (!response.ok) throw new Error("Processing failed");
|
|
|
|
|
|
|
+ if (!response.ok) throw new Error("Background removal failed");
|
|
|
const blob = await response.blob();
|
|
const blob = await response.blob();
|
|
|
const url = URL.createObjectURL(blob);
|
|
const url = URL.createObjectURL(blob);
|
|
|
document.getElementById('processed-preview').src = url;
|
|
document.getElementById('processed-preview').src = url;
|
|
|
|
|
+ document.getElementById('processed-preview').classList.remove('hidden');
|
|
|
|
|
+ document.getElementById('caption-text').classList.add('hidden');
|
|
|
|
|
+
|
|
|
const btn = document.getElementById('download-btn');
|
|
const btn = document.getElementById('download-btn');
|
|
|
btn.href = url;
|
|
btn.href = url;
|
|
|
btn.download = `cleared_${file.name.split('.')[0]}.png`;
|
|
btn.download = `cleared_${file.name.split('.')[0]}.png`;
|
|
|
btn.classList.remove('hidden');
|
|
btn.classList.remove('hidden');
|
|
|
- } catch (err) {
|
|
|
|
|
- alert("Error processing image: " + err.message);
|
|
|
|
|
- location.reload();
|
|
|
|
|
- } finally {
|
|
|
|
|
- document.getElementById('result-loader').classList.add('hidden');
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- // --- PRESERVED BULK LOGIC ---
|
|
|
|
|
- const bulkInput = document.getElementById('bulk-file-input');
|
|
|
|
|
- const fileQueue = document.getElementById('file-queue');
|
|
|
|
|
- const bulkList = document.getElementById('bulk-list-container');
|
|
|
|
|
- const startBulkBtn = document.getElementById('start-bulk-btn');
|
|
|
|
|
- const bulkLoader = document.getElementById('bulk-loader');
|
|
|
|
|
-
|
|
|
|
|
- if (bulkInput) {
|
|
|
|
|
- bulkInput.onchange = (e) => {
|
|
|
|
|
- const files = Array.from(e.target.files);
|
|
|
|
|
- if (files.length === 0) return;
|
|
|
|
|
- bulkList.classList.remove('hidden');
|
|
|
|
|
- document.getElementById('file-count').innerText = files.length;
|
|
|
|
|
- fileQueue.innerHTML = '';
|
|
|
|
|
- files.forEach(file => {
|
|
|
|
|
- const div = document.createElement('div');
|
|
|
|
|
- div.className = "relative bg-gray-50 rounded-xl border border-gray-100 p-2 text-center";
|
|
|
|
|
- if (file.name.toLowerCase().endsWith('.zip')) {
|
|
|
|
|
- div.innerHTML = `<div class="aspect-square flex flex-col items-center justify-center text-indigo-500"><i class="bi bi-file-earmark-zip-fill text-4xl"></i><span class="text-[10px] font-bold mt-1 truncate w-full px-2">${file.name}</span></div>`;
|
|
|
|
|
- } else {
|
|
|
|
|
- const reader = new FileReader();
|
|
|
|
|
- reader.onload = (event) => {
|
|
|
|
|
- div.innerHTML = `<div class="aspect-square rounded-lg overflow-hidden bg-white mb-1"><img src="${event.target.result}" class="w-full h-full object-cover"></div><span class="text-[9px] font-bold text-gray-400 truncate block">${file.name}</span>`;
|
|
|
|
|
- };
|
|
|
|
|
- reader.readAsDataURL(file);
|
|
|
|
|
- }
|
|
|
|
|
- fileQueue.appendChild(div);
|
|
|
|
|
|
|
+ document.getElementById('caption-container').classList.add('hidden'); // hide caption
|
|
|
|
|
+ document.getElementById('caption-text-below').classList.add('hidden'); // hide caption
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ } else if (selectedAction === 'caption') {
|
|
|
|
|
+ // --- GENERATE CAPTION ---
|
|
|
|
|
+ const captionResp = await fetch('/bg-remover/caption/', {
|
|
|
|
|
+ method: 'POST',
|
|
|
|
|
+ body: formData,
|
|
|
|
|
+ headers: {'X-CSRFToken': '{{ csrf_token }}'}
|
|
|
});
|
|
});
|
|
|
- };
|
|
|
|
|
|
|
+ if (!captionResp.ok) throw new Error("Caption generation failed");
|
|
|
|
|
+ const data = await captionResp.json();
|
|
|
|
|
+ document.getElementById('caption-text').innerText = data.caption;
|
|
|
|
|
+ document.getElementById('caption-container').classList.remove('hidden');
|
|
|
|
|
+ document.getElementById('caption-text-below').classList.remove('hidden');
|
|
|
|
|
+
|
|
|
|
|
+ document.getElementById('caption-text').classList.remove('hidden');
|
|
|
|
|
+ document.getElementById('processed-preview').classList.add('hidden');
|
|
|
|
|
+ document.getElementById('download-btn').classList.add('hidden');
|
|
|
|
|
+
|
|
|
|
|
+ // document.getElementById('processed-preview').src = ''; // no image
|
|
|
|
|
+ // document.getElementById('download-btn').classList.add('hidden');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ alert("Error: " + err.message);
|
|
|
|
|
+ location.reload();
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ document.getElementById('result-loader').classList.add('hidden');
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
+ // BULK LOGIC PRESERVED
|
|
|
|
|
+ const bulkInput = document.getElementById('bulk-file-input');
|
|
|
|
|
+ const fileQueue = document.getElementById('file-queue');
|
|
|
|
|
+ const bulkList = document.getElementById('bulk-list-container');
|
|
|
|
|
+ const startBulkBtn = document.getElementById('start-bulk-btn');
|
|
|
|
|
+ const bulkLoader = document.getElementById('bulk-loader');
|
|
|
|
|
|
|
|
- /*if (startBulkBtn) {
|
|
|
|
|
- startBulkBtn.onclick = async () => {
|
|
|
|
|
- const files = bulkInput.files;
|
|
|
|
|
- if (!files || files.length === 0) return;
|
|
|
|
|
- const formData = new FormData();
|
|
|
|
|
- for (let i = 0; i < files.length; i++) formData.append('images', files[i]);
|
|
|
|
|
- if (bulkLoader) bulkLoader.classList.remove('hidden');
|
|
|
|
|
- try {
|
|
|
|
|
- const response = await fetch('/bg-remover/remove-bg/bulk/', {
|
|
|
|
|
- method: 'POST', body: formData, headers: {'X-CSRFToken': '{{ csrf_token }}'}
|
|
|
|
|
- });
|
|
|
|
|
- if (response.ok) {
|
|
|
|
|
- const blob = await response.blob();
|
|
|
|
|
- const url = window.URL.createObjectURL(blob);
|
|
|
|
|
- const bulkCardInner = document.querySelector('#pills-bulk .bg-white');
|
|
|
|
|
- bulkCardInner.innerHTML = `<div class="text-center py-12"><div class="bg-green-100 text-green-600 p-6 rounded-full inline-block mb-6"><i class="bi bi-check-all text-6xl"></i></div><h2 class="text-3xl font-bold">Complete!</h2><a href="${url}" download="processed.zip" class="bg-indigo-600 text-white px-10 py-4 rounded-2xl font-bold inline-block mt-4">Download ZIP</a></div>`;
|
|
|
|
|
- }
|
|
|
|
|
- } finally { if (bulkLoader) bulkLoader.classList.add('hidden'); }
|
|
|
|
|
- };
|
|
|
|
|
- }*/
|
|
|
|
|
|
|
+ if (bulkInput) {
|
|
|
|
|
+ bulkInput.onchange = (e) => {
|
|
|
|
|
+ const files = Array.from(e.target.files);
|
|
|
|
|
+ if (files.length === 0) return;
|
|
|
|
|
+ bulkList.classList.remove('hidden');
|
|
|
|
|
+ document.getElementById('file-count').innerText = files.length;
|
|
|
|
|
+ fileQueue.innerHTML = '';
|
|
|
|
|
+ files.forEach(file => {
|
|
|
|
|
+ const div = document.createElement('div');
|
|
|
|
|
+ div.className = "relative bg-gray-50 rounded-xl border border-gray-100 p-2 text-center";
|
|
|
|
|
+ if (file.name.toLowerCase().endsWith('.zip')) {
|
|
|
|
|
+ div.innerHTML = `<div class="aspect-square flex flex-col items-center justify-center text-indigo-500"><i class="bi bi-file-earmark-zip-fill text-4xl"></i><span class="text-[10px] font-bold mt-1 truncate w-full px-2">${file.name}</span></div>`;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const reader = new FileReader();
|
|
|
|
|
+ reader.onload = (event) => {
|
|
|
|
|
+ div.innerHTML = `<div class="aspect-square rounded-lg overflow-hidden bg-white mb-1"><img src="${event.target.result}" class="w-full h-full object-cover"></div><span class="text-[9px] font-bold text-gray-400 truncate block">${file.name}</span>`;
|
|
|
|
|
+ };
|
|
|
|
|
+ reader.readAsDataURL(file);
|
|
|
|
|
+ }
|
|
|
|
|
+ fileQueue.appendChild(div);
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if (startBulkBtn) {
|
|
|
|
|
|
|
+ if (startBulkBtn) {
|
|
|
startBulkBtn.onclick = async () => {
|
|
startBulkBtn.onclick = async () => {
|
|
|
- const files = document.getElementById('bulk-file-input').files;
|
|
|
|
|
|
|
+ const files = bulkInput.files;
|
|
|
if (!files.length) return;
|
|
if (!files.length) return;
|
|
|
|
|
+
|
|
|
|
|
+ // 1. Identify which action is selected for bulk
|
|
|
|
|
+ const selectedAction = document.querySelector('input[name="bulk-action"]:checked').value;
|
|
|
const formData = new FormData();
|
|
const formData = new FormData();
|
|
|
- for (let i = 0; i < files.length; i++) formData.append('images', files[i]);
|
|
|
|
|
|
|
|
|
|
- document.getElementById('bulk-loader').classList.remove('hidden');
|
|
|
|
|
|
|
+ // Use 'images' as the key to match your single image logic/backend expectation
|
|
|
|
|
+ for (let i = 0; i < files.length; i++) {
|
|
|
|
|
+ formData.append('images', files[i]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const loader = document.getElementById('bulk-loader');
|
|
|
|
|
+ const loaderTitle = loader.querySelector('h2');
|
|
|
|
|
+ const loaderSub = loader.querySelector('p');
|
|
|
|
|
+
|
|
|
|
|
+ // Update loader text based on action
|
|
|
|
|
+ if (selectedAction === 'caption') {
|
|
|
|
|
+ loaderTitle.innerText = "Generating Captions...";
|
|
|
|
|
+ loaderSub.innerText = "AI is describing your images and preparing a report.";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ loaderTitle.innerText = "Processing Batch...";
|
|
|
|
|
+ loaderSub.innerText = "AI is removing backgrounds and preparing your ZIP.";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ loader.classList.remove('hidden');
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
- const response = await fetch('/bg-remover/remove-bg/bulk/', {
|
|
|
|
|
|
|
+ // 2. Determine URL based on action
|
|
|
|
|
+ const endpoint = selectedAction === 'caption'
|
|
|
|
|
+ ? '/bg-remover/caption/bulk/'
|
|
|
|
|
+ : '/bg-remover/remove-bg/bulk/';
|
|
|
|
|
+
|
|
|
|
|
+ const response = await fetch(endpoint, {
|
|
|
method: 'POST',
|
|
method: 'POST',
|
|
|
body: formData,
|
|
body: formData,
|
|
|
headers: {'X-CSRFToken': '{{ csrf_token }}'}
|
|
headers: {'X-CSRFToken': '{{ csrf_token }}'}
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
if (response.ok) {
|
|
if (response.ok) {
|
|
|
- // REDIRECT TO THE NEW HISTORY PAGE
|
|
|
|
|
- window.location.href = "{% url 'bg_history_page' %}";
|
|
|
|
|
|
|
+ const data = await response.json();
|
|
|
|
|
+
|
|
|
|
|
+ if (selectedAction === 'caption') {
|
|
|
|
|
+ // If your caption bulk returns an Excel or CSV file
|
|
|
|
|
+ if (data.file_url) {
|
|
|
|
|
+ window.location.href = data.file_url;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ alert("Captions generated successfully. Check Task History.");
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // Standard ZIP download for background removal
|
|
|
|
|
+ window.location.href = data.zip_url;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const errorData = await response.json();
|
|
|
|
|
+ alert("Batch processing failed: " + (errorData.error || "Unknown error"));
|
|
|
}
|
|
}
|
|
|
- } catch (err) {
|
|
|
|
|
- alert("Upload failed");
|
|
|
|
|
- document.getElementById('bulk-loader').classList.add('hidden');
|
|
|
|
|
|
|
+ } catch(err) {
|
|
|
|
|
+ console.error(err);
|
|
|
|
|
+ alert("An error occurred during batch processing.");
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ loader.classList.add('hidden');
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- </script>
|
|
|
|
|
- <script>
|
|
|
|
|
- const SELECTOR_SIDEBAR_WRAPPER = ".sidebar-wrapper";
|
|
|
|
|
- const Default = {
|
|
|
|
|
- scrollbarTheme: "os-theme-light",
|
|
|
|
|
- scrollbarAutoHide: "leave",
|
|
|
|
|
- scrollbarClickScroll: true,
|
|
|
|
|
- };
|
|
|
|
|
- document.addEventListener("DOMContentLoaded", function () {
|
|
|
|
|
- const sidebarWrapper = document.querySelector(SELECTOR_SIDEBAR_WRAPPER);
|
|
|
|
|
- if (
|
|
|
|
|
- sidebarWrapper &&
|
|
|
|
|
- typeof OverlayScrollbarsGlobal?.OverlayScrollbars !== "undefined"
|
|
|
|
|
- ) {
|
|
|
|
|
- OverlayScrollbarsGlobal.OverlayScrollbars(sidebarWrapper, {
|
|
|
|
|
- scrollbars: {
|
|
|
|
|
- theme: Default.scrollbarTheme,
|
|
|
|
|
- autoHide: Default.scrollbarAutoHide,
|
|
|
|
|
- clickScroll: Default.scrollbarClickScroll,
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- </script>
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // if (startBulkBtn) {
|
|
|
|
|
+ // startBulkBtn.onclick = async () => {
|
|
|
|
|
+ // const files = bulkInput.files;
|
|
|
|
|
+ // if (!files.length) return;
|
|
|
|
|
+ // const formData = new FormData();
|
|
|
|
|
+ // for (let i = 0; i < files.length; i++) formData.append('images', files[i]);
|
|
|
|
|
+
|
|
|
|
|
+ // document.getElementById('bulk-loader').classList.remove('hidden');
|
|
|
|
|
+ // try {
|
|
|
|
|
+ // const response = await fetch('/bg-remover/remove-bg/bulk/', {
|
|
|
|
|
+ // method: 'POST',
|
|
|
|
|
+ // body: formData,
|
|
|
|
|
+ // headers: {'X-CSRFToken': '{{ csrf_token }}'}
|
|
|
|
|
+ // });
|
|
|
|
|
+ // if (response.ok) {
|
|
|
|
|
+ // window.location.href = await response.json().then(data => data.zip_url);
|
|
|
|
|
+ // } else { alert("Batch processing failed."); }
|
|
|
|
|
+ // } catch(err) { alert(err); }
|
|
|
|
|
+ // finally { bulkLoader.classList.add('hidden'); }
|
|
|
|
|
+ // };
|
|
|
|
|
+ // }
|
|
|
|
|
+</script>
|
|
|
</body>
|
|
</body>
|
|
|
-</html>
|
|
|
|
|
|
|
+</html>
|