rrg92 commited on
Commit
b1cbef8
·
1 Parent(s): d74cb9e
Files changed (5) hide show
  1. Caddyfile +9 -0
  2. Dockerfile +9 -0
  3. README.md +1 -0
  4. app/index.js +72 -0
  5. docker-compose.yml +5 -0
Caddyfile ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ https://localhost:3000 {
2
+ tls internal # gera cert self-signed automático p/ *.localhost
3
+ reverse_proxy * http://localhost:8080
4
+
5
+ log {
6
+ output stdout
7
+ format json
8
+ }
9
+ }
Dockerfile ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ FROM node:22-alpine
2
+
3
+ WORKDIR app
4
+ RUN npm i express
5
+ RUN npm i @gradio/client
6
+
7
+ COPY ./app ./app
8
+
9
+ CMD ["node","app"]
README.md CHANGED
@@ -5,6 +5,7 @@ colorFrom: gray
5
  colorTo: indigo
6
  sdk: docker
7
  pinned: false
 
8
  ---
9
 
10
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
5
  colorTo: indigo
6
  sdk: docker
7
  pinned: false
8
+ app_port: 8080
9
  ---
10
 
11
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app/index.js ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import express from 'express';
2
+ const app = express()
3
+ const port = 8080
4
+ import { Client } from "@gradio/client";
5
+
6
+
7
+
8
+ process.on('uncaughtException', err => log('Exception:', err))
9
+
10
+ app.use(express.json());
11
+
12
+ function log(m){
13
+ let d = new Date();
14
+ let diso = d.toISOString();
15
+
16
+ console.log(`${diso} ${m}`)
17
+ }
18
+
19
+
20
+ let SpaceSql = null;
21
+
22
+ app.post('/v1/embeddings', async (req, res) => {
23
+
24
+ console.log(req.body);
25
+
26
+ let model = req.body.model;
27
+ let text = req.body.input;
28
+
29
+ if(SpaceSql == null){
30
+ SpaceSql = await Client.connect("rrg92/sqlserver-lib-assistant")
31
+ }
32
+
33
+ let result = await SpaceSql.predict("/embed",{
34
+ text: text
35
+ }
36
+ )
37
+ console.log()
38
+
39
+ res.json({
40
+ object: "list"
41
+ ,data: [{
42
+ object: "embeddings"
43
+ ,embedding: JSON.parse(result.data[0])
44
+ ,index:0
45
+ }]
46
+ ,model
47
+ ,usage:{
48
+ prompt_tokens: 0
49
+ ,total_tokens: 0
50
+ }
51
+ })
52
+ })
53
+
54
+ app.get("/test", async (req,res) =>{
55
+
56
+
57
+
58
+ })
59
+
60
+ app.get('/', async (req, res) => {
61
+ res.send('on!')
62
+ })
63
+
64
+ app.use(function(err, req, res, next) {
65
+ console.error(err.stack);
66
+ res.json({error:'Server error, admin must check logs',status:res.status})
67
+ });
68
+
69
+
70
+ app.listen(port, () => {
71
+ log(`Server started`)
72
+ })
docker-compose.yml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ services:
2
+ app:
3
+ build: .
4
+ ports:
5
+ - 8080:8080