-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
335 lines (306 loc) · 11.6 KB
/
index.html
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>G4F - Framework</title>
<link rel="apple-touch-icon" sizes="180x180" href="dist/img/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="dist/img/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="dist/img/favicon-16x16.png">
<link rel="manifest" href="dist/img/site.webmanifest">
<style>
:root {
--colour-1: #000000;
--colour-2: #ccc;
--colour-3: #e4d4ff;
--colour-4: #f0f0f0;
--colour-5: #181818;
--colour-6: #242424;
--accent: #8b3dff;
--gradient: #1a1a1a;
--background: #16101b;
--size: 70vw;
--top: 50%;
--blur: 40px;
--opacity: 0.6;
}
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap");
/* Body and text color */
body {
background: var(--background);
color: var(--colour-3);
font-family: "Inter", sans-serif;
height: 100vh;
margin: 0;
padding: 0;
overflow: hidden;
font-weight: bold;
}
/* Container for the main content */
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100%;
text-align: center;
z-index: 1;
transition: transform 0.25s ease-in;
}
.container.slide {
transform: translateX(-100%);
transition: transform 0.15s ease-out;
}
.slide-button {
position: absolute;
top: 20px;
left: 20px;
background: var(--colour-4);
border: none;
border-radius: 4px;
cursor: pointer;
padding: 6px 8px;
}
header {
font-size: 3rem;
text-transform: uppercase;
margin: 20px;
color: var(--colour-4);
}
iframe {
background: transparent;
width: 100%;
border: none;
}
#background {
height: 100%;
position: absolute;
object-fit: cover;
object-position: center;
width: 100%;
background: black;
}
.container * {
z-index: 2;
}
.description, form p a {
font-size: 1.2rem;
margin-bottom: 30px;
color: var(--colour-2);
}
.input-field {
width: 80%;
max-width: 400px;
padding: 12px;
margin: 10px 0;
border: 2px solid var(--colour-6);
background-color: var(--colour-5);
color: var(--colour-3);
border-radius: 8px;
font-size: 1.1rem;
}
.input-field:focus {
outline: none;
border-color: var(--accent);
}
.button {
background-color: var(--accent);
color: var(--colour-3);
border: none;
padding: 15px 30px;
font-size: 1.1rem;
border-radius: 8px;
cursor: pointer;
transition: background-color 0.3s ease;
margin-top: 15px;
width: 100%;
max-width: 400px;
font-weight: bold;
text-decoration: none;
white-space: nowrap;
}
.button:hover {
background-color: #7a2ccd;
}
.button-container {
display: flex;
flex-direction: row;
align-items: center;
gap: 10px;
}
.footer {
margin-top: 30px;
font-size: 0.9rem;
color: var(--colour-2);
}
.hidden {
display: none;
}
</style>
<link rel="stylesheet" href="dist/css/all.min.css">
<script src="dist/js/framework.js"></script>
<script src="https://unpkg.com/es-module-shims@1.7.0/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"@huggingface/hub": "https://cdn.jsdelivr.net/npm/@huggingface/hub@0.21.0/+esm"
}
}
</script>
</head>
<body>
<iframe id="background" src="background.html"></iframe>
<button class="slide-button">
<i class="fa-solid fa-arrow-left"></i>
</button>
<!-- Main Content -->
<div class="container">
<header>
G4F - Framework
</header>
<div class="description">
<span>Welcome to the G4F Web UI!</span><br>
<span>Your AI assistant is ready to assist you.</span>
</div>
<div class="connected">
<p><strong>Connected to:</strong><span> </span><span id="connect_status">...</span></p>
</div>
<!-- Input and Button -->
<form action="chat/">
<input type="text" name="token" class="input-field" placeholder="Enter an Access Token..." autocomplete="off">
<div class="button-container">
<a id="new_window" href="" class="button hidden" target="_blank">New Window</a>
<button class="button">Submit</button>
</div>
<p>
<a href="https://huggingface.co/settings/tokens" target="_blank">Get Access Token</a>
</p>
<img src="https://huggingface.co/datasets/huggingface/badges/resolve/main/sign-in-with-huggingface-xl-dark.svg" alt="Sign in with Hugging Face" style="cursor: pointer; display: none;" id="signin">
<button id="signout" style="display: none">Sign out</button>
</form>
<script type="module">
import * as hub from "@huggingface/hub";
import { oauthLoginUrl, oauthHandleRedirectIfPresent } from "@huggingface/hub";
window.connectToBackend();
window.addEventListener('load', async function() {
if (!localStorage.getItem(window.translationKey)) {
try {
if (await translateAll()) {
window.location.reload();
}
} catch (e) {
console.debug(e);
}
}
});
const isIframe = window.self !== window.top;
const button = document.querySelector('form a.button');
if (isIframe) {
button.classList.remove('hidden');
}
const form = document.querySelector("form");
const input = document.querySelector('form input[name="token"]');
async function check_access_token() {
const accessToken = input.value || localStorage.getItem("HuggingFace-api_key");
if (!accessToken) {
return;
}
let user;
try {
user = await hub.whoAmI({accessToken: accessToken});
} catch(e) {
console.log(e);
input.setCustomValidity("Invalid Access Token.");
localStorage.removeItem("HuggingFace-api_key");
if (localStorage.getItem("oauth")) {
localStorage.removeItem("oauth");
window.location.replace("/");
}
return;
}
localStorage.setItem("HuggingFace-api_key", accessToken);
localStorage.setItem("user", user.name);
localStorage.setItem("report_error", "true")
location.href = "chat/";
}
input.addEventListener("input", () => check_access_token());
input.addEventListener("click", () => check_access_token());
form.addEventListener("submit", async (event) => {
check_access_token();
});
let oauthResult = localStorage.getItem("oauth");
if (oauthResult) {
let user;
try {
oauthResult = JSON.parse(oauthResult);
user = await hub.whoAmI({accessToken: oauthResult.accessToken});
} catch (e) {
console.error(e);
oauthResult = null;
localStorage.removeItem("oauth");
localStorage.removeItem("HuggingFace-api_key");
}
}
oauthResult ||= await oauthHandleRedirectIfPresent();
if (oauthResult) {
localStorage.setItem("oauth", JSON.stringify(oauthResult));
localStorage.setItem("HuggingFace-api_key", oauthResult.accessToken);
localStorage.setItem("user", oauthResult.userInfo.fullname);
document.getElementById("signout").style.removeProperty("display");
document.getElementById("signout").onclick = async function() {
localStorage.removeItem("oauth");
localStorage.removeItem("HuggingFace-api_key");
window.location.replace("/");
}
} else {
localStorage.removeItem("oauth");
document.getElementById("signin").style.removeProperty("display");
document.getElementById("signin").onclick = async function() {
window.location.href = (await oauthLoginUrl(window.oauthConfig));
}
}
</script>
<!-- Footer -->
<div class="footer">
<p>© 2025 G4F. All Rights Reserved.</p>
<p>Powered by the G4F framework</p>
</div>
</div>
<script>
(async () => {
// const today = new Date().toJSON().slice(0, 10);
// const max = 6;
// const cache_id = Math.floor(Math.random() * max);
// if (cache_id > 3) {
// let prompt;
// if (cache_id % 2 == 0) {
// prompt = `Today is ${new Date().toJSON().slice(0, 10)}.
// Create a single-page HTML screensaver reflecting the current season (based on the date).
// Avoid using any text.`;
// } else {
// prompt = `Create a single-page HTML screensaver. Avoid using any text.`;
// }
// const response = await fetch(`/backend-api/v2/create?prompt=${prompt}&filter_markdown=html&cache=${cache_id}`);
// const text = await response.text()
// if (text) {
// background.src = `data:text/html;charset=utf-8,${encodeURIComponent(text)}`;
// }
// }
const container = document.querySelector('.container');
const button = document.querySelector('.slide-button');
const slideIcon = button.querySelector('i');
button.onclick = () => {
if (container.classList.contains('slide')) {
container.classList.remove('slide');
slideIcon.classList.remove('fa-arrow-right');
slideIcon.classList.add('fa-arrow-left');
} else {
container.classList.add('slide');
slideIcon.classList.remove('fa-arrow-left');
slideIcon.classList.add('fa-arrow-right');
}
}
})();
</script>
</body>
</html>