-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
58 lines (52 loc) · 1.92 KB
/
index.php
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
<!DOCTYPE html>
<html>
<head>
<title>AI Backend Results</title>
<style>
.prediction {
margin-bottom: 20px;
}
</style>
</head>
<body>
<h1>AI Backend Results</h1>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="image" accept="image/*" required>
<input type="submit" value="Predict">
</form>
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Mendapatkan data gambar
$image = $_FILES['image'];
$imageData = base64_encode(file_get_contents($image['tmp_name']));
// Mengirim permintaan ke backend Flask
$url = 'http://localhost:5000/predict'; // Ganti URL dengan URL backend Flask Anda
$data = array('' => $imageData);
// Mengirim permintaan menggunakan metode POST
$options = array(
'http' => array(
'header' => "Content-type: application/json\r\n",
'method' => 'POST',
'content' => json_encode($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
// Mengecek apakah permintaan berhasil atau tidak
if ($result === FALSE) {
echo "Error accessing the AI backend";
} else {
// Mendapatkan hasil prediksi dari JSON response
$prediction = json_decode($result, true);
// Menampilkan hasil prediksi
echo '<div class="prediction">';
echo ' <h2>Prediction Results</h2>';
echo ' <img src="data:image/jpeg;base64,' . $imageData . '" alt="Input Image" width="300">';
echo ' <p><strong>Top Prediction:</strong> ' . $prediction['nama'] . '</p>';
echo ' <p><strong>Confidence:</strong> ' . $prediction['probability'] . '%</p>';
echo '</div>';
}
}
?>
</body>
</html>