Spaces:
Sleeping
Sleeping
File size: 10,077 Bytes
18ea579 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 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 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Image Upscaler API Test</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
max-width: 800px;
margin: 0 auto;
padding: 20px;
background: #f5f5f5;
}
.container {
background: white;
padding: 30px;
border-radius: 12px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
h1 {
color: #333;
text-align: center;
margin-bottom: 30px;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: 600;
color: #555;
}
input, select {
width: 100%;
padding: 10px;
border: 2px solid #ddd;
border-radius: 6px;
font-size: 16px;
box-sizing: border-box;
}
input:focus, select:focus {
outline: none;
border-color: #007bff;
}
button {
background: #007bff;
color: white;
padding: 12px 24px;
border: none;
border-radius: 6px;
font-size: 16px;
cursor: pointer;
width: 100%;
margin-top: 10px;
}
button:hover {
background: #0056b3;
}
button:disabled {
background: #ccc;
cursor: not-allowed;
}
.result {
margin-top: 30px;
padding: 20px;
background: #f8f9fa;
border-radius: 6px;
border-left: 4px solid #007bff;
}
.error {
background: #f8d7da;
border-left-color: #dc3545;
color: #721c24;
}
.success {
background: #d4edda;
border-left-color: #28a745;
color: #155724;
}
.image-container {
display: flex;
gap: 20px;
margin-top: 20px;
flex-wrap: wrap;
}
.image-box {
flex: 1;
min-width: 300px;
}
.image-box h3 {
margin-top: 0;
color: #555;
}
.image-box img {
max-width: 100%;
height: auto;
border: 2px solid #ddd;
border-radius: 6px;
}
.metadata {
background: #e9ecef;
padding: 15px;
border-radius: 6px;
margin-top: 15px;
font-family: monospace;
font-size: 14px;
}
.loading {
text-align: center;
padding: 20px;
}
.spinner {
border: 4px solid #f3f3f3;
border-top: 4px solid #007bff;
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
margin: 0 auto 10px;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
</style>
</head>
<body>
<div class="container">
<h1>๐ AI Image Upscaler API Test</h1>
<form id="upscaleForm">
<div class="form-group">
<label for="imageFile">Select Image:</label>
<input type="file" id="imageFile" accept="image/*" required>
</div>
<div class="form-group">
<label for="scale">Scale Factor:</label>
<select id="scale">
<option value="2">2x</option>
<option value="3">3x</option>
<option value="4">4x</option>
</select>
</div>
<div class="form-group">
<label for="modelType">AI Model:</label>
<select id="modelType">
<option value="esrgan-slim">ESRGAN Slim (Fast)</option>
<option value="esrgan-medium">ESRGAN Medium (Balanced)</option>
<option value="esrgan-thick">ESRGAN Thick (Best Quality)</option>
</select>
</div>
<div class="form-group">
<label for="patchSize">Patch Size:</label>
<select id="patchSize">
<option value="64">64</option>
<option value="96">96</option>
<option value="128" selected>128</option>
<option value="160">160</option>
<option value="192">192</option>
</select>
</div>
<div class="form-group">
<label for="padding">Padding:</label>
<select id="padding">
<option value="0">0</option>
<option value="4">4</option>
<option value="8" selected>8</option>
<option value="12">12</option>
<option value="16">16</option>
</select>
</div>
<button type="submit" id="submitBtn">Upscale Image</button>
</form>
<div id="result"></div>
</div>
<script>
document.getElementById('upscaleForm').addEventListener('submit', async (e) => {
e.preventDefault();
const fileInput = document.getElementById('imageFile');
const scale = document.getElementById('scale').value;
const modelType = document.getElementById('modelType').value;
const patchSize = document.getElementById('patchSize').value;
const padding = document.getElementById('padding').value;
const submitBtn = document.getElementById('submitBtn');
const resultDiv = document.getElementById('result');
if (!fileInput.files[0]) {
alert('Please select an image file');
return;
}
// Show loading state
submitBtn.disabled = true;
submitBtn.textContent = 'Processing...';
resultDiv.innerHTML = `
<div class="loading">
<div class="spinner"></div>
<p>Upscaling image with ${scale}x scale using ${modelType} model...</p>
</div>
`;
try {
const formData = new FormData();
formData.append('image', fileInput.files[0]);
formData.append('scale', scale);
formData.append('modelType', modelType);
formData.append('patchSize', patchSize);
formData.append('padding', padding);
const startTime = Date.now();
const response = await fetch('/upscale', {
method: 'POST',
body: formData
});
const result = await response.json();
const totalTime = Date.now() - startTime;
if (result.success) {
// Create original image URL
const originalImageUrl = URL.createObjectURL(fileInput.files[0]);
resultDiv.innerHTML = `
<div class="result success">
<h3>โ
Upscaling Successful!</h3>
<div class="image-container">
<div class="image-box">
<h3>Original Image</h3>
<img src="${originalImageUrl}" alt="Original">
</div>
<div class="image-box">
<h3>Upscaled Image (${result.metadata.scale}x)</h3>
<img src="${result.result}" alt="Upscaled">
<a href="${result.result}" download="upscaled-${result.metadata.scale}x.png"
style="display: inline-block; margin-top: 10px; padding: 8px 16px; background: #007bff; color: white; text-decoration: none; border-radius: 4px;">
Download Upscaled Image
</a>
</div>
</div>
<div class="metadata">
<strong>Processing Details:</strong><br>
Scale: ${result.metadata.scale}x<br>
Model: ${result.metadata.modelType}<br>
Patch Size: ${result.metadata.patchSize}<br>
Padding: ${result.metadata.padding}<br>
Backend: ${result.metadata.backend}<br>
Server Processing Time: ${result.metadata.processingTime}ms<br>
Total Time: ${totalTime}ms
</div>
</div>
`;
} else {
throw new Error(result.error || 'Unknown error');
}
} catch (error) {
resultDiv.innerHTML = `
<div class="result error">
<h3>โ Error</h3>
<p><strong>Failed to upscale image:</strong> ${error.message}</p>
</div>
`;
} finally {
submitBtn.disabled = false;
submitBtn.textContent = 'Upscale Image';
}
});
</script>
</body>
</html>
|