Spaces:
Sleeping
Sleeping
| 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); | |