File size: 2,061 Bytes
5c1cc06
 
 
 
 
 
 
 
 
efe93a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
---
title: Live Vision
emoji: 🐠
colorFrom: blue
colorTo: yellow
sdk: docker
pinned: false
---

# Prompt evolution below:  

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: 

```javascript
import express from "express";
import 'dotenv/config.js'
import { createServer } from "http";
import { Server } from "socket.io";
import { client } from "@gradio/client";
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url);
global.EventSource = require('eventsource');

const app = express();
const httpServer = createServer(app);
app.use(express.static('public'));
const io = new Server(httpServer, { /* options */ });

io.on("connection", (socket) => {
    
    console.log("new socket connection");
    
    socket.on("ask_api", (client_data) => {
        console.log(client_data)
        console.log("trying to reach api");   
        asyncAPICall(client_data, socket)
    });

});

async function test_servers(){
  try{
    const grapi_test = await client("https://gradio-hello-world.hf.space");
    const apitest_result = await grapi_test.predict("/predict", [
      "John",
    ]);
    console.log(apitest_result);
  }
  catch(e){
    console.log(e)
  }
  
}

//test_servers()

async function asyncAPICall(data, socket) {

  const grapi = await client("fffiloni/mndrm-call");
  try{
      const api_result = await grapi.predict("/infer", [
          data[0], 	// blob in 'image' Image component		
          data[1], // string  in 'Question' Textbox component
      ]); 
      console.log(api_result)
      socket.emit("api_response", (api_result.data))
  }
  catch(e){
      console.log(e)
      socket.emit("api_error", ("ERROR ON API SIDE, SORRY..."))
  }    
 
}



httpServer.listen(7860);
console.log("App running on localhost:7860")
```

# Update program:

```