Spaces:
Running
Running
Update index.html
Browse files- index.html +19 -14
index.html
CHANGED
|
@@ -4,7 +4,6 @@
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>Open-Generative-AI Studio</title>
|
| 7 |
-
<!-- Include Puter.js for zero-key AI and cloud features -->
|
| 8 |
<script src="https://js.puter.com/v2/"></script>
|
| 9 |
</head>
|
| 10 |
<body style="margin: 0; padding: 20px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background-color: #0b0b0f; color: #f1f1f3;">
|
|
@@ -12,7 +11,7 @@
|
|
| 12 |
|
| 13 |
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
|
| 14 |
<h2 style="margin: 0; color: #fff; font-size: 20px;">Open-Generative-AI Studio</h2>
|
| 15 |
-
<button id="authBtn" onclick="
|
| 16 |
</div>
|
| 17 |
|
| 18 |
<div style="margin-bottom: 16px;">
|
|
@@ -22,7 +21,7 @@
|
|
| 22 |
|
| 23 |
<div style="display: flex; gap: 10px; margin-bottom: 20px;">
|
| 24 |
<button onclick="generateImage()" style="flex: 1; background: #7c3aed; color: #fff; border: none; padding: 10px; border-radius: 6px; font-size: 14px; font-weight: 600; cursor: pointer;">Generate Image</button>
|
| 25 |
-
<button onclick="generateText()" style="flex:
|
| 26 |
</div>
|
| 27 |
|
| 28 |
<label style="display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; color: #a1a1aa;">Output Result</label>
|
|
@@ -32,19 +31,26 @@
|
|
| 32 |
</div>
|
| 33 |
|
| 34 |
<script>
|
| 35 |
-
// Check initial sign-in state
|
| 36 |
window.addEventListener('DOMContentLoaded', async () => {
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
}
|
| 40 |
});
|
| 41 |
|
| 42 |
-
async function
|
| 43 |
-
|
|
|
|
|
|
|
| 44 |
await puter.auth.signIn();
|
| 45 |
document.getElementById('authBtn').innerText = "Connected";
|
| 46 |
-
}
|
| 47 |
-
|
|
|
|
|
|
|
| 48 |
}
|
| 49 |
}
|
| 50 |
|
|
@@ -57,16 +63,15 @@
|
|
| 57 |
return;
|
| 58 |
}
|
| 59 |
|
| 60 |
-
output.innerHTML = "Generating image
|
| 61 |
try {
|
| 62 |
-
// Generates an image element directly using Puter.js
|
| 63 |
const imgElement = await puter.ai.txt2img(prompt);
|
| 64 |
output.innerHTML = "";
|
| 65 |
imgElement.style.maxWidth = "100%";
|
| 66 |
imgElement.style.borderRadius = "6px";
|
| 67 |
output.appendChild(imgElement);
|
| 68 |
} catch (err) {
|
| 69 |
-
output.innerText = "Error: " + err;
|
| 70 |
}
|
| 71 |
}
|
| 72 |
|
|
@@ -84,7 +89,7 @@
|
|
| 84 |
const response = await puter.ai.chat(prompt);
|
| 85 |
output.innerHTML = `<div style="text-align: left; width: 100%; white-space: pre-wrap;">${response}</div>`;
|
| 86 |
} catch (err) {
|
| 87 |
-
output.innerText = "Error: " + err;
|
| 88 |
}
|
| 89 |
}
|
| 90 |
</script>
|
|
|
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>Open-Generative-AI Studio</title>
|
|
|
|
| 7 |
<script src="https://js.puter.com/v2/"></script>
|
| 8 |
</head>
|
| 9 |
<body style="margin: 0; padding: 20px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background-color: #0b0b0f; color: #f1f1f3;">
|
|
|
|
| 11 |
|
| 12 |
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px;">
|
| 13 |
<h2 style="margin: 0; color: #fff; font-size: 20px;">Open-Generative-AI Studio</h2>
|
| 14 |
+
<button id="authBtn" onclick="handleAuth()" style="background: #2563eb; color: #fff; border: none; padding: 6px 12px; border-radius: 6px; font-size: 12px; cursor: pointer;">Sign In / Connect</button>
|
| 15 |
</div>
|
| 16 |
|
| 17 |
<div style="margin-bottom: 16px;">
|
|
|
|
| 21 |
|
| 22 |
<div style="display: flex; gap: 10px; margin-bottom: 20px;">
|
| 23 |
<button onclick="generateImage()" style="flex: 1; background: #7c3aed; color: #fff; border: none; padding: 10px; border-radius: 6px; font-size: 14px; font-weight: 600; cursor: pointer;">Generate Image</button>
|
| 24 |
+
<button onclick="generateText()" style="flex: 1; background: #2563eb; color: #fff; border: none; padding: 10px; border-radius: 6px; font-size: 14px; font-weight: 600; cursor: pointer;">Ask AI</button>
|
| 25 |
</div>
|
| 26 |
|
| 27 |
<label style="display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; color: #a1a1aa;">Output Result</label>
|
|
|
|
| 31 |
</div>
|
| 32 |
|
| 33 |
<script>
|
|
|
|
| 34 |
window.addEventListener('DOMContentLoaded', async () => {
|
| 35 |
+
try {
|
| 36 |
+
if (puter.auth.isSignedIn()) {
|
| 37 |
+
document.getElementById('authBtn').innerText = "Connected";
|
| 38 |
+
}
|
| 39 |
+
} catch (e) {
|
| 40 |
+
console.log("Auth check skipped");
|
| 41 |
}
|
| 42 |
});
|
| 43 |
|
| 44 |
+
async function handleAuth() {
|
| 45 |
+
try {
|
| 46 |
+
document.getElementById('authBtn').innerText = "Connecting...";
|
| 47 |
+
// Attempt standard sign-in popup
|
| 48 |
await puter.auth.signIn();
|
| 49 |
document.getElementById('authBtn').innerText = "Connected";
|
| 50 |
+
} catch (err) {
|
| 51 |
+
console.error(err);
|
| 52 |
+
document.getElementById('authBtn').innerText = "Sign In Failed";
|
| 53 |
+
alert("Popup was blocked or closed. Tip: Log into puter.com in another tab first, then return here and try again.");
|
| 54 |
}
|
| 55 |
}
|
| 56 |
|
|
|
|
| 63 |
return;
|
| 64 |
}
|
| 65 |
|
| 66 |
+
output.innerHTML = "Generating image...";
|
| 67 |
try {
|
|
|
|
| 68 |
const imgElement = await puter.ai.txt2img(prompt);
|
| 69 |
output.innerHTML = "";
|
| 70 |
imgElement.style.maxWidth = "100%";
|
| 71 |
imgElement.style.borderRadius = "6px";
|
| 72 |
output.appendChild(imgElement);
|
| 73 |
} catch (err) {
|
| 74 |
+
output.innerText = "Error: Please sign in first or check connection. (" + err + ")";
|
| 75 |
}
|
| 76 |
}
|
| 77 |
|
|
|
|
| 89 |
const response = await puter.ai.chat(prompt);
|
| 90 |
output.innerHTML = `<div style="text-align: left; width: 100%; white-space: pre-wrap;">${response}</div>`;
|
| 91 |
} catch (err) {
|
| 92 |
+
output.innerText = "Error: Please sign in first or check connection. (" + err + ")";
|
| 93 |
}
|
| 94 |
}
|
| 95 |
</script>
|