Spaces:
Running
Running
Update index.html
Browse files- index.html +13 -27
index.html
CHANGED
|
@@ -23,7 +23,7 @@
|
|
| 23 |
width: 100%;
|
| 24 |
text-align: center;
|
| 25 |
}
|
| 26 |
-
h1 { color: #
|
| 27 |
select, input, button {
|
| 28 |
width: 100%;
|
| 29 |
padding: 12px;
|
|
@@ -34,19 +34,19 @@
|
|
| 34 |
font-size: 16px;
|
| 35 |
}
|
| 36 |
button {
|
| 37 |
-
background-color: #
|
| 38 |
color: white;
|
| 39 |
border: none;
|
| 40 |
font-weight: bold;
|
| 41 |
cursor: pointer;
|
| 42 |
}
|
| 43 |
-
button:hover { background-color: #
|
| 44 |
#output {
|
| 45 |
margin-top: 20px;
|
| 46 |
padding: 15px;
|
| 47 |
background: #f8f9fa;
|
| 48 |
border-radius: 8px;
|
| 49 |
-
border-left: 5px solid #
|
| 50 |
text-align: left;
|
| 51 |
min-height: 50px;
|
| 52 |
white-space: pre-wrap;
|
|
@@ -83,37 +83,23 @@ async function askAI() {
|
|
| 83 |
outputDiv.innerText = "🤖 Thinking...";
|
| 84 |
|
| 85 |
try {
|
| 86 |
-
//
|
| 87 |
-
const response = await fetch("https://
|
| 88 |
method: "POST",
|
| 89 |
headers: { "Content-Type": "application/json" },
|
| 90 |
body: JSON.stringify({
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
| 93 |
})
|
| 94 |
});
|
| 95 |
|
| 96 |
-
const
|
| 97 |
-
|
| 98 |
-
// Pick out the raw text answer generated by the model
|
| 99 |
-
let aiText = "";
|
| 100 |
-
if (Array.isArray(data) && data[0]?.generated_text) {
|
| 101 |
-
aiText = data[0].generated_text;
|
| 102 |
-
} else if (data?.generated_text) {
|
| 103 |
-
aiText = data.generated_text;
|
| 104 |
-
} else {
|
| 105 |
-
aiText = "The AI server is slightly busy. Try tapping send again!";
|
| 106 |
-
}
|
| 107 |
-
|
| 108 |
-
// Clean up formatting tags if they appear in the result
|
| 109 |
-
if (aiText.includes("<|im_start|>assistant\n")) {
|
| 110 |
-
aiText = aiText.split("<|im_start|>assistant\n").pop();
|
| 111 |
-
}
|
| 112 |
-
aiText = aiText.replace("<|im_end|>", "").replace("assistant", "");
|
| 113 |
-
|
| 114 |
outputDiv.innerText = aiText.trim();
|
| 115 |
} catch (error) {
|
| 116 |
-
outputDiv.innerText = "
|
| 117 |
}
|
| 118 |
}
|
| 119 |
</script>
|
|
|
|
| 23 |
width: 100%;
|
| 24 |
text-align: center;
|
| 25 |
}
|
| 26 |
+
h1 { color: #202124; margin-top: 0; }
|
| 27 |
select, input, button {
|
| 28 |
width: 100%;
|
| 29 |
padding: 12px;
|
|
|
|
| 34 |
font-size: 16px;
|
| 35 |
}
|
| 36 |
button {
|
| 37 |
+
background-color: #34a853;
|
| 38 |
color: white;
|
| 39 |
border: none;
|
| 40 |
font-weight: bold;
|
| 41 |
cursor: pointer;
|
| 42 |
}
|
| 43 |
+
button:hover { background-color: #2b8c44; }
|
| 44 |
#output {
|
| 45 |
margin-top: 20px;
|
| 46 |
padding: 15px;
|
| 47 |
background: #f8f9fa;
|
| 48 |
border-radius: 8px;
|
| 49 |
+
border-left: 5px solid #34a853;
|
| 50 |
text-align: left;
|
| 51 |
min-height: 50px;
|
| 52 |
white-space: pre-wrap;
|
|
|
|
| 83 |
outputDiv.innerText = "🤖 Thinking...";
|
| 84 |
|
| 85 |
try {
|
| 86 |
+
// Send request to an open, tokenless text-generation network
|
| 87 |
+
const response = await fetch("https://pollinations.ai", {
|
| 88 |
method: "POST",
|
| 89 |
headers: { "Content-Type": "application/json" },
|
| 90 |
body: JSON.stringify({
|
| 91 |
+
messages: [
|
| 92 |
+
{ role: "system", content: systemPrompt },
|
| 93 |
+
{ role: "user", content: input }
|
| 94 |
+
],
|
| 95 |
+
model: "openai"
|
| 96 |
})
|
| 97 |
});
|
| 98 |
|
| 99 |
+
const aiText = await response.text();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
outputDiv.innerText = aiText.trim();
|
| 101 |
} catch (error) {
|
| 102 |
+
outputDiv.innerText = "The public server is busy. Tap send one more time!";
|
| 103 |
}
|
| 104 |
}
|
| 105 |
</script>
|