This repository was archived by the owner on Dec 12, 2023. It is now read-only.
generated from course-files/BBT4206-Lab15of15-ConsumePlumberAPIOutput
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequiredlabworksubmission.php
More file actions
85 lines (75 loc) · 2.72 KB
/
requiredlabworksubmission.php
File metadata and controls
85 lines (75 loc) · 2.72 KB
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
85
<?php
$apiUrl = 'http://127.0.0.1:5022/diabetes';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Process form data and make the API request
// Set the values of the parameters to pass to the model
$arg_pregnant = $_POST['arg_pregnant'];
$arg_glucose = $_POST['arg_glucose'];
$arg_pressure = $_POST['arg_pressure'];
$arg_triceps = $_POST['arg_triceps'];
$arg_insulin = $_POST['arg_insulin'];
$arg_mass = $_POST['arg_mass'];
$arg_pedigree = $_POST['arg_pedigree'];
$arg_age = $_POST['arg_age'];
$params = array(
'arg_pregnant' => $arg_pregnant,
'arg_glucose' => $arg_glucose,
'arg_pressure' => $arg_pressure,
'arg_triceps' => $arg_triceps,
'arg_insulin' => $arg_insulin,
'arg_mass' => $arg_mass,
'arg_pedigree' => $arg_pedigree,
'arg_age' => $arg_age
);
// Set the cURL options
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $apiUrl);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// Make the request
$response = curl_exec($curl);
// Check for cURL errors
if (curl_errno($curl)) {
$error = curl_error($curl);
die("cURL Error: $error");
}
// Close cURL session/resource
curl_close($curl);
// Process the response
$data = json_decode($response, true);
if (isset($data['0'])) {
// API request was successful
echo "The predicted diabetes status is:<br>";
foreach ($data as $repository) {
echo $repository['0'], $repository['1'], $repository['2'], "<br>";
}
} else {
// API request failed or returned an error
echo "API Error: " . $data['message'];
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Diabetes Form</title>
</head>
<body>
<h1>Diabetes Form</h1>
<form method="post" action="">
<!-- Add input fields for each parameter -->
Pregnant: <input type="number" name="arg_pregnant" required><br>
Glucose: <input type="number" name="arg_glucose" required><br>
Pressure: <input type="number" name="arg_pressure" required><br>
Triceps: <input type="number" name="arg_triceps" required><br>
Insulin: <input type="number" name="arg_insulin" required><br>
Mass: <input type="number" name="arg_mass" required><br>
Pedigree: <input type="number" step="0.001" name="arg_pedigree" required><br>
Age: <input type="number" name="arg_age" required><br>
<button type="submit">Predict</button>
</form>
</body>
</html>