home.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  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 GUI</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. .stream-widget {
  99. max-height: 0;
  100. transition: max-height 0.15s ease-out;
  101. color: var(--colour-5);
  102. overflow: scroll;
  103. text-align: left;
  104. }
  105. .stream-widget.show {
  106. max-height: 1000px;
  107. height: 1000px;
  108. transition: max-height 0.25s ease-in;
  109. background: rgba(255,255,255,0.7);
  110. border-top: 2px solid rgba(255,255,255,0.5);
  111. padding: 20px;
  112. }
  113. .stream-widget img {
  114. max-width: 320px;
  115. }
  116. #stream-container {
  117. width: 100%;
  118. }
  119. .description {
  120. font-size: 1.2rem;
  121. margin-bottom: 30px;
  122. color: var(--colour-2);
  123. }
  124. .input-field {
  125. width: 80%;
  126. max-width: 400px;
  127. padding: 12px;
  128. margin: 10px 0;
  129. border: 2px solid var(--colour-6);
  130. background-color: var(--colour-5);
  131. color: var(--colour-3);
  132. border-radius: 8px;
  133. font-size: 1.1rem;
  134. }
  135. .input-field:focus {
  136. outline: none;
  137. border-color: var(--accent);
  138. }
  139. .button {
  140. background-color: var(--accent);
  141. color: var(--colour-3);
  142. border: none;
  143. padding: 15px 30px;
  144. font-size: 1.1rem;
  145. border-radius: 8px;
  146. cursor: pointer;
  147. transition: background-color 0.3s ease;
  148. margin-top: 15px;
  149. width: 100%;
  150. max-width: 400px;
  151. font-weight: bold;
  152. }
  153. .button:hover {
  154. background-color: #7a2ccd;
  155. }
  156. .footer {
  157. margin-top: 30px;
  158. font-size: 0.9rem;
  159. color: var(--colour-2);
  160. }
  161. /* Animation for the gradient circle */
  162. @keyframes zoom_gradient {
  163. 0% {
  164. transform: translate(-50%, -50%) scale(1);
  165. }
  166. 100% {
  167. transform: translate(-50%, -50%) scale(1.5);
  168. }
  169. }
  170. </style>
  171. <script src="https://cdn.jsdelivr.net/npm/markdown-it@13.0.1/dist/markdown-it.min.js"></script>
  172. </head>
  173. <body>
  174. <iframe id="background"></iframe>
  175. <!-- Gradient Background Circle -->
  176. <div class="gradient"></div>
  177. <!-- Main Content -->
  178. <div class="container">
  179. <header>
  180. G4F GUI
  181. </header>
  182. <div class="description">
  183. Welcome to the G4F GUI! <br>
  184. Your AI assistant is ready to assist you.
  185. </div>
  186. <!-- Input and Button -->
  187. <form action="/chat/">
  188. <input type="text" name="prompt" class="input-field" placeholder="Enter your query...">
  189. <button class="button">Open Chat</button>
  190. </form>
  191. <!-- Footer -->
  192. <div class="footer">
  193. <p>&copy; 2025 G4F. All Rights Reserved.</p>
  194. <p>Powered by the G4F framework</p>
  195. </div>
  196. <iframe class="stream-widget" frameborder="0"></iframe>
  197. </div>
  198. <script>
  199. const iframe = document.querySelector('.stream-widget');
  200. const rand_idx = Math.floor(Math.random() * 9)
  201. if (rand_idx < 3) {
  202. search = "xtekky/gpt4free releases";
  203. } else if (rand_idx < 5) {
  204. search = "developer news";
  205. } else {
  206. search = (navigator.language == "de" ? "news in deutsch" : navigator.language == "en" ? "world news" : `news in ${navigator.language}`);
  207. }
  208. const summary_prompt = "Give a summary of the provided text in ```markdown``` format. Add maybe one or more images.";
  209. const url = `/backend-api/v2/create?prompt=${summary_prompt}&stream=1&web_search=${search}`;
  210. iframe.src = url;
  211. const message = "Loading...";
  212. setTimeout(()=>{
  213. iframe.classList.add('show');
  214. const iframeDocument = iframe.contentDocument || iframe.contentWindow?.document;
  215. if (iframeDocument) {
  216. const iframeBody = iframeDocument.querySelector("body");
  217. if (iframeBody) {
  218. iframeBody.innerHTML = message + iframeBody.innerHTML;
  219. }
  220. } else {
  221. iframe.parentElement.removeChild(iframe);
  222. }
  223. }, 1000);
  224. function filterMarkdown(text, allowedTypes = null, defaultValue = null) {
  225. const match = text.match(/```(.+)\n(?<code>[\s\S]+?)(\n```|$)/);
  226. if (match) {
  227. const [, type, code] = match;
  228. if (!allowedTypes || allowedTypes.includes(type)) {
  229. return code;
  230. }
  231. }
  232. return defaultValue;
  233. }
  234. let scroll_to_bottom_callback = () => {
  235. const i = document.querySelector(".stream-widget");
  236. if (!i.contentWindow || !i.contentDocument) {
  237. return;
  238. }
  239. clientHeight = i.contentDocument.body.scrollHeight;
  240. i.contentWindow.scrollTo(0, clientHeight);
  241. if (clientHeight - i.contentWindow.scrollY < 2 * clientHeight) {
  242. setTimeout(scroll_to_bottom_callback, 1000);
  243. }
  244. };
  245. setTimeout(scroll_to_bottom_callback, 1000);
  246. iframe.onload = () => {
  247. const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;
  248. const iframeContent = iframeDocument.querySelector("pre");
  249. let iframeText = iframeContent.innerHTML;
  250. const markdown = window.markdownit();
  251. const iframeContainer = document.querySelector(".container");
  252. iframe.remove()
  253. if (iframeText.indexOf('"error"') < 0) {
  254. iframeContainer.innerHTML += `<div class="stream-widget show">${markdown.render(filterMarkdown(iframeText, "markdown", iframeText))}</div>`;
  255. }
  256. scroll_to_bottom_callback = () => null;
  257. }
  258. (async () => {
  259. const today = new Date().toJSON().slice(0, 10);
  260. const max = 5;
  261. const cache_id = Math.floor(Math.random() * max);
  262. let prompt;
  263. if (cache_id % 2 == 0) {
  264. prompt = `
  265. Today is ${new Date().toJSON().slice(0, 10)}.
  266. Create a single-page HTML screensaver reflecting the current season (based on the date).
  267. Avoid using any text.`;
  268. } else {
  269. prompt = `Create a single-page HTML screensaver. Avoid using any text.`;
  270. const response = await fetch(`/backend-api/v2/create?prompt=${prompt}&filter_markdown=html&cache=${cache_id}`);
  271. }
  272. const response = await fetch(`/backend-api/v2/create?prompt=${prompt}&filter_markdown=html&cache=${cache_id}`);
  273. const text = await response.text()
  274. background.src = `data:text/html;charset=utf-8,${encodeURIComponent(text)}`;
  275. const gradient = document.querySelector('.gradient');
  276. gradient.classList.add('hidden');
  277. })();
  278. </script>
  279. </body>
  280. </html>