-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrop_prediction.php
More file actions
176 lines (156 loc) · 8.33 KB
/
Copy pathcrop_prediction.php
File metadata and controls
176 lines (156 loc) · 8.33 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!DOCTYPE html>
<html>
<?php include ('header.php'); ?>
<body class="bg-white" id="top">
<?php include ('nav.php'); ?>
<section class="section section-shaped section-lg">
<div class="shape shape-style-1 shape-primary">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
<!-- ======================================================================================================================================== -->
<div class="container ">
<div class="row">
<div class="col-md-8 mx-auto text-center">
<span class="badge badge-danger badge-pill mb-3">Prediction</span>
</div>
</div>
<div class="row row-content">
<div class="col-md-12 mb-3">
<div class="card text-white bg-gradient-success mb-3">
<div class="card-header">
<span class="text-success display-4">Crop Prediction</span>
</div>
<div class="card-body">
<form role="form" action="#" method="post" class="prediction-form">
<div class="prediction-table">
<table class="table table-hover table-bordered bg-gradient-white text-center display" id="myTable">
<thead>
<tr class="font-weight-bold text-default">
<th><center>State</center></th>
<th><center>District</center></th>
<th><center>Season</center></th>
<th><center>Prediction</center></th>
</tr>
</thead>
<tbody>
<tr class="text-center">
<td>
<div class="form-group">
<select onchange="print_city('state', this.selectedIndex);" id="sts" name="stt" class="form-control" required>
</select>
<script language="javascript">print_state("sts");</script>
</div>
</td>
<td>
<div class="form-group">
<select id="state" name="district" class="form-control" required>
<option value="">Select District</option>
</select>
</div>
</td>
<td>
<div class="form-group">
<select name="Season" class="form-control">
<option value="">Select Season ...</option>
<option value="Kharif">Kharif</option>
<option value="Whole Year">Whole Year</option>
<option value="Autumn">Autumn</option>
<option value="Rabi">Rabi</option>
<option value="Summer">Summer</option>
<option value="Winter">Winter</option>
</select>
</div>
</td>
<td>
<center>
<div class="form-group">
<button type="submit" name="Crop_Predict" class="btn btn-predict">
<i class="fas fa-seedling mr-2"></i>Predict
</button>
</div>
</center>
</td>
</tr>
</tbody>
</table>
</div>
</form>
<?php
if(isset($_POST['Crop_Predict'])) {
$state = trim($_POST['stt']);
$district = trim($_POST['district']);
$season = trim($_POST['Season']);
// Remove quotes from JSON encoded values
$state = trim($state, '"');
$district = trim($district, '"');
$season = trim($season, '"');
$command = escapeshellcmd("python ML/crop_prediction/ZDecision_Tree_Model_Call.py \"$state\" \"$district\" \"$season\"");
$output = shell_exec($command);
// Debug output
error_log("Debug - Command: " . $command);
error_log("Debug - Raw output: " . $output);
// Clean and process the output
$lines = explode("\n", $output);
$final_output = "";
foreach($lines as $line) {
if(strpos($line, "Debug:") === false) {
$final_output .= trim($line);
}
}
$crops = explode(",", $final_output);
?>
<div class="prediction-result">
<div class="result-header">
<h3>Prediction Results</h3>
</div>
<div class="result-content">
<div class="result-item">
<span class="result-label">State:</span>
<span class="result-value"><?php echo htmlspecialchars($state); ?></span>
</div>
<div class="result-item">
<span class="result-label">District:</span>
<span class="result-value"><?php echo htmlspecialchars($district); ?></span>
</div>
<div class="result-item">
<span class="result-label">Season:</span>
<span class="result-value"><?php echo htmlspecialchars($season); ?></span>
</div>
<div class="result-item">
<span class="result-label">Recommended Crop:</span>
<span class="result-value prediction-badge">
<i class="fas fa-leaf mr-2"></i>
<?php
if(!empty($crops)) {
foreach($crops as $crop) {
if(trim($crop) != "") {
echo htmlspecialchars(trim($crop)) . ", ";
}
}
} else {
echo "No crops found for the selected criteria";
}
?>
</span>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
</section>
<?php require("footer.php");?>
</body>
</html>