Spaces:
Sleeping
Sleeping
Update README.md
Browse files
README.md
CHANGED
@@ -7,4 +7,77 @@ sdk: docker
|
|
7 |
pinned: false
|
8 |
---
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
pinned: false
|
8 |
---
|
9 |
|
10 |
+
# Prompt evolution below:
|
11 |
+
|
12 |
+
Add the ability to save and download the image snapshots which should be named with the result text from the ML model which creates a text caption. Name the output png file by the generated caption along with extension.png and add a date time string then show download links for this node program below:
|
13 |
+
|
14 |
+
```javascript
|
15 |
+
import express from "express";
|
16 |
+
import 'dotenv/config.js'
|
17 |
+
import { createServer } from "http";
|
18 |
+
import { Server } from "socket.io";
|
19 |
+
import { client } from "@gradio/client";
|
20 |
+
import { createRequire } from 'node:module'
|
21 |
+
const require = createRequire(import.meta.url);
|
22 |
+
global.EventSource = require('eventsource');
|
23 |
+
|
24 |
+
const app = express();
|
25 |
+
const httpServer = createServer(app);
|
26 |
+
app.use(express.static('public'));
|
27 |
+
const io = new Server(httpServer, { /* options */ });
|
28 |
+
|
29 |
+
io.on("connection", (socket) => {
|
30 |
+
|
31 |
+
console.log("new socket connection");
|
32 |
+
|
33 |
+
socket.on("ask_api", (client_data) => {
|
34 |
+
console.log(client_data)
|
35 |
+
console.log("trying to reach api");
|
36 |
+
asyncAPICall(client_data, socket)
|
37 |
+
});
|
38 |
+
|
39 |
+
});
|
40 |
+
|
41 |
+
async function test_servers(){
|
42 |
+
try{
|
43 |
+
const grapi_test = await client("https://gradio-hello-world.hf.space");
|
44 |
+
const apitest_result = await grapi_test.predict("/predict", [
|
45 |
+
"John",
|
46 |
+
]);
|
47 |
+
console.log(apitest_result);
|
48 |
+
}
|
49 |
+
catch(e){
|
50 |
+
console.log(e)
|
51 |
+
}
|
52 |
+
|
53 |
+
}
|
54 |
+
|
55 |
+
//test_servers()
|
56 |
+
|
57 |
+
async function asyncAPICall(data, socket) {
|
58 |
+
|
59 |
+
const grapi = await client("fffiloni/mndrm-call");
|
60 |
+
try{
|
61 |
+
const api_result = await grapi.predict("/infer", [
|
62 |
+
data[0], // blob in 'image' Image component
|
63 |
+
data[1], // string in 'Question' Textbox component
|
64 |
+
]);
|
65 |
+
console.log(api_result)
|
66 |
+
socket.emit("api_response", (api_result.data))
|
67 |
+
}
|
68 |
+
catch(e){
|
69 |
+
console.log(e)
|
70 |
+
socket.emit("api_error", ("ERROR ON API SIDE, SORRY..."))
|
71 |
+
}
|
72 |
+
|
73 |
+
}
|
74 |
+
|
75 |
+
|
76 |
+
|
77 |
+
httpServer.listen(7860);
|
78 |
+
console.log("App running on localhost:7860")
|
79 |
+
```
|
80 |
+
|
81 |
+
# Update program:
|
82 |
+
|
83 |
+
```
|