Spaces:
Running on Zero
Running on Zero
Update index.html
Browse files- index.html +27 -8
index.html
CHANGED
|
@@ -363,7 +363,7 @@ body{
|
|
| 363 |
.example-meta{padding:6px 10px 2px;display:flex;align-items:center;gap:5px;flex-wrap:wrap}
|
| 364 |
.example-lora-badge{
|
| 365 |
display:inline-flex;padding:2px 7px;background:rgba(255,165,0,.1);border-radius:4px;
|
| 366 |
-
font-size:9px;font-weight:600;color:var(--accent2);font-family
|
| 367 |
white-space:nowrap;border:1px solid rgba(255,165,0,.25);
|
| 368 |
}
|
| 369 |
.example-body{flex:1;display:flex;flex-direction:column;justify-content:center;min-width:0}
|
|
@@ -727,6 +727,24 @@ const SUGGESTIONS = [
|
|
| 727 |
['Car', 'red car'],
|
| 728 |
];
|
| 729 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 730 |
/* ── Toast ── */
|
| 731 |
function showToast(message, type) {
|
| 732 |
let toast = document.getElementById('app-toast');
|
|
@@ -778,17 +796,18 @@ function renderCanvas() {
|
|
| 778 |
|
| 779 |
if (mediaData.type === 'video') {
|
| 780 |
const vid = document.createElement('video');
|
| 781 |
-
vid.src = mediaData.b64;
|
| 782 |
vid.className = 'modern-out-vid';
|
| 783 |
vid.controls = true;
|
| 784 |
vid.autoplay = true;
|
| 785 |
vid.loop = true;
|
| 786 |
vid.muted = true;
|
|
|
|
| 787 |
outBody.appendChild(vid);
|
| 788 |
canvasMeta.textContent = (showResult ? 'result' : 'input') + ' · video';
|
| 789 |
} else {
|
| 790 |
const img = document.createElement('img');
|
| 791 |
-
img.src = mediaData.b64;
|
| 792 |
img.className = 'modern-out-img';
|
| 793 |
if (showInput) {
|
| 794 |
img.style.cursor = 'crosshair';
|
|
@@ -910,9 +929,9 @@ function renderFilmstrip() {
|
|
| 910 |
t.className = 'fs-thumb selected';
|
| 911 |
let mediaHTML = '';
|
| 912 |
if (currentImage.type === 'video') {
|
| 913 |
-
mediaHTML = '<video src="' + currentImage.b64 + '" muted preload="metadata"></video>';
|
| 914 |
} else {
|
| 915 |
-
mediaHTML = '<img src="' + currentImage.b64 + '" alt="">';
|
| 916 |
}
|
| 917 |
t.innerHTML = mediaHTML +
|
| 918 |
'<span class="fs-badge">' + (currentImage.type === 'video' ? 'video' : 'image') + '</span>' +
|
|
@@ -1068,7 +1087,7 @@ function renderHistory() {
|
|
| 1068 |
const t = document.createElement('div');
|
| 1069 |
t.className = 'fs-thumb' + (i === historyIdx ? ' selected' : '');
|
| 1070 |
const im = document.createElement('img');
|
| 1071 |
-
im.src = entry.b64;
|
| 1072 |
t.appendChild(im);
|
| 1073 |
t.addEventListener('click', () => { historyIdx = i; showResult(history[i]); renderHistory(); });
|
| 1074 |
historyStrip.appendChild(t);
|
|
@@ -1087,7 +1106,7 @@ lightbox.addEventListener('click', () => lightbox.classList.remove('visible'));
|
|
| 1087 |
document.addEventListener('keydown', (e) => { if (e.key === 'Escape') lightbox.classList.remove('visible'); });
|
| 1088 |
zoomBtn.addEventListener('click', () => {
|
| 1089 |
if (currentResult && currentResult.type === 'image') {
|
| 1090 |
-
lightboxImg.src = currentResult.b64;
|
| 1091 |
lightbox.classList.add('visible');
|
| 1092 |
}
|
| 1093 |
});
|
|
@@ -1096,7 +1115,7 @@ zoomBtn.addEventListener('click', () => {
|
|
| 1096 |
dlBtn.addEventListener('click', () => {
|
| 1097 |
if (currentResult && currentResult.b64) {
|
| 1098 |
const a = document.createElement('a');
|
| 1099 |
-
a.href = currentResult.b64;
|
| 1100 |
a.download = 'sam3_result.' + (currentResult.type === 'video' ? 'mp4' : 'png');
|
| 1101 |
document.body.appendChild(a); a.click(); document.body.removeChild(a);
|
| 1102 |
}
|
|
|
|
| 363 |
.example-meta{padding:6px 10px 2px;display:flex;align-items:center;gap:5px;flex-wrap:wrap}
|
| 364 |
.example-lora-badge{
|
| 365 |
display:inline-flex;padding:2px 7px;background:rgba(255,165,0,.1);border-radius:4px;
|
| 366 |
+
font-size:9px;font-weight:600;color:var(--accent2);font-family='JetBrains Mono',monospace;
|
| 367 |
white-space:nowrap;border:1px solid rgba(255,165,0,.25);
|
| 368 |
}
|
| 369 |
.example-body{flex:1;display:flex;flex-direction:column;justify-content:center;min-width:0}
|
|
|
|
| 727 |
['Car', 'red car'],
|
| 728 |
];
|
| 729 |
|
| 730 |
+
/* ── Helper: Convert Base64 Data URI to Object URL for better video playback ── */
|
| 731 |
+
function dataURItoBlob(dataURI) {
|
| 732 |
+
if (!dataURI || !dataURI.startsWith('data:')) return dataURI;
|
| 733 |
+
try {
|
| 734 |
+
const byteString = atob(dataURI.split(',')[1]);
|
| 735 |
+
const mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
|
| 736 |
+
const ab = new ArrayBuffer(byteString.length);
|
| 737 |
+
const ia = new Uint8Array(ab);
|
| 738 |
+
for (let i = 0; i < byteString.length; i++) {
|
| 739 |
+
ia[i] = byteString.charCodeAt(i);
|
| 740 |
+
}
|
| 741 |
+
return URL.createObjectURL(new Blob([ab], {type: mimeString}));
|
| 742 |
+
} catch (e) {
|
| 743 |
+
console.error("Blob conversion failed:", e);
|
| 744 |
+
return dataURI; // Fallback to raw data URI
|
| 745 |
+
}
|
| 746 |
+
}
|
| 747 |
+
|
| 748 |
/* ── Toast ── */
|
| 749 |
function showToast(message, type) {
|
| 750 |
let toast = document.getElementById('app-toast');
|
|
|
|
| 796 |
|
| 797 |
if (mediaData.type === 'video') {
|
| 798 |
const vid = document.createElement('video');
|
| 799 |
+
vid.src = dataURItoBlob(mediaData.b64); // Use Blob URL for reliable playback
|
| 800 |
vid.className = 'modern-out-vid';
|
| 801 |
vid.controls = true;
|
| 802 |
vid.autoplay = true;
|
| 803 |
vid.loop = true;
|
| 804 |
vid.muted = true;
|
| 805 |
+
vid.playsInline = true; // Crucial for iOS Safari
|
| 806 |
outBody.appendChild(vid);
|
| 807 |
canvasMeta.textContent = (showResult ? 'result' : 'input') + ' · video';
|
| 808 |
} else {
|
| 809 |
const img = document.createElement('img');
|
| 810 |
+
img.src = dataURItoBlob(mediaData.b64); // Use Blob URL
|
| 811 |
img.className = 'modern-out-img';
|
| 812 |
if (showInput) {
|
| 813 |
img.style.cursor = 'crosshair';
|
|
|
|
| 929 |
t.className = 'fs-thumb selected';
|
| 930 |
let mediaHTML = '';
|
| 931 |
if (currentImage.type === 'video') {
|
| 932 |
+
mediaHTML = '<video src="' + dataURItoBlob(currentImage.b64) + '" muted preload="metadata"></video>';
|
| 933 |
} else {
|
| 934 |
+
mediaHTML = '<img src="' + dataURItoBlob(currentImage.b64) + '" alt="">';
|
| 935 |
}
|
| 936 |
t.innerHTML = mediaHTML +
|
| 937 |
'<span class="fs-badge">' + (currentImage.type === 'video' ? 'video' : 'image') + '</span>' +
|
|
|
|
| 1087 |
const t = document.createElement('div');
|
| 1088 |
t.className = 'fs-thumb' + (i === historyIdx ? ' selected' : '');
|
| 1089 |
const im = document.createElement('img');
|
| 1090 |
+
im.src = dataURItoBlob(entry.b64);
|
| 1091 |
t.appendChild(im);
|
| 1092 |
t.addEventListener('click', () => { historyIdx = i; showResult(history[i]); renderHistory(); });
|
| 1093 |
historyStrip.appendChild(t);
|
|
|
|
| 1106 |
document.addEventListener('keydown', (e) => { if (e.key === 'Escape') lightbox.classList.remove('visible'); });
|
| 1107 |
zoomBtn.addEventListener('click', () => {
|
| 1108 |
if (currentResult && currentResult.type === 'image') {
|
| 1109 |
+
lightboxImg.src = dataURItoBlob(currentResult.b64);
|
| 1110 |
lightbox.classList.add('visible');
|
| 1111 |
}
|
| 1112 |
});
|
|
|
|
| 1115 |
dlBtn.addEventListener('click', () => {
|
| 1116 |
if (currentResult && currentResult.b64) {
|
| 1117 |
const a = document.createElement('a');
|
| 1118 |
+
a.href = currentResult.b64; // Keep base64 for download to ensure it saves correctly
|
| 1119 |
a.download = 'sam3_result.' + (currentResult.type === 'video' ? 'mp4' : 'png');
|
| 1120 |
document.body.appendChild(a); a.click(); document.body.removeChild(a);
|
| 1121 |
}
|