0% found this document useful (0 votes)
5 views3 pages

Total Code

The document outlines a Python program for AI-based agriculture projects, featuring a menu with options for crop health monitoring, smart irrigation, crop yield prediction, soil health analysis, weather prediction, weed detection, and crop price forecasting. Each option includes basic simulations or analyses, such as image processing for crop health and weed detection, and simple predictive models for crop yield and prices. The program utilizes libraries like NumPy, Pandas, Matplotlib, and OpenCV for data handling and visualization.

Uploaded by

sonidevesh632
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

Total Code

The document outlines a Python program for AI-based agriculture projects, featuring a menu with options for crop health monitoring, smart irrigation, crop yield prediction, soil health analysis, weather prediction, weed detection, and crop price forecasting. Each option includes basic simulations or analyses, such as image processing for crop health and weed detection, and simple predictive models for crop yield and prices. The program utilizes libraries like NumPy, Pandas, Matplotlib, and OpenCV for data handling and visualization.

Uploaded by

sonidevesh632
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

import numpy as np

import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import accuracy_score, mean_squared_error
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
import cv2
import os

# Menu for AI-based Agriculture Projects


def main_menu():
while True:
print("\nAI in Agriculture Project Suite")
print("1. Crop Health Monitoring")
print("2. Smart Irrigation System")
print("3. Crop Yield Prediction")
print("4. Soil Health Analysis")
print("5. Weather Prediction")
print("6. Weed Detection")
print("7. Crop Price Forecasting")
print("8. Exit")
choice = input("\nSelect an option (1-8): ")
if choice == '1':
crop_health_monitoring()
elif choice == '2':
smart_irrigation()
elif choice == '3':
crop_yield_prediction()
elif choice == '4':
soil_health_analysis()
elif choice == '5':
weather_prediction()
elif choice == '6':
weed_detection()
elif choice == '7':
crop_price_forecasting()
elif choice == '8':
print("Exiting... Goodbye!")
break
else:
print("Invalid choice. Please try again.")

# 1. Crop Health Monitoring (Basic Simulation)


def crop_health_monitoring():
print("\nCrop Health Monitoring")
image_path = input("Enter path to crop image: ")
if os.path.exists(image_path):
image = cv2.imread(image_path)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
_, thresh = cv2.threshold(gray, 128, 255, cv2.THRESH_BINARY)
print("Image processed for crop health analysis.")
plt.imshow(cv2.cvtColor(thresh, cv2.COLOR_BGR2RGB))
plt.show()
else:
print("Image not found. Please check the path.")
# 2. Smart Irrigation System
def smart_irrigation():
print("\nSmart Irrigation System")
soil_moisture = float(input("Enter soil moisture percentage (0-100): "))
if soil_moisture < 30:
print("Irrigation required.")
else:
print("Soil moisture is sufficient.")

# 3. Crop Yield Prediction


def crop_yield_prediction():
print("\nCrop Yield Prediction")
data = {'Rainfall': [100, 200, 150, 300, 250],
'Fertilizer': [20, 30, 25, 35, 30],
'Yield': [3000, 3500, 3200, 4000, 3700]}
df = pd.DataFrame(data)
X = df[['Rainfall', 'Fertilizer']]
y = df['Yield']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3,
random_state=42)
model = LinearRegression()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
print(f"Predicted Yield: {predictions}")
print(f"Mean Squared Error: {mean_squared_error(y_test, predictions)}")

# 4. Soil Health Analysis (Basic Simulation)


def soil_health_analysis():
print("\nSoil Health Analysis")
ph_level = float(input("Enter soil pH level (0-14): "))
if 6 <= ph_level <= 7.5:
print("Soil pH is optimal.")
else:
print("Soil pH is not ideal. Amendments required.")

# 5. Weather Prediction (Simple Simulation)


def weather_prediction():
print("\nWeather Prediction")
temp = float(input("Enter today's temperature (°C): "))
if temp > 35:
print("Hot weather expected.")
elif 25 <= temp <= 35:
print("Moderate weather expected.")
else:
print("Cold weather expected.")

# 6. Weed Detection (Basic Image Processing)


def weed_detection():
print("\nWeed Detection")
image_path = input("Enter path to field image: ")
if os.path.exists(image_path):
image = cv2.imread(image_path)
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
lower_green = np.array([25, 40, 40])
upper_green = np.array([90, 255, 255])
mask = cv2.inRange(hsv, lower_green, upper_green)
print("Weed detection completed.")
plt.imshow(mask, cmap='gray')
plt.show()
else:
print("Image not found. Please check the path.")

# 7. Crop Price Forecasting (Simple Simulation)


def crop_price_forecasting():
print("\nCrop Price Forecasting")
past_prices = [1000, 1100, 1050, 1200, 1150]
future_price = np.mean(past_prices) * 1.05
print(f"Predicted crop price next month: ₹{future_price:.2f}")

# Run the program


if __name__ == '__main__':
main_menu()

You might also like