Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Piexie3 committed Sep 24, 2023
2 parents 44b6200 + 8e9d5db commit ee65988
Show file tree
Hide file tree
Showing 7 changed files with 401 additions and 301 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/master_cropguard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions
# More info on Python, GitHub Actions, and Azure App Service: https://aka.ms/python-webapps-actions

name: Build and deploy Python app to Azure Web App - cropGuard

on:
push:
branches:
- master
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Python version
uses: actions/setup-python@v1
with:
python-version: '3.11'

- name: Create and start virtual environment
run: |
python -m venv venv
source venv/bin/activate
- name: Install dependencies
run: pip install -r requirements.txt

# Optional: Add step to run tests here (PyTest, Django test suites, etc.)

- name: Upload artifact for deployment jobs
uses: actions/upload-artifact@v2
with:
name: python-app
path: |
.
!venv/
deploy:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v2
with:
name: python-app
path: .

- name: 'Deploy to Azure Web App'
uses: azure/webapps-deploy@v2
id: deploy-to-webapp
with:
app-name: 'cropGuard'
slot-name: 'Production'
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_91459E4BF9E4413ABEF11AE35C4F1D4A }}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# CropGuard_backend
506 changes: 253 additions & 253 deletions disease_detection/disease_dic.py

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions fertilizer_detection/fertilizer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from flask import Flask, jsonify, redirect, render_template, request, session, Markup, Response
from fertilizer_detection.fertilizer_dic import fertilizer_dic
import pandas as pd

Expand Down Expand Up @@ -37,8 +36,8 @@ def fert_recommend(msg_received):
else:
key = "Klow"

response = Markup(str(fertilizer_dic[key]))
response = str(fertilizer_dic[key])
# response = jsonify(response)
return {"response": f"{response}"}
return {"response": f"{response}", }
except Exception as e:
return {"Error": str(e), "statusCode": 600}
88 changes: 44 additions & 44 deletions fertilizer_detection/fertilizer_dic.py
Original file line number Diff line number Diff line change
@@ -1,92 +1,92 @@
fertilizer_dic = {
'NHigh': """The N value of soil is high and might give rise to weeds.
<br/> Please consider the following suggestions:
Please consider the following suggestions:
<br/><br/> 1. <i> Manure </i> - adding manure is one of the simplest ways to amend your soil with nitrogen. Be careful as there are various types of manures with varying degrees of nitrogen.
1. Manure - adding manure is one of the simplest ways to amend your soil with nitrogen. Be careful as there are various types of manures with varying degrees of nitrogen.
<br/> 2. <i>Coffee grinds </i> - use your morning addiction to feed your gardening habit! Coffee grinds are considered a green compost material which is rich in nitrogen. Once the grounds break down, your soil will be fed with delicious, delicious nitrogen. An added benefit to including coffee grounds to your soil is while it will compost, it will also help provide increased drainage to your soil.
2. Coffee grinds - use your morning addiction to feed your gardening habit! Coffee grinds are considered a green compost material which is rich in nitrogen. Once the grounds break down, your soil will be fed with delicious, delicious nitrogen. An added benefit to including coffee grounds to your soil is while it will compost, it will also help provide increased drainage to your soil.
<br/>3. <i>Plant nitrogen fixing plants</i> - planting vegetables that are in Fabaceae family like peas, beans and soybeans have the ability to increase nitrogen in your soil
3. Plant nitrogen fixing plants - planting vegetables that are in Fabaceae family like peas, beans and soybeans have the ability to increase nitrogen in your soil
<br/>4. Plant 'green manure' crops like cabbage, corn and brocolli
4. Plant 'green manure' crops like cabbage, corn and brocolli
<br/>5. <i>Use mulch (wet grass) while growing crops</i> - Mulch can also include sawdust and scrap soft woods""",
5. Use mulch (wet grass) while growing crops - Mulch can also include sawdust and scrap soft woods""",

'Nlow': """The N value of your soil is low.
<br/> Please consider the following suggestions:
<br/><br/> 1. <i>Add sawdust or fine woodchips to your soil</i> - the carbon in the sawdust/woodchips love nitrogen and will help absorb and soak up and excess nitrogen.
Please consider the following suggestions:
1. Add sawdust or fine woodchips to your soil - the carbon in the sawdust/woodchips love nitrogen and will help absorb and soak up and excess nitrogen.
<br/>2. <i>Plant heavy nitrogen feeding plants</i> - tomatoes, corn, broccoli, cabbage and spinach are examples of plants that thrive off nitrogen and will suck the nitrogen dry.
2. Plant heavy nitrogen feeding plants - tomatoes, corn, broccoli, cabbage and spinach are examples of plants that thrive off nitrogen and will suck the nitrogen dry.
<br/>3. <i>Water</i> - soaking your soil with water will help leach the nitrogen deeper into your soil, effectively leaving less for your plants to use.
3. Water - soaking your soil with water will help leach the nitrogen deeper into your soil, effectively leaving less for your plants to use.
<br/>4. <i>Sugar</i> - In limited studies, it was shown that adding sugar to your soil can help potentially reduce the amount of nitrogen is your soil. Sugar is partially composed of carbon, an element which attracts and soaks up the nitrogen in the soil. This is similar concept to adding sawdust/woodchips which are high in carbon content.
4. Sugar - In limited studies, it was shown that adding sugar to your soil can help potentially reduce the amount of nitrogen is your soil. Sugar is partially composed of carbon, an element which attracts and soaks up the nitrogen in the soil. This is similar concept to adding sawdust/woodchips which are high in carbon content.
<br/>5. Add composted manure to the soil.
5. Add composted manure to the soil.
<br/>6. Plant Nitrogen fixing plants like peas or beans.
6. Plant Nitrogen fixing plants like peas or beans.
<br/>7. <i>Use NPK fertilizers with high N value.
7. Use NPK fertilizers with high N value.
<br/>8. <i>Do nothing</i> - It may seem counter-intuitive, but if you already have plants that are producing lots of foliage, it may be best to let them continue to absorb all the nitrogen to amend the soil for your next crops.""",
8. Do nothing - It may seem counter-intuitive, but if you already have plants that are producing lots of foliage, it may be best to let them continue to absorb all the nitrogen to amend the soil for your next crops.""",

'PHigh': """The P value of your soil is high.
<br/> Please consider the following suggestions:
Please consider the following suggestions:
<br/><br/>1. <i>Avoid adding manure</i> - manure contains many key nutrients for your soil but typically including high levels of phosphorous. Limiting the addition of manure will help reduce phosphorus being added.
1. Avoid adding manure - manure contains many key nutrients for your soil but typically including high levels of phosphorous. Limiting the addition of manure will help reduce phosphorus being added.
<br/>2. <i>Use only phosphorus-free fertilizer</i> - if you can limit the amount of phosphorous added to your soil, you can let the plants use the existing phosphorus while still providing other key nutrients such as Nitrogen and Potassium. Find a fertilizer with numbers such as 10-0-10, where the zero represents no phosphorous.
2. Use only phosphorus-free fertilizer - if you can limit the amount of phosphorous added to your soil, you can let the plants use the existing phosphorus while still providing other key nutrients such as Nitrogen and Potassium. Find a fertilizer with numbers such as 10-0-10, where the zero represents no phosphorous.
<br/>3. <i>Water your soil</i> - soaking your soil liberally will aid in driving phosphorous out of the soil. This is recommended as a last ditch effort.
3. Water your soil - soaking your soil liberally will aid in driving phosphorous out of the soil. This is recommended as a last ditch effort.
<br/>4. Plant nitrogen fixing vegetables to increase nitrogen without increasing phosphorous (like beans and peas).
4. Plant nitrogen fixing vegetables to increase nitrogen without increasing phosphorous (like beans and peas).
<br/>5. Use crop rotations to decrease high phosphorous levels""",
5. Use crop rotations to decrease high phosphorous levels""",

'Plow': """The P value of your soil is low.
<br/> Please consider the following suggestions:
Please consider the following suggestions:
<br/><br/>1. <i>Bone meal</i> - a fast acting source that is made from ground animal bones which is rich in phosphorous.
1. Bone meal - a fast acting source that is made from ground animal bones which is rich in phosphorous.
<br/>2. <i>Rock phosphate</i> - a slower acting source where the soil needs to convert the rock phosphate into phosphorous that the plants can use.
2. Rock phosphate - a slower acting source where the soil needs to convert the rock phosphate into phosphorous that the plants can use.
<br/>3. <i>Phosphorus Fertilizers</i> - applying a fertilizer with a high phosphorous content in the NPK ratio (example: 10-20-10, 20 being phosphorous percentage).
3. Phosphorus Fertilizers - applying a fertilizer with a high phosphorous content in the NPK ratio (example: 10-20-10, 20 being phosphorous percentage).
<br/>4. <i>Organic compost</i> - adding quality organic compost to your soil will help increase phosphorous content.
4. Organic compost - adding quality organic compost to your soil will help increase phosphorous content.
<br/>5. <i>Manure</i> - as with compost, manure can be an excellent source of phosphorous for your plants.
5. Manure - as with compost, manure can be an excellent source of phosphorous for your plants.
<br/>6. <i>Clay soil</i> - introducing clay particles into your soil can help retain & fix phosphorus deficiencies.
6. Clay soil - introducing clay particles into your soil can help retain & fix phosphorus deficiencies.
<br/>7. <i>Ensure proper soil pH</i> - having a pH in the 6.0 to 7.0 range has been scientifically proven to have the optimal phosphorus uptake in plants.
7. Ensure proper soil pH - having a pH in the 6.0 to 7.0 range has been scientifically proven to have the optimal phosphorus uptake in plants.
<br/>8. If soil pH is low, add lime or potassium carbonate to the soil as fertilizers. Pure calcium carbonate is very effective in increasing the pH value of the soil.
8. If soil pH is low, add lime or potassium carbonate to the soil as fertilizers. Pure calcium carbonate is very effective in increasing the pH value of the soil.
<br/>9. If pH is high, addition of appreciable amount of organic matter will help acidify the soil. Application of acidifying fertilizers, such as ammonium sulfate, can help lower soil pH""",
9. If pH is high, addition of appreciable amount of organic matter will help acidify the soil. Application of acidifying fertilizers, such as ammonium sulfate, can help lower soil pH""",

'KHigh': """The K value of your soil is high</b>.
<br/> Please consider the following suggestions:
Please consider the following suggestions:
<br/><br/>1. <i>Loosen the soil</i> deeply with a shovel, and water thoroughly to dissolve water-soluble potassium. Allow the soil to fully dry, and repeat digging and watering the soil two or three more times.
1. Loosen the soil deeply with a shovel, and water thoroughly to dissolve water-soluble potassium. Allow the soil to fully dry, and repeat digging and watering the soil two or three more times.
<br/>2. <i>Sift through the soil</i>, and remove as many rocks as possible, using a soil sifter. Minerals occurring in rocks such as mica and feldspar slowly release potassium into the soil slowly through weathering.
2. Sift through the soil, and remove as many rocks as possible, using a soil sifter. Minerals occurring in rocks such as mica and feldspar slowly release potassium into the soil slowly through weathering.
<br/>3. Stop applying potassium-rich commercial fertilizer. Apply only commercial fertilizer that has a '0' in the final number field. Commercial fertilizers use a three number system for measuring levels of nitrogen, phosphorous and potassium. The last number stands for potassium. Another option is to stop using commercial fertilizers all together and to begin using only organic matter to enrich the soil.
3. Stop applying potassium-rich commercial fertilizer. Apply only commercial fertilizer that has a '0' in the final number field. Commercial fertilizers use a three number system for measuring levels of nitrogen, phosphorous and potassium. The last number stands for potassium. Another option is to stop using commercial fertilizers all together and to begin using only organic matter to enrich the soil.
<br/>4. Mix crushed eggshells, crushed seashells, wood ash or soft rock phosphate to the soil to add calcium. Mix in up to 10 percent of organic compost to help amend and balance the soil.
4. Mix crushed eggshells, crushed seashells, wood ash or soft rock phosphate to the soil to add calcium. Mix in up to 10 percent of organic compost to help amend and balance the soil.
<br/>5. Use NPK fertilizers with low K levels and organic fertilizers since they have low NPK values.
5. Use NPK fertilizers with low K levels and organic fertilizers since they have low NPK values.
<br/>6. Grow a cover crop of legumes that will fix nitrogen in the soil. This practice will meet the soil's needs for nitrogen without increasing phosphorus or potassium.
6. Grow a cover crop of legumes that will fix nitrogen in the soil. This practice will meet the soil's needs for nitrogen without increasing phosphorus or potassium.
""",

'Klow': """The K value of your soil is low.
<br/>Please consider the following suggestions:
Please consider the following suggestions:
<br/><br/>1. Mix in muricate of potash or sulphate of potash
<br/>2. Try kelp meal or seaweed
<br/>3. Try Sul-Po-Mag
<br/>4. Bury banana peels an inch below the soils surface
<br/>5. Use Potash fertilizers since they contain high values potassium
1. Mix in muricate of potash or sulphate of potash
2. Try kelp meal or seaweed
3. Try Sul-Po-Mag
4. Bury banana peels an inch below the soils surface
5. Use Potash fertilizers since they contain high values potassium
"""
}
35 changes: 35 additions & 0 deletions media_handler/azure_upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient

def upload_image_to_azure(local_image_path, container_name, blob_name, connection_string):
try:
# Create a BlobServiceClient
blob_service_client = BlobServiceClient.from_connection_string(connection_string)

# Create a ContainerClient
container_client = blob_service_client.get_container_client(container_name)

# Upload the image to Azure Blob Storage
with open(local_image_path, "rb") as data:
container_client.upload_blob(name=blob_name, data=data)

# Generate a URL for the uploaded image
blob_url = f"https://{blob_service_client.account_name}.blob.core.windows.net/{container_name}/{blob_name}"

return blob_url

except Exception as e:
return {"Message": str(e)}

# # Example usage:
# if __name__ == "__main__":
# local_image_path = "path_to_local_image.jpg" # Replace with the path to your local image
# container_name = "your_container_name" # Replace with your Azure Blob Storage container name
# blob_name = "image.jpg" # Replace with the name you want for the image in Azure
# connection_string = "your_connection_string" # Replace with your Azure Storage Account connection string

# image_url = upload_image_to_azure(local_image_path, container_name, blob_name, connection_string)

# if not image_url.startswith("Error"):
# print(f"Image uploaded successfully. URL: {image_url}")
# else:
# print(f"Error uploading
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ mysql
sqlalchemy
flask
bcrpt
mysql-connector-python
mysql-connector-python
azure
gunicorn

0 comments on commit ee65988

Please sign in to comment.