File size: 1,084 Bytes
3e0c793
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const https = require('https');

const POTABILITY_API = 'https://dpv007-newclear.hf.space/gradio_api/call/predict_potability';

function test(pH, hardness, turbidity, temperature) {
  const postData = JSON.stringify({
    data: [pH, hardness, turbidity, temperature]
  });

  const options = {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Content-Length': Buffer.byteLength(postData)
    }
  };

  const req = https.request(POTABILITY_API, options, (res) => {
    let data = '';
    res.on('data', chunk => data += chunk);
    res.on('end', () => {
      console.log("POST Response:", data);
      const eventId = JSON.parse(data).event_id;
      
      const predReq = https.request(`${POTABILITY_API}/${eventId}`, {method: 'GET'}, (predRes) => {
        let predData = '';
        predRes.on('data', chunk => predData += chunk);
        predRes.on('end', () => {
          console.log("GET Response:", predData);
        });
      });
      predReq.end();
    });
  });
  req.write(postData);
  req.end();
}

test(6.96, 108.95, 15.57, 90.33);