Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question #6

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
44 changes: 27 additions & 17 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,28 +133,30 @@ def predict_image(img, model=disease_model):

@ app.route('/')
def home():
return render_template('index.html')
title = 'Harvestify - Home'
return render_template('index.html', title=title)

# render crop recommendation form page


@ app.route('/crop-recommend')
def crop_recommend():
return render_template('crop.html')
title = 'Harvestify - Crop Recommendation'
return render_template('crop.html', title=title)

# render fertilizer recommendation form page


@ app.route('/fertilizer')
def fertilizer_recommendation():
return render_template('fertilizer.html')
title = 'Harvestify - Fertilizer Suggestion'

return render_template('fertilizer.html', title=title)

# render disease prediction input page


@ app.route('/disease')
def disease():
return render_template('disease.html')


# ===============================================================================================

Expand All @@ -165,6 +167,8 @@ def disease():

@ app.route('/crop-predict', methods=['POST'])
def crop_prediction():
title = 'Harvestify - Crop Recommendation'

if request.method == 'POST':
N = int(request.form['nitrogen'])
P = int(request.form['phosphorous'])
Expand All @@ -181,17 +185,19 @@ def crop_prediction():
my_prediction = crop_recommendation_model.predict(data)
final_prediction = my_prediction[0]

return render_template('crop-result.html', prediction=final_prediction)
return render_template('crop-result.html', prediction=final_prediction, title=title)

else:

return render_template('try_again.html')
return render_template('try_again.html', title=title)

# render fertilizer recommendation result page


@ app.route('/fertilizer-predict', methods=['POST'])
def fert_recommend():
title = 'Harvestify - Fertilizer Suggestion'

crop_name = str(request.form['cropname'])
N = int(request.form['nitrogen'])
P = int(request.form['phosphorous'])
Expand Down Expand Up @@ -227,29 +233,33 @@ def fert_recommend():

response = Markup(str(fertilizer_dic[key]))

return render_template('fertilizer-result.html', recommendation=response)
return render_template('fertilizer-result.html', recommendation=response, title=title)

# render disease prediction result page


@app.route('/disease-predict', methods=['GET', 'POST'])
def disease_prediction():
title = 'Harvestify - Disease Detection'

if request.method == 'POST':
if 'file' not in request.files:
return redirect(request.url)
file = request.files.get('file')
if not file:
return
img = file.read()

prediction = predict_image(img)
return render_template('disease.html', title=title)
try:
img = file.read()

prediction = Markup(str(disease_dic[prediction]))
return render_template('disease-result.html', prediction=prediction)
prediction = predict_image(img)

return render_template('disease.html')
prediction = Markup(str(disease_dic[prediction]))
return render_template('disease-result.html', prediction=prediction, title=title)
except:
pass
return render_template('disease.html', title=title)


# ===============================================================================================
if __name__ == '__main__':
app.run(debug=True)
app.run(debug=False)
Binary file added static/images/favicon.ico
Binary file not shown.
Binary file added static/images/logo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed static/images/logo.png
Binary file not shown.
Binary file modified static/images/s4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 24 additions & 23 deletions templates/crop.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
<!-- {% extends 'layout.html' %} -->

{% block body %}
{% extends 'layout.html' %} {% block body %}

<style>

html body {
background-color: rgb(206, 206, 228);


html body {
background-color: rgb(206, 206, 228);
}


</style>
<!--Form Section-->
<br /><br />
Expand All @@ -33,7 +26,7 @@ <h2 style="text-align: center; margin: 0px; color: black">
<div class="form-group">
<label for="Nitrogen" style="font-size: 17px"><b>Nitrogen</b></label>
<input
type="text"
type="number"
class="form-control"
id="Nitrogen"
name="nitrogen"
Expand All @@ -47,7 +40,7 @@ <h2 style="text-align: center; margin: 0px; color: black">
><b>Phosphorous</b></label
>
<input
type="text"
type="number"
class="form-control"
id="Phosphorous"
name="phosphorous"
Expand All @@ -60,7 +53,7 @@ <h2 style="text-align: center; margin: 0px; color: black">
<div class="form-group">
<label for="Pottasium" style="font-size: 17px"><b>Pottasium</b></label>
<input
type="text"
type="number"
class="form-control"
id="Pottasium"
name="pottasium"
Expand All @@ -72,7 +65,8 @@ <h2 style="text-align: center; margin: 0px; color: black">
<div class="form-group">
<label for="ph" style="font-size: 17px"><b>ph level</b></label>
<input
type="text"
type="number"
step="0.01"
class="form-control"
id="ph"
name="ph"
Expand All @@ -82,9 +76,12 @@ <h2 style="text-align: center; margin: 0px; color: black">
/>
</div>
<div class="form-group">
<label for="Rainfall" style="font-size: 17px"><b>Rainfall (in mm)</b></label>
<label for="Rainfall" style="font-size: 17px"
><b>Rainfall (in mm)</b></label
>
<input
type="text"
type="number"
step="0.01"
class="form-control"
id="Rainfall"
name="rainfall"
Expand All @@ -94,14 +91,13 @@ <h2 style="text-align: center; margin: 0px; color: black">
/>
</div>
<div class="form-group">
<label for="State" style="font-size: 17px "><b>State</b></label>
<label for="State" style="font-size: 17px"><b>State</b></label>
<select
onchange="print_city('state', this.selectedIndex);"
id="sts"
name="stt"
class="form-control"
style="font-weight: bold; color: black;"

style="font-weight: bold; color: black"
required
></select>
<br />
Expand All @@ -110,7 +106,7 @@ <h2 style="text-align: center; margin: 0px; color: black">
id="state"
class="form-control"
name="city"
style="font-weight: bold; color: black;"
style="font-weight: bold; color: black"
required
></select>
<script language="javascript">
Expand All @@ -122,16 +118,21 @@ <h2 style="text-align: center; margin: 0px; color: black">
<button
type="submit"
class="btn btn-info"
style="color: black; font-weight: bold; width: 130px; height:50px; border-radius:12px; font-size: 21px;"
style="
color: black;
font-weight: bold;
width: 130px;
height: 50px;
border-radius: 12px;
font-size: 21px;
"
>
Predict
</button>
</div>
</form>
</div>



<!-- Form section -->

{% endblock %}
3 changes: 1 addition & 2 deletions templates/disease-result.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

<!-- {% extends 'layout.html' %} -->
{% extends 'layout.html' %} {% block body %}


{% block body %}
<div class="container py-2 mx-auto my-50 h-10 " style="margin: 9rem;">
<div class="row">
<div class="col-sm py-2 py-md-3">
Expand Down
6 changes: 3 additions & 3 deletions templates/disease.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<!-- {% extends 'layout.html' %} -->
{% extends 'layout.html' %} {% block body %}

{% block body %}

<style>
html body {
Expand Down Expand Up @@ -31,7 +30,8 @@ <h2 style="text-align: center; margin: 0px; color: black">

<h2 class="h4 mb-3 font-weight-normal"><b>Please Upload The Image</b></h2>
<input type="file" name="file" class="form-control-file" id="inputfile" onchange="preview_image(event)" style="font-weight: bold;">
<br />
<br>
<br>
<img id="output-image" class="rounded mx-auto d-block" />
<button class="btn btn-lg btn-primary btn-block" type="submit" style="font-weight: bold;">Predict</button>

Expand Down
21 changes: 4 additions & 17 deletions templates/fertilizer.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<!-- {% extends 'layout.html' %} -->
{% extends 'layout.html' %} {% block body %}

{% block body %}
<style>
html body {
background-color: rgb(206, 206, 228);
Expand All @@ -27,7 +26,7 @@ <h2 style="text-align: center; margin: 0px; color: black">
<div class="form-group">
<label for="Nitrogen" style="font-size: 17px"><b>Nitrogen</b></label>
<input
type="text"
type="number"
class="form-control"
id="Nitrogen"
name="nitrogen"
Expand All @@ -41,7 +40,7 @@ <h2 style="text-align: center; margin: 0px; color: black">
><b>Phosphorous</b></label
>
<input
type="text"
type="number"
class="form-control"
id="Phosphorous"
name="phosphorous"
Expand All @@ -54,7 +53,7 @@ <h2 style="text-align: center; margin: 0px; color: black">
<div class="form-group">
<label for="Pottasium" style="font-size: 17px"><b>Pottasium</b></label>
<input
type="text"
type="number"
class="form-control"
id="Pottasium"
name="pottasium"
Expand All @@ -63,18 +62,6 @@ <h2 style="text-align: center; margin: 0px; color: black">
required
/>
</div>
<!-- <div class="form-group">
<label for="ph" style="font-size: 17px"><b>ph level</b></label>
<input
type="text"
class="form-control"
id="ph"
name="ph"
placeholder="Enter the value"
style="font-weight: bold"
required
/>
</div> -->
<div class="form-group">
<label for="crop" style="font-size: 17px"
><b>Crop you want to grow</b></label
Expand Down
3 changes: 2 additions & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ <h4 class="text-wh mx-auto my-4"><strong> Here are some questions we'll answer</
<p class="text-li mx-auto mt-2">
1. What crop to plant here? <br>
2. What fertilizer to use? <br>
3. Which disease do your crop have ?</p>
3. Which disease do your crop have?<br>
4. How to cure the disease?</p>
</div>
</div>
</div>
Expand Down
Loading