Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -140,66 +140,79 @@ HTML_UI = """
|
|
| 140 |
<head>
|
| 141 |
<meta charset="UTF-8">
|
| 142 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 143 |
-
<title>
|
| 144 |
<style>
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
</style>
|
| 157 |
</head>
|
| 158 |
<body>
|
| 159 |
<div class="card">
|
| 160 |
-
<h2>
|
|
|
|
| 161 |
|
| 162 |
<div class="input-group">
|
| 163 |
-
<label>
|
| 164 |
-
<input type="text" id="imgUrl" placeholder="
|
| 165 |
</div>
|
| 166 |
|
|
|
|
|
|
|
| 167 |
<div class="input-group">
|
| 168 |
-
<label>
|
| 169 |
<input type="file" id="imgFile" accept="image/*">
|
| 170 |
</div>
|
| 171 |
|
|
|
|
| 172 |
<select id="level">
|
| 173 |
-
<option value="none">
|
| 174 |
-
<option value="extreme" selected>
|
| 175 |
-
<option value="medium">
|
| 176 |
</select>
|
| 177 |
|
| 178 |
-
<button onclick="
|
| 179 |
|
| 180 |
<div id="result">
|
| 181 |
-
<h3 style="margin:0 0 10px 0;">β
|
| 182 |
-
<p style="margin: 0; color: #
|
| 183 |
<div class="url-box" id="resLink"></div>
|
|
|
|
|
|
|
| 184 |
<div class="stats">
|
| 185 |
-
<span id="oldSize">
|
| 186 |
-
<span
|
| 187 |
</div>
|
| 188 |
-
<
|
| 189 |
</div>
|
| 190 |
</div>
|
| 191 |
|
| 192 |
<script>
|
| 193 |
-
async function
|
| 194 |
const btn = document.getElementById('btn');
|
| 195 |
const urlInput = document.getElementById('imgUrl').value;
|
| 196 |
const fileInput = document.getElementById('imgFile').files[0];
|
| 197 |
const level = document.getElementById('level').value;
|
| 198 |
const resDiv = document.getElementById('result');
|
| 199 |
|
| 200 |
-
if(!urlInput && !fileInput) { alert("Please provide
|
| 201 |
|
| 202 |
-
btn.innerText = "
|
| 203 |
btn.disabled = true;
|
| 204 |
resDiv.style.display = "none";
|
| 205 |
|
|
@@ -214,18 +227,25 @@ HTML_UI = """
|
|
| 214 |
|
| 215 |
if(data.success) {
|
| 216 |
document.getElementById('resLink').innerText = data.url;
|
| 217 |
-
document.getElementById('oldSize').innerText =
|
| 218 |
-
document.getElementById('newSize').innerText =
|
|
|
|
| 219 |
resDiv.style.display = "block";
|
| 220 |
} else {
|
| 221 |
-
alert("
|
| 222 |
}
|
| 223 |
} catch (err) {
|
| 224 |
-
alert("
|
| 225 |
}
|
| 226 |
-
btn.innerText = "
|
| 227 |
btn.disabled = false;
|
| 228 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
</script>
|
| 230 |
</body>
|
| 231 |
</html>
|
|
|
|
| 140 |
<head>
|
| 141 |
<meta charset="UTF-8">
|
| 142 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 143 |
+
<title>OptiPix Pro | Smart Image Optimizer</title>
|
| 144 |
<style>
|
| 145 |
+
:root { --primary: #3b82f6; --bg: #0f172a; --card: #1e293b; --text: #f1f5f9; }
|
| 146 |
+
body { font-family: 'Inter', system-ui, sans-serif; background: var(--bg); color: var(--text); padding: 20px; max-width: 700px; margin: auto; }
|
| 147 |
+
.card { background: var(--card); padding: 30px; border-radius: 16px; box-shadow: 0 10px 25px rgba(0,0,0,0.3); border: 1px solid #334155; }
|
| 148 |
+
h2 { color: #fff; margin-top: 0; font-size: 24px; text-align: center; }
|
| 149 |
+
p.sub { text-align: center; color: #94a3b8; font-size: 14px; margin-bottom: 25px; }
|
| 150 |
+
.input-group { background: #0f172a; padding: 15px; border-radius: 10px; margin-bottom: 20px; border: 1px solid #334155; }
|
| 151 |
+
label { display: block; font-weight: 600; margin-bottom: 8px; font-size: 14px; color: #3b82f6; }
|
| 152 |
+
input[type="text"], input[type="file"], select { width: 100%; padding: 12px; background: #1e293b; color: #fff; border: 1px solid #475569; border-radius: 8px; outline: none; box-sizing: border-box; font-size: 14px; }
|
| 153 |
+
input:focus { border-color: var(--primary); }
|
| 154 |
+
button { width: 100%; padding: 14px; background: var(--primary); color: white; font-weight: bold; border: none; border-radius: 8px; cursor: pointer; font-size: 16px; transition: 0.3s; margin-top: 10px; }
|
| 155 |
+
button:hover { background: #2563eb; transform: translateY(-1px); }
|
| 156 |
+
button:disabled { background: #475569; cursor: not-allowed; transform: none; }
|
| 157 |
+
#result { margin-top: 30px; padding: 20px; background: #064e3b; border-radius: 12px; display: none; animation: fadeIn 0.5s ease; }
|
| 158 |
+
.url-box { background: #0f172a; padding: 12px; border: 1px solid #059669; border-radius: 6px; margin: 10px 0; font-family: monospace; font-size: 13px; color: #34d399; overflow-x: auto; white-space: nowrap; }
|
| 159 |
+
.stats { display: flex; justify-content: space-between; font-size: 13px; margin-top: 15px; background: rgba(0,0,0,0.2); padding: 8px 12px; border-radius: 6px; }
|
| 160 |
+
.preview-img { max-width: 100%; border-radius: 8px; margin-top: 15px; border: 1px solid #334155; display: block; }
|
| 161 |
+
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
|
| 162 |
+
.copy-btn { background: #334155; color: #fff; padding: 5px 10px; font-size: 11px; border-radius: 4px; border: none; cursor: pointer; float: right; margin-top: -35px; margin-right: 5px; }
|
| 163 |
</style>
|
| 164 |
</head>
|
| 165 |
<body>
|
| 166 |
<div class="card">
|
| 167 |
+
<h2>π OptiPix Pro</h2>
|
| 168 |
+
<p class="sub">High-performance AI image compression and cloud hosting.</p>
|
| 169 |
|
| 170 |
<div class="input-group">
|
| 171 |
+
<label>Remote Image URL</label>
|
| 172 |
+
<input type="text" id="imgUrl" placeholder="https://example.com/image.jpg">
|
| 173 |
</div>
|
| 174 |
|
| 175 |
+
<div style="text-align: center; margin-bottom: 20px; color: #475569; font-size: 12px;">β OR β</div>
|
| 176 |
+
|
| 177 |
<div class="input-group">
|
| 178 |
+
<label>Upload Local Image</label>
|
| 179 |
<input type="file" id="imgFile" accept="image/*">
|
| 180 |
</div>
|
| 181 |
|
| 182 |
+
<label>Compression Level</label>
|
| 183 |
<select id="level">
|
| 184 |
+
<option value="none">Original (No Compression)</option>
|
| 185 |
+
<option value="extreme" selected>Web-Ready (Max Optimization)</option>
|
| 186 |
+
<option value="medium">Standard (Balanced)</option>
|
| 187 |
</select>
|
| 188 |
|
| 189 |
+
<button onclick="processImage()" id="btn">Optimize & Host Image</button>
|
| 190 |
|
| 191 |
<div id="result">
|
| 192 |
+
<h3 style="margin:0 0 10px 0; font-size: 18px; color: #34d399;">β
Processing Complete</h3>
|
| 193 |
+
<p style="margin: 0; color: #a7f3d0; font-size: 13px;">CDN Optimized Link:</p>
|
| 194 |
<div class="url-box" id="resLink"></div>
|
| 195 |
+
<button class="copy-btn" onclick="copyUrl()">Copy URL</button>
|
| 196 |
+
|
| 197 |
<div class="stats">
|
| 198 |
+
<span>Original: <span id="oldSize">--</span> KB</span>
|
| 199 |
+
<span style="color: #34d399;">Optimized: <span id="newSize">--</span> KB</span>
|
| 200 |
</div>
|
| 201 |
+
<img id="resImg" class="preview-img" src="" alt="Preview">
|
| 202 |
</div>
|
| 203 |
</div>
|
| 204 |
|
| 205 |
<script>
|
| 206 |
+
async function processImage() {
|
| 207 |
const btn = document.getElementById('btn');
|
| 208 |
const urlInput = document.getElementById('imgUrl').value;
|
| 209 |
const fileInput = document.getElementById('imgFile').files[0];
|
| 210 |
const level = document.getElementById('level').value;
|
| 211 |
const resDiv = document.getElementById('result');
|
| 212 |
|
| 213 |
+
if(!urlInput && !fileInput) { alert("Please provide an image source!"); return; }
|
| 214 |
|
| 215 |
+
btn.innerText = "β‘ Processing on Cloud...";
|
| 216 |
btn.disabled = true;
|
| 217 |
resDiv.style.display = "none";
|
| 218 |
|
|
|
|
| 227 |
|
| 228 |
if(data.success) {
|
| 229 |
document.getElementById('resLink').innerText = data.url;
|
| 230 |
+
document.getElementById('oldSize').innerText = data.original_size_kb;
|
| 231 |
+
document.getElementById('newSize').innerText = data.encrypted_size_kb;
|
| 232 |
+
document.getElementById('resImg').src = data.url;
|
| 233 |
resDiv.style.display = "block";
|
| 234 |
} else {
|
| 235 |
+
alert("Processing Error: " + data.error);
|
| 236 |
}
|
| 237 |
} catch (err) {
|
| 238 |
+
alert("Cloud connection failed!");
|
| 239 |
}
|
| 240 |
+
btn.innerText = "Optimize & Host Image";
|
| 241 |
btn.disabled = false;
|
| 242 |
}
|
| 243 |
+
|
| 244 |
+
function copyUrl() {
|
| 245 |
+
const url = document.getElementById('resLink').innerText;
|
| 246 |
+
navigator.clipboard.writeText(url);
|
| 247 |
+
alert("Link copied to clipboard!");
|
| 248 |
+
}
|
| 249 |
</script>
|
| 250 |
</body>
|
| 251 |
</html>
|