demo.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>G4F DEMO</title>
  7. <link rel="apple-touch-icon" sizes="180x180" href="/static/img/apple-touch-icon.png">
  8. <link rel="icon" type="image/png" sizes="32x32" href="/static/img/favicon-32x32.png">
  9. <link rel="icon" type="image/png" sizes="16x16" href="/static/img/favicon-16x16.png">
  10. <link rel="manifest" href="/static/img/site.webmanifest">
  11. <style>
  12. :root {
  13. --colour-1: #000000;
  14. --colour-2: #ccc;
  15. --colour-3: #e4d4ff;
  16. --colour-4: #f0f0f0;
  17. --colour-5: #181818;
  18. --colour-6: #242424;
  19. --accent: #8b3dff;
  20. --gradient: #1a1a1a;
  21. --background: #16101b;
  22. --size: 70vw;
  23. --top: 50%;
  24. --blur: 40px;
  25. --opacity: 0.6;
  26. }
  27. @import url("https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap");
  28. .gradient {
  29. position: absolute;
  30. z-index: -1;
  31. left: 50vw;
  32. border-radius: 50%;
  33. background: radial-gradient(circle at center, var(--accent), var(--gradient));
  34. width: var(--size);
  35. height: var(--size);
  36. top: var(--top);
  37. transform: translate(-50%, -50%);
  38. filter: blur(var(--blur)) opacity(var(--opacity));
  39. animation: zoom_gradient 6s infinite alternate;
  40. display: none;
  41. max-height: 100%;
  42. transition: max-height 0.25s ease-in;
  43. }
  44. .gradient.hidden {
  45. max-height: 0;
  46. transition: max-height 0.15s ease-out;
  47. }
  48. @media only screen and (min-width: 40em) {
  49. body .gradient{
  50. display: block;
  51. }
  52. }
  53. @keyframes zoom_gradient {
  54. 0% {
  55. transform: translate(-50%, -50%) scale(1);
  56. }
  57. 100% {
  58. transform: translate(-50%, -50%) scale(1.2);
  59. }
  60. }
  61. /* Body and text color */
  62. body {
  63. background: var(--background);
  64. color: var(--colour-3);
  65. font-family: "Inter", sans-serif;
  66. height: 100vh;
  67. margin: 0;
  68. padding: 0;
  69. overflow: hidden;
  70. font-weight: bold;
  71. }
  72. /* Container for the main content */
  73. .container {
  74. display: flex;
  75. flex-direction: column;
  76. justify-content: center;
  77. align-items: center;
  78. height: 100%;
  79. text-align: center;
  80. z-index: 1;
  81. }
  82. header {
  83. font-size: 3rem;
  84. text-transform: uppercase;
  85. margin: 20px;
  86. color: var(--colour-4);
  87. }
  88. iframe {
  89. background: transparent;
  90. width: 100%;
  91. border: none;
  92. }
  93. #background {
  94. height: 100%;
  95. position: absolute;
  96. z-index: -1;
  97. }
  98. .description, form p a {
  99. font-size: 1.2rem;
  100. margin-bottom: 30px;
  101. color: var(--colour-2);
  102. }
  103. .input-field {
  104. width: 80%;
  105. max-width: 400px;
  106. padding: 12px;
  107. margin: 10px 0;
  108. border: 2px solid var(--colour-6);
  109. background-color: var(--colour-5);
  110. color: var(--colour-3);
  111. border-radius: 8px;
  112. font-size: 1.1rem;
  113. }
  114. .input-field:focus {
  115. outline: none;
  116. border-color: var(--accent);
  117. }
  118. .button {
  119. background-color: var(--accent);
  120. color: var(--colour-3);
  121. border: none;
  122. padding: 15px 30px;
  123. font-size: 1.1rem;
  124. border-radius: 8px;
  125. cursor: pointer;
  126. transition: background-color 0.3s ease;
  127. margin-top: 15px;
  128. width: 100%;
  129. max-width: 400px;
  130. font-weight: bold;
  131. text-decoration: none;
  132. white-space: nowrap;
  133. }
  134. .button:hover {
  135. background-color: #7a2ccd;
  136. }
  137. .button-container {
  138. display: flex;
  139. flex-direction: row;
  140. align-items: center;
  141. gap: 10px;
  142. }
  143. .footer {
  144. margin-top: 30px;
  145. font-size: 0.9rem;
  146. color: var(--colour-2);
  147. }
  148. .hidden {
  149. display: none;
  150. }
  151. /* Animation for the gradient circle */
  152. @keyframes zoom_gradient {
  153. 0% {
  154. transform: translate(-50%, -50%) scale(1);
  155. }
  156. 100% {
  157. transform: translate(-50%, -50%) scale(1.5);
  158. }
  159. }
  160. </style>
  161. <script>
  162. (async () => {
  163. const isIframe = window.self !== window.top;
  164. const backendUrl = "{{backend_url}}";
  165. let url = new URL(window.location.href)
  166. let params = new URLSearchParams(url.search);
  167. if (isIframe && backendUrl) {
  168. if (params.get("get_gpu_token")) {
  169. window.addEventListener('DOMContentLoaded', async function() {
  170. const link = document.getElementById("new_window");
  171. link.href = `${backendUrl}${url.search}`;
  172. link.click();
  173. });
  174. } else {
  175. window.location.replace(`${backendUrl}${url.search}`);
  176. }
  177. return;
  178. }
  179. if (params.get("__sign")) {
  180. localStorage.setItem("HuggingSpace-api_key", params.get("__sign"));
  181. if (!isIframe) {
  182. window.location.replace("/");
  183. }
  184. }
  185. })();
  186. </script>
  187. <script src="https://unpkg.com/es-module-shims@1.7.0/dist/es-module-shims.js"></script>
  188. <script type="importmap">
  189. {
  190. "imports": {
  191. "@huggingface/hub": "https://cdn.jsdelivr.net/npm/@huggingface/hub@0.21.0/+esm",
  192. "@huggingface/space-header": "https://cdn.jsdelivr.net/npm/@huggingface/space-header/+esm"
  193. }
  194. }
  195. </script>
  196. </head>
  197. <body>
  198. <iframe id="background"></iframe>
  199. <!-- Gradient Background Circle -->
  200. <div class="gradient"></div>
  201. <!-- Main Content -->
  202. <div class="container">
  203. <header>
  204. G4F DEMO
  205. </header>
  206. <div class="description">
  207. Welcome to the G4F Web UI! <br>
  208. Your AI assistant is ready to assist you.
  209. </div>
  210. <!-- Input and Button -->
  211. <form action="/chat/">
  212. <input type="text" name="token" class="input-field" placeholder="Enter an Access Token..." autocomplete="off">
  213. <div class="button-container">
  214. <a id="new_window" href="" class="button hidden" target="_blank">New Window</a>
  215. <button class="button">Submit</button>
  216. </div>
  217. <p>
  218. <a href="https://huggingface.co/settings/tokens" target="_blank">Get Access Token</a>
  219. </p>
  220. </form>
  221. <script type="module">
  222. import * as hub from "@huggingface/hub";
  223. import { init } from "@huggingface/space-header";
  224. const isIframe = window.self !== window.top;
  225. const button = document.querySelector('form a.button');
  226. if (isIframe) {
  227. button.classList.remove('hidden');
  228. } else {
  229. init("roxky/g4f-space-new");
  230. }
  231. const form = document.querySelector("form");
  232. const input = document.querySelector('form input[name="token"]');
  233. async function check_access_token() {
  234. const accessToken = input.value || localStorage.getItem("HuggingFace-api_key");
  235. if (!accessToken) {
  236. return;
  237. }
  238. let user;
  239. try {
  240. user = await hub.whoAmI({accessToken: accessToken});
  241. } catch(e) {
  242. console.log(e);
  243. input.setCustomValidity("Invalid Access Token.");
  244. return;
  245. }
  246. localStorage.setItem("HuggingFace-api_key", accessToken);
  247. localStorage.setItem("HuggingFace-user", JSON.stringify(user));
  248. localStorage.setItem("user", user.name);
  249. localStorage.setItem("report_error", "true")
  250. location.href = "/chat/";
  251. }
  252. input.addEventListener("input", () => check_access_token());
  253. input.addEventListener("click", () => check_access_token());
  254. form.addEventListener("submit", async (event) => {
  255. event.preventDefault();
  256. check_access_token();
  257. });
  258. </script>
  259. <!-- Footer -->
  260. <div class="footer">
  261. <p>&copy; 2025 G4F. All Rights Reserved.</p>
  262. <p>Powered by the G4F framework</p>
  263. </div>
  264. </div>
  265. <script>
  266. (async () => {
  267. const today = new Date().toJSON().slice(0, 10);
  268. const max = 5;
  269. const cache_id = Math.floor(Math.random() * max);
  270. let prompt;
  271. if (cache_id % 2 == 0) {
  272. prompt = `Today is ${new Date().toJSON().slice(0, 10)}.
  273. Create a single-page HTML screensaver reflecting the current season (based on the date).
  274. Avoid using any text.`;
  275. } else {
  276. prompt = `Create a single-page HTML screensaver. Avoid using any text.`;
  277. }
  278. const response = await fetch(`/backend-api/v2/create?prompt=${prompt}&filter_markdown=html&cache=${cache_id}`);
  279. const text = await response.text()
  280. background.src = `data:text/html;charset=utf-8,${encodeURIComponent(text)}`;
  281. const gradient = document.querySelector('.gradient');
  282. gradient.classList.add('hidden');
  283. })();
  284. </script>
  285. </body>
  286. </html>