hadadrjt commited on
Commit
1dfeea6
·
1 Parent(s): 5de0892

ai: Load playground.

Browse files
Files changed (8) hide show
  1. .gitattributes +7 -1
  2. Dockerfile +11 -40
  3. LICENSE +0 -22
  4. README.md +3 -5
  5. assets/images/favicon.ico +0 -0
  6. index.js +208 -0
  7. package.json +17 -0
  8. src/database/webui.db +0 -3
.gitattributes CHANGED
@@ -33,4 +33,10 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
- *.db filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ dist/** filter=lfs diff=lfs merge=lfs -text
37
+ build/** filter=lfs diff=lfs merge=lfs -text
38
+ .out/** filter=lfs diff=lfs merge=lfs -text
39
+ .next/** filter=lfs diff=lfs merge=lfs -text
40
+ coverage/** filter=lfs diff=lfs merge=lfs -text
41
+ logs/** filter=lfs diff=lfs merge=lfs -text
42
+ *.log filter=lfs diff=lfs merge=lfs -text
Dockerfile CHANGED
@@ -1,51 +1,22 @@
1
  #
2
  # SPDX-FileCopyrightText: Hadad <hadad@linuxmail.org>
3
- # SPDX-License-Identifier: MIT
4
  #
5
 
6
- # Use a specific container image for the application
7
  FROM hadadrjt/ai:latest
8
 
9
  # Set the main working directory inside the container
10
- WORKDIR /app/backend
11
 
12
- # Copy the database file into the container
13
- # This database is a placeholder or dummy,
14
- # and the core configuration is located in the Environment
15
- # and Secret Environment settings of Hugging Face Spaces.
16
- COPY --chown=$UID:$GID src/database/webui.db /app/backend/data/
17
 
18
- # Set the database permission
19
- RUN chmod 777 /app/backend/data/webui.db
20
 
21
- # Search Engine Optimization (SEO)
22
- # Robots Exclusion Protocol
23
- RUN search='<meta name="robots" content="noindex,nofollow"' && \
24
- replace='<meta name="robots" content="index,follow"' && \
25
- find /app -type f -name '*.html' -exec grep -l "$search" {} \; | \
26
- while IFS= read -r file; do \
27
- echo "Processing: $file" && \
28
- if sed -i "s|$search|$replace|g" "$file"; then \
29
- echo "Success: $file updated"; \
30
- else \
31
- echo "Error: failed to update $file"; \
32
- exit 1; \
33
- fi; \
34
- done
35
- # https://umint-ai.hf.space/robots.txt
36
- COPY --chown=$UID:$GID src/crawlers/robots.txt /app/build/
37
- # Sitemaps
38
- # https://umint-ai.hf.space/sitemap.xml
39
- COPY --chown=$UID:$GID src/crawlers/sitemap.xml /app/build/
40
- # Google Search Console Tools
41
- # https://umint-ai.hf.space/google15aba15fe250d693.html
42
- COPY --chown=$UID:$GID src/webmasters/google.html /app/build/google15aba15fe250d693.html
43
- # Bing Webmaster Tools
44
- # https://umint-ai.hf.space/BingSiteAuth.xml
45
- COPY --chown=$UID:$GID src/webmasters/bing.xml /app/build/BingSiteAuth.xml
46
 
47
- # Open the port so the application can be accessed
48
- EXPOSE 8000
49
-
50
- # Start the application using the startup script
51
- CMD ["bash", "start.sh"]
 
1
  #
2
  # SPDX-FileCopyrightText: Hadad <hadad@linuxmail.org>
3
+ # SPDX-License-Identifier: Apache-2.0
4
  #
5
 
6
+ # Use a specific container image for the sever
7
  FROM hadadrjt/ai:latest
8
 
9
  # Set the main working directory inside the container
10
+ WORKDIR /node
11
 
12
+ # Copy all files into the container
13
+ COPY . .
 
 
 
14
 
15
+ # Install all dependencies
16
+ RUN npm install
17
 
18
+ # Open the port so the web can be accessed
19
+ EXPOSE 7860
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
+ # Start the server
22
+ CMD ["npm", "start"]
 
 
 
LICENSE DELETED
@@ -1,22 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 pollinations
4
- Copyright (c) 2025 Hadad <hadad@linuxmail.org>
5
-
6
- Permission is hereby granted, free of charge, to any person obtaining a copy
7
- of this software and associated documentation files (the "Software"), to deal
8
- in the Software without restriction, including without limitation the rights
9
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- copies of the Software, and to permit persons to whom the Software is
11
- furnished to do so, subject to the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be included in all
14
- copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- SOFTWARE.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md CHANGED
@@ -1,12 +1,12 @@
1
  ---
2
  title: UltimaX Intelligence
3
  short_description: Premium AI | Tools | Code Interpreter | Web Generator | etc
4
- license: mit
5
  emoji: ⚡
6
  colorFrom: purple
7
  colorTo: green
8
  sdk: docker
9
- app_port: 8000
10
  pinned: true
11
  thumbnail: >-
12
  https://cdn-uploads.huggingface.co/production/uploads/686e28b405d4ddcdd96adeb2/i9iufR3L-rgj39mk_B9QW.jpeg
@@ -56,6 +56,4 @@ models:
56
  - Qwen/Qwen3-235B-A22B-Thinking-2507
57
  - zai-org/GLM-4.5
58
  - zai-org/GLM-4.5-Air
59
- ---
60
-
61
- This service is powered by the [Pollinations](https://github.com/pollinations/pollinations) open-source AI community.
 
1
  ---
2
  title: UltimaX Intelligence
3
  short_description: Premium AI | Tools | Code Interpreter | Web Generator | etc
4
+ license: apache-2.0
5
  emoji: ⚡
6
  colorFrom: purple
7
  colorTo: green
8
  sdk: docker
9
+ app_port: 7860
10
  pinned: true
11
  thumbnail: >-
12
  https://cdn-uploads.huggingface.co/production/uploads/686e28b405d4ddcdd96adeb2/i9iufR3L-rgj39mk_B9QW.jpeg
 
56
  - Qwen/Qwen3-235B-A22B-Thinking-2507
57
  - zai-org/GLM-4.5
58
  - zai-org/GLM-4.5-Air
59
+ ---
 
 
assets/images/favicon.ico ADDED
index.js ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ //
2
+ // SPDX-FileCopyrightText: Hadad <hadad@linuxmail.org>
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ //
5
+
6
+ import express from "express";
7
+ import http from "http";
8
+ import { WebSocketServer } from "ws";
9
+ import fetch from "node-fetch";
10
+ import cookieParser from "cookie-parser";
11
+ import path from "path";
12
+
13
+ const app = express();
14
+ const server = http.createServer(app);
15
+ const wss = new WebSocketServer({ server });
16
+ const OPENAI_API_BASE_URL = process.env.OPENAI_API_BASE_URL || "";
17
+ const OPENAI_API_KEY = process.env.OPENAI_API_KEY || "";
18
+ const UMINT = process.env.UMINT || ``;
19
+
20
+ app.use(cookieParser());
21
+
22
+ // Root endpoint.
23
+ app.get("/", (_req, res) => res.send(UMINT));
24
+
25
+ // Search Engine Optimization (SEO).
26
+ // Robots Exclusion Protocol.
27
+ app.get("/robots.txt", (_req, res) => {
28
+ res.sendFile(path.resolve("src/crawlers/robots.txt"));
29
+ }); // https://umint-ai.hf.space/robots.txt
30
+ // Sitemaps.
31
+ app.get("/sitemap.xml", (_req, res) => {
32
+ res.sendFile(path.resolve("src/crawlers/sitemap.xml"));
33
+ }); // https://umint-ai.hf.space/sitemap.xml
34
+ // Google Search Console Tools.
35
+ app.get("/google15aba15fe250d693.html", (_req, res) => {
36
+ res.sendFile(path.resolve("src/webmasters/google.html"));
37
+ }); // https://umint-ai.hf.space/google15aba15fe250d693.html
38
+ // Bing Webmaster Tools.
39
+ app.get("/BingSiteAuth.xml", (_req, res) => {
40
+ res.sendFile(path.resolve("src/webmasters/bing.xml"));
41
+ }); // https://umint-ai.hf.space/BingSiteAuth.xml
42
+ // End of SEO.
43
+
44
+ // Favicon.
45
+ app.get("/assets/images/favicon.ico", (_req, res) => {
46
+ res.sendFile(path.resolve("assets/images/favicon.ico"));
47
+ });
48
+
49
+ wss.on("connection", (ws) => {
50
+ // Abort controller for the currently active streaming request.
51
+ let currentAbortController = null;
52
+
53
+ // Handle incoming messages from the WebSocket client.
54
+ ws.on("message", async (msg) => {
55
+ try {
56
+ const data = JSON.parse(msg.toString());
57
+
58
+ // Handle explicit stop request from client.
59
+ if (data.type === "stop") {
60
+ if (currentAbortController) {
61
+ // Abort the active fetch request to stop streaming.
62
+ currentAbortController.abort();
63
+ currentAbortController = null;
64
+ }
65
+ // Notify client that streaming ended.
66
+ ws.send(JSON.stringify({ type: "end" }));
67
+ return;
68
+ }
69
+
70
+ // Extract user message and optional history for context.
71
+ const message = data.message;
72
+ const history = data.history || [];
73
+ // Build messages array with history and the new user message.
74
+ const setup_messages = [...history, { role: "user", content: message }];
75
+
76
+ // Create a new AbortController to allow client to cancel the stream.
77
+ currentAbortController = new AbortController();
78
+ const signal = currentAbortController.signal;
79
+
80
+ // Send request to the Endpoint.
81
+ const request = await fetch(OPENAI_API_BASE_URL, {
82
+ method: "POST",
83
+ headers: {
84
+ "Content-Type": "application/json",
85
+ "Authorization": `Bearer ${OPENAI_API_KEY}`,
86
+ },
87
+ body: JSON.stringify({
88
+ model: "gpt-4.1-nano",
89
+ messages: setup_messages,
90
+ stream: true,
91
+ private: true,
92
+ isPrivate: true
93
+ }),
94
+ signal
95
+ });
96
+
97
+ // Handle non 2xx responses by returning an error to the client.
98
+ if (!request.ok) {
99
+ const errorData = await request.text();
100
+ ws.send(JSON.stringify({ type: "error", error: `HTTP ${request.status}: ${request.statusText} - ${errorData}` }));
101
+ if (currentAbortController) {
102
+ currentAbortController.abort();
103
+ currentAbortController = null;
104
+ }
105
+ return;
106
+ }
107
+
108
+ // Get the response body stream to read incremental chunks.
109
+ const reader = request.body;
110
+ if (!reader) {
111
+ ws.send(JSON.stringify({ type: "error", error: "Response body is empty" }));
112
+ if (currentAbortController) {
113
+ currentAbortController.abort();
114
+ currentAbortController = null;
115
+ }
116
+ return;
117
+ }
118
+
119
+ // Buffer partial data between streamed chunks.
120
+ let buffer = "";
121
+ try {
122
+ // Iterate over stream chunks as they arrive.
123
+ for await (const chunk of reader) {
124
+ // If client requested abort, stop processing and inform the client.
125
+ if (signal.aborted) {
126
+ ws.send(JSON.stringify({ type: "end" }));
127
+ if (currentAbortController) {
128
+ currentAbortController.abort();
129
+ currentAbortController = null;
130
+ }
131
+ return;
132
+ }
133
+
134
+ // Append raw chunk text to the buffer.
135
+ buffer += chunk.toString();
136
+
137
+ // Process full lines separated by newline characters.
138
+ let idx;
139
+ while ((idx = buffer.indexOf("\n")) !== -1) {
140
+ const line = buffer.slice(0, idx).trim();
141
+ buffer = buffer.slice(idx + 1);
142
+
143
+ if (line.startsWith("data: ")) {
144
+ const dataStr = line.substring(6).trim();
145
+ // Skip empty events and the stream terminator.
146
+ if (!dataStr || dataStr === "[DONE]") continue;
147
+ try {
148
+ // Parse JSON payload and extract incremental content.
149
+ const parsed = JSON.parse(dataStr);
150
+ const part = parsed?.choices?.[0]?.delta?.content;
151
+ if (part) {
152
+ // Send incremental chunk to the client.
153
+ ws.send(JSON.stringify({ type: "chunk", chunk: part }));
154
+ }
155
+ } catch (parseError) {
156
+ // Log parsing errors for debugging.
157
+ console.error("Error parsing JSON:", parseError, "Data string:", dataStr);
158
+ }
159
+ }
160
+ }
161
+ }
162
+ } catch (logs) {
163
+ // If the fetch was aborted by the client, signal end.
164
+ if (signal.aborted) {
165
+ ws.send(JSON.stringify({ type: "end" }));
166
+ } else {
167
+ // For unexpected stream errors, log and notify client.
168
+ console.error("Error:", logs);
169
+ ws.send(JSON.stringify({ type: "error", error: "Error: " + (logs && logs.message ? logs.message : String(logs)) }));
170
+ }
171
+ if (currentAbortController) {
172
+ currentAbortController.abort();
173
+ currentAbortController = null;
174
+ }
175
+ return;
176
+ }
177
+
178
+ // Normal end of stream, notify client.
179
+ ws.send(JSON.stringify({ type: "end" }));
180
+ if (currentAbortController) {
181
+ currentAbortController.abort();
182
+ currentAbortController = null;
183
+ }
184
+ } catch (e) {
185
+ // Catch JSON parse errors and other unexpected exceptions.
186
+ console.error("General error:", e);
187
+ ws.send(JSON.stringify({ type: "error", error: e.message || "An unknown error occurred" }));
188
+ if (currentAbortController) {
189
+ currentAbortController.abort();
190
+ currentAbortController = null;
191
+ }
192
+ }
193
+ });
194
+
195
+ // Ensure any active fetch is aborted when the WebSocket closes.
196
+ ws.on("close", () => {
197
+ if (currentAbortController) {
198
+ currentAbortController.abort();
199
+ currentAbortController = null;
200
+ }
201
+ });
202
+ });
203
+
204
+ const PORT = process.env.PORT || 7860;
205
+ // Start the HTTP and WebSocket server.
206
+ server.listen(PORT, () => {
207
+ console.log(`Server running on port ${PORT}`);
208
+ });
package.json ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "UltimaX Intelligence",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "start": "node index.js"
8
+ },
9
+ "dependencies": {
10
+ "express": "latest",
11
+ "http": "latest",
12
+ "ws": "latest",
13
+ "node-fetch": "latest",
14
+ "cookie-parser": "latest",
15
+ "path": "latest"
16
+ }
17
+ }
src/database/webui.db DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:a69bca9badf0df533af496629aee7a691c924a0085d87687d54cb25e2a6c0c48
3
- size 9211904