Spaces:
Paused
Paused
Commit
•
65a0a47
1
Parent(s):
5ff1b90
working on the API
Browse files- src/gaussian-splatting.mts +1 -1
- src/index.mts +29 -7
src/gaussian-splatting.mts
CHANGED
@@ -3,7 +3,7 @@ import { exec } from "child_process"
|
|
3 |
/**
|
4 |
* Interface for the options for the `runGaussianSplattingCUDA` function.
|
5 |
*/
|
6 |
-
interface Options {
|
7 |
/**
|
8 |
* Data path for the training data.
|
9 |
*/
|
|
|
3 |
/**
|
4 |
* Interface for the options for the `runGaussianSplattingCUDA` function.
|
5 |
*/
|
6 |
+
export interface Options {
|
7 |
/**
|
8 |
* Data path for the training data.
|
9 |
*/
|
src/index.mts
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
-
console.log("splatter-api is booting up")
|
2 |
-
|
3 |
import express from "express"
|
4 |
|
|
|
|
|
5 |
import { initFolders } from "./initFolders.mts"
|
6 |
|
7 |
initFolders()
|
@@ -9,15 +9,36 @@ initFolders()
|
|
9 |
const app = express()
|
10 |
const port = 7860
|
11 |
|
12 |
-
const
|
13 |
-
|
14 |
|
15 |
app.use(express.json({limit: '50mb'}))
|
16 |
app.use(express.urlencoded({limit: '50mb', extended: true}))
|
17 |
|
18 |
app.post("/", async (req, res) => {
|
19 |
-
|
20 |
-
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
app.get("/", async (req, res) => {
|
23 |
// this is what users will see in the space - but no need to show something scary
|
@@ -28,4 +49,5 @@ Splatter API is a micro-service used to generate gaussian splatting scenes.
|
|
28 |
res.end()
|
29 |
})
|
30 |
|
31 |
-
app.listen(port, () => { console.log(`Open http://localhost:${port}`) })
|
|
|
|
|
|
|
|
1 |
import express from "express"
|
2 |
|
3 |
+
import { runGaussianSplattingCUDA, Options } from "./gaussian-splatting.mts"
|
4 |
+
|
5 |
import { initFolders } from "./initFolders.mts"
|
6 |
|
7 |
initFolders()
|
|
|
9 |
const app = express()
|
10 |
const port = 7860
|
11 |
|
12 |
+
const maxActiveRequests = 4
|
13 |
+
let activeRequests = 0
|
14 |
|
15 |
app.use(express.json({limit: '50mb'}))
|
16 |
app.use(express.urlencoded({limit: '50mb', extended: true}))
|
17 |
|
18 |
app.post("/", async (req, res) => {
|
19 |
+
if(activeRequests >= maxActiveRequests) {
|
20 |
+
res.status(503).json({message: "Service Unavailable: Max concurrent requests reached. Please try again later"}).end();
|
21 |
+
return
|
22 |
+
}
|
23 |
+
activeRequests++
|
24 |
+
|
25 |
+
let options: Options = req.body // Assuming the body contains the options
|
26 |
+
|
27 |
+
try {
|
28 |
+
const result = await runGaussianSplattingCUDA(options);
|
29 |
+
res.status(200).json({
|
30 |
+
success: true,
|
31 |
+
message: result
|
32 |
+
}).end();
|
33 |
+
} catch (error) {
|
34 |
+
res.status(500).json({
|
35 |
+
error: "Couldn't generate gaussian splatting scene",
|
36 |
+
message: error
|
37 |
+
}).end()
|
38 |
+
}
|
39 |
+
|
40 |
+
activeRequests--
|
41 |
+
});
|
42 |
|
43 |
app.get("/", async (req, res) => {
|
44 |
// this is what users will see in the space - but no need to show something scary
|
|
|
49 |
res.end()
|
50 |
})
|
51 |
|
52 |
+
app.listen(port, () => { console.log(`Open http://localhost:${port}`) })
|
53 |
+
|