-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
122 lines (108 loc) · 3.39 KB
/
index.html
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>花卉识别</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
h1 {
text-align: center;
margin-bottom: 20px;
}
form {
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 20px;
}
input[type="file"] {
display: none;
}
.custom-file-upload {
border: 2px solid #4CAF50;
background-color: white;
color: #4CAF50;
padding: 8px 20px;
border-radius: 5px;
cursor: pointer;
transition: all 0.3s ease;
}
.custom-file-upload:hover {
background-color: #4CAF50;
color: white;
}
#originalImage {
max-width: 384px;
max-height: 384px;
display: block;
margin: 20px auto;
}
#predictButton {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
font-size: 16px;
cursor: pointer;
transition: all 0.3s ease;
}
#predictButton:hover {
background-color: #2E8B57;
}
#result {
text-align: center;
font-size: 18px;
font-weight: bold;
margin-top: 20px;
}
</style>
</head>
<body>
<h1>花卉识别</h1>
<form id="uploadForm" enctype="multipart/form-data">
<label for="imageInput" class="custom-file-upload">选择图片</label>
<input type="file" name="image" id="imageInput">
<button type="submit" id="predictButton" style="display:none">预测</button>
</form>
<div>
<img id="originalImage" style="display:none">
</div>
<div id="result"></div>
<script>
$(document).ready(function() {
$('#uploadForm').submit(function(event) {
event.preventDefault();
var formData = new FormData(this);
$.ajax({
url: 'http://localhost:5000/predict',
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(response) {
$('#result').text('类别: ' + response.class + ', 概率: ' + response.probability.toFixed(3));
},
error: function(error) {
console.log(error);
$('#result').text('预测出错');
}
});
});
$('#imageInput').change(function() {
var file = this.files[0];
var reader = new FileReader();
reader.onload = function(e) {
$('#originalImage').attr('src', e.target.result).show();
}
reader.readAsDataURL(file);
$('#predictButton').show();
});
});
</script>
</body>
</html>