Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +591 -765
src/streamlit_app.py
CHANGED
|
@@ -3,9 +3,8 @@ import pandas as pd
|
|
| 3 |
import numpy as np
|
| 4 |
from datetime import datetime, timedelta
|
| 5 |
import logging
|
| 6 |
-
from pathlib import Path
|
| 7 |
import requests
|
| 8 |
-
from typing import Optional, Dict, List,
|
| 9 |
import json
|
| 10 |
from io import BytesIO
|
| 11 |
from PIL import Image
|
|
@@ -14,9 +13,12 @@ import os
|
|
| 14 |
import sqlite3
|
| 15 |
import hashlib
|
| 16 |
|
| 17 |
-
#
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# Image Recognition
|
| 22 |
try:
|
|
@@ -62,404 +64,17 @@ except ImportError:
|
|
| 62 |
logging.basicConfig(level=logging.INFO)
|
| 63 |
logger = logging.getLogger(__name__)
|
| 64 |
|
| 65 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 66 |
-
# LANGUAGE TRANSLATION DICTIONARY
|
| 67 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 68 |
-
|
| 69 |
-
TRANSLATIONS = {
|
| 70 |
-
"Hindi": {
|
| 71 |
-
"title": "๐พ เคเคฟเคธเคพเคจ เคธเคพเคฅเฅ v4.0",
|
| 72 |
-
"subtitle": "๐ค เคเคตเคพเค เคเฅ เคฎเคพเคงเฅเคฏเคฎ เคธเฅ เคฌเคพเคค เคเคฐเฅเค - เคเคธเคพเคจ เคเคฐ เคธเคฐเคฒ!",
|
| 73 |
-
"settings": "โ๏ธ เคธเฅเคเคฟเคเคเฅเคธ",
|
| 74 |
-
"location": "๐ เคเคชเคเคพ เคธเฅเคฅเคพเคจ",
|
| 75 |
-
"language": "๐ เคญเคพเคทเคพ",
|
| 76 |
-
"alerts": "๐ เค
เคฒเคฐเฅเค",
|
| 77 |
-
"all_conditions_normal": "โ
เคธเคญเฅ เคธเฅเคฅเคฟเคคเคฟเคฏเคพเค เคธเคพเคฎเคพเคจเฅเคฏ เคนเฅเค!",
|
| 78 |
-
"frost_risk": "โ๏ธ เค เคเคก เคเคพ เคเคคเคฐเคพ! เคจเคพเคเฅเค เคซเคธเคฒเฅเค เคเฅ เคฌเคเคพเคเค",
|
| 79 |
-
"high_temp": "๐ฅ เค
เคงเคฟเค เคคเคพเคชเคฎเคพเคจ! เคธเคฟเคเคเคพเค เคฌเคขเคผเคพเคเค",
|
| 80 |
-
"high_humidity": "๐ฆ เค
เคงเคฟเค เคจเคฎเฅ! เคเคตเค เคฐเฅเคเฅเค เคเฅ เคฒเคฟเค เคธเคพเคตเคงเคพเคจ เคฐเคนเฅเค",
|
| 81 |
-
"voice_assistant": "๐ฃ๏ธ เคเคตเคพเค เคธเคนเคพเคฏเค",
|
| 82 |
-
"weather": "๐ค๏ธ เคฎเฅเคธเคฎ",
|
| 83 |
-
"market": "๐ฐ เคฌเคพเคเคพเคฐ",
|
| 84 |
-
"crops": "๐ฑ เคซเคธเคฒเฅเค",
|
| 85 |
-
"pests": "๐ เคเฅเค",
|
| 86 |
-
"irrigation": "๐ง เคธเคฟเคเคเคพเค",
|
| 87 |
-
"analytics": "๐ เคตเคฟเคถเฅเคฒเฅเคทเคฃ",
|
| 88 |
-
"disease": "๐ธ เคฐเฅเค",
|
| 89 |
-
"other": "๐ค เค
เคจเฅเคฏ",
|
| 90 |
-
"soil": "๐งช เคฎเคฟเคเฅเคเฅ",
|
| 91 |
-
"yield": "๐ เคซเคธเคฒ",
|
| 92 |
-
"profile": "๐ค เคชเฅเคฐเฅเคซเคพเคเคฒ",
|
| 93 |
-
"speak_with_voice": "### ๐ค เคเคตเคพเค เคธเฅ เคฌเคพเคค เคเคฐเฅเค",
|
| 94 |
-
"what_you_want": "#### เคเฅเคฏเคพ เคเคช เคเคพเคจเคจเคพ เคเคพเคนเคคเฅ เคนเฅเค?",
|
| 95 |
-
"rainfall_info": "เคฌเคพเคฐเคฟเคถ เคเฅ เคเคพเคจเคเคพเคฐเฅ",
|
| 96 |
-
"pest_problem": "เคเฅเค เคเฅ เคธเคฎเคธเฅเคฏเคพ",
|
| 97 |
-
"market_prices": "เคฌเคพเคเคพเคฐ เคญเคพเคต",
|
| 98 |
-
"speak_question": "๐๏ธ เค
เคชเคจเฅ เคเคตเคพเค เคธเฅ เคชเฅเคเฅเค",
|
| 99 |
-
"microphone_on": "๐๏ธ เคฎเคพเคเคเฅเคฐเฅเคซเฅเคจ เคเคพเคฒเฅ เคเคฐเฅเค",
|
| 100 |
-
"hear_answer": "๐ เคเคตเคพเคฌ เคธเฅเคจเฅเค",
|
| 101 |
-
"listening": "๐๏ธ เคธเฅเคจเคฟเค... เคฌเฅเคฒเคฟเค!",
|
| 102 |
-
"you_said": "เคเคชเคจเฅ เคเคนเคพ:",
|
| 103 |
-
"weather_unavailable": "เคฎเฅเคธเคฎ เคกเฅเคเคพ เคเคชเคฒเคฌเฅเคง เคจเคนเฅเค เคนเฅ",
|
| 104 |
-
"upload_photo_disease": "๐ธ เคชเคคเฅเคคเฅ เคเฅ เคซเฅเคเฅ เค
เคชเคฒเฅเคก เคเคฐเคจเฅ เคเฅ เคฒเคฟเค 'เคฐเฅเค' เคเฅเคฌ เคชเคฐ เคเคพเคเค",
|
| 105 |
-
"go_disease_tab": "เคเฅเคชเคฏเคพ เคฐเฅเค เคเฅเคฌ เคชเคฐ เคเคพเคเคฐ เคชเคคเฅเคคเฅ เคเฅ เคคเคธเฅเคตเฅเคฐ เค
เคชเคฒเฅเคก เคเคฐเฅเค",
|
| 106 |
-
"browser_no_mic": "เคเคชเคเฅ เคฌเฅเคฐเคพเคเคเคผเคฐ เคฎเฅเค เคฎเคพเคเคเฅเคฐเฅเคซเฅเคจ เคธเคชเฅเคฐเฅเค เคจเคนเฅเค เคนเฅ",
|
| 107 |
-
"weather_info": "### ๐ค๏ธ เคฎเฅเคธเคฎ เคเฅ เคเคพเคจเคเคพเคฐเฅ",
|
| 108 |
-
"refresh_weather": "๐ เคฎเฅเคธเคฎ เค
เคชเคกเฅเค เคเคฐเฅเค",
|
| 109 |
-
"loading": "เคกเฅเคเคพ เคฒเฅเคก เคนเฅ เคฐเคนเคพ เคนเฅ...",
|
| 110 |
-
"temperature": "๐ก๏ธ เคคเคพเคชเคฎเคพเคจ",
|
| 111 |
-
"humidity": "๐ง เคจเคฎเฅ",
|
| 112 |
-
"wind": "๐จ เคนเคตเคพ",
|
| 113 |
-
"market_prices_title": "### ๐ฐ เคฌเคพเคเคพเคฐ เคญเคพเคต",
|
| 114 |
-
"refresh_prices": "๐ เคญเคพเคต เค
เคชเคกเฅเค เคเคฐเฅเค",
|
| 115 |
-
"per_quintal": "/เคเฅเคตเคฟเคเคเคฒ",
|
| 116 |
-
"crop_suggestions": "### ๐ฑ เคซเคธเคฒ เคเฅ เคธเฅเคเคพเคต",
|
| 117 |
-
"best_crops": "๐ เคเคชเคเฅ เคเฅเคทเฅเคคเฅเคฐ เคฎเฅเค เคธ๏ฟฝ๏ฟฝ๏ฟฝเฅเคตเคถเฅเคฐเฅเคทเฅเค เคซเคธเคฒเฅเค: เคเคชเคพเคธ, เคเฅเคนเฅเค, เคเคพเคตเคฒ, เคเคจเฅเคจเคพ",
|
| 118 |
-
"current_season": "๐
เคฎเฅเคธเคฎ:",
|
| 119 |
-
"pest_management": "### ๐ เคเฅเค เคชเฅเคฐเคฌเคเคงเคจ",
|
| 120 |
-
"pest_info": "เคเฅเคเฅเค เคเฅ เคชเคนเคเคพเคจ เคเคฐ เคจเคฟเคฏเคเคคเฅเคฐเคฃ เคเฅ เคธเฅเคเคพเคต เคฏเคนเคพเค เคฎเคฟเคฒเฅเคเคเฅ",
|
| 121 |
-
"irrigation_management": "### ๐ง เคธเคฟเคเคเคพเค เคชเฅเคฐเคฌเคเคงเคจ",
|
| 122 |
-
"irrigation_info": "เคธเฅเคฎเคพเคฐเฅเค เคธเคฟเคเคเคพเค เค
เคจเฅเคธเฅเคเฅ เคเคฐ เคเคฒ เคธเคเคฐเคเฅเคทเคฃ เคเคฟเคชเฅเคธ",
|
| 123 |
-
"farm_analytics": "### ๐ เคเฅเคค เคตเคฟเคถเฅเคฒเฅเคทเคฃ",
|
| 124 |
-
"analytics_info": "เคฒเคพเคญ เคเคฃเคจเคพ เคเคฐ เคเฅเคค เคเฅ เคเคเคเคกเคผเฅ เคฏเคนเคพเค เคฆเคฟเคเฅเคเคเฅ",
|
| 125 |
-
"disease_detection": "### ๐ธ เคฐเฅเค เคชเคนเคเคพเคจ (เคชเคคเฅเคคเฅ เคเฅ เคซเฅเคเฅ เคฒเคเคพเคเค)",
|
| 126 |
-
"upload_leaf": "๐ท เคชเคคเฅเคคเฅ เคเฅ เคคเคธเฅเคตเฅเคฐ เคเฅเคจเฅเค",
|
| 127 |
-
"your_photo": "เคเคชเคเฅ เคคเคธเฅเคตเฅเคฐ",
|
| 128 |
-
"analyze": "๐ เคตเคฟเคถเฅเคฒเฅเคทเคฃ เคเคฐเฅเค",
|
| 129 |
-
"analysis_complete": "โ
เคตเคฟเคถเฅเคฒเฅเคทเคฃ เคชเฅเคฐเคพ!",
|
| 130 |
-
"disease": "เคฐเฅเค",
|
| 131 |
-
"confidence": "เคตเคฟเคถเฅเคตเคพเคธ",
|
| 132 |
-
"severity": "เคเคเคญเฅเคฐเคคเคพ",
|
| 133 |
-
"image_recognition_unavailable": "โ ๏ธ เคเคตเคฟ เคชเคนเคเคพเคจ เคเคชเคฒเคฌเฅเคง เคจเคนเฅเค เคนเฅ",
|
| 134 |
-
"soil_check": "### ๐งช เคฎเคฟเคเฅเคเฅ เคเฅ เคเคพเคเค",
|
| 135 |
-
"soil_ph": "เคฎเคฟเคเฅเคเฅ เคเคพ pH",
|
| 136 |
-
"nitrogen": "เคจเคพเคเคเฅเคฐเฅเคเคจ (mg/kg)",
|
| 137 |
-
"phosphorus": "เคซเฅเคธเฅเคซเฅเคฐเคธ (mg/kg)",
|
| 138 |
-
"potassium": "เคชเฅเคเฅเคถเคฟเคฏเคฎ (mg/kg)",
|
| 139 |
-
"organic_matter": "เคเฅเคต เคชเคฆเคพเคฐเฅเคฅ (%)",
|
| 140 |
-
"moisture": "เคจเคฎเฅ (%)",
|
| 141 |
-
"save_soil_test": "๐พ เคฎเคฟเคเฅเคเฅ เคชเคฐเฅเคเฅเคทเคฃ เคธเคนเฅเคเฅเค",
|
| 142 |
-
"saved": "โ
เคธเคนเฅเคเคพ เคเคฏเคพ!",
|
| 143 |
-
"recommendations": "### ๐ เคธเฅเคเคพเคต:",
|
| 144 |
-
"acidic_soil": "๐ด **เค
เคฎเฅเคฒเฅเคฏ เคฎเคฟเคเฅเคเฅ**: เคเฅเคจเคพ (CaCO3) เคฒเคเคพเคเค",
|
| 145 |
-
"alkaline_soil": "๐ด **เคเฅเคทเคพเคฐเฅเคฏ เคฎเคฟเคเฅเคเฅ**: เคเคเคงเค เคฏเคพ เคเฅเคต เคชเคฆเคพเคฐเฅเคฅ เคฒเคเคพเคเค",
|
| 146 |
-
"ideal_ph": "โ
**เคเคฆเคฐเฅเคถ pH**: 6.5-7.5 เคเฅ เคฌเฅเค เค
เคเฅเคเคพ เคนเฅ",
|
| 147 |
-
"low_nitrogen": "๐ก **เคเคฎ เคจเคพเคเคเฅเคฐเฅเคเคจ**: NPK 20:20:0 เคฒเคเคพเคเค",
|
| 148 |
-
"high_nitrogen": "๐ก **เค
เคงเคฟเค เคจเคพเคเคเฅเคฐเฅเคเคจ**: เคจเคพเคเคเฅเคฐเฅเคเคจ เคเคฎ เคเคฐเฅเค",
|
| 149 |
-
"ideal_nitrogen": "โ
**เคเคฆเคฐเฅเคถ เคจเคพเคเคเฅเคฐเฅเคเคจ**: เค
เคเฅเคเคพ เคธเฅเคคเคฐ",
|
| 150 |
-
"low_phosphorus": "๐ก **เคเคฎ เคซเฅเคธเฅเคซเฅเคฐเคธ**: DAP เคฏเคพ SSP เคฒเคเคพเคเค",
|
| 151 |
-
"ideal_phosphorus": "โ
**เคเคฆเคฐเฅเคถ เคซเฅเคธเฅเคซเฅเคฐเคธ**: เค
เคเฅเคเคพ เคธเฅเคคเคฐ",
|
| 152 |
-
"low_potassium": "๐ก **เคเคฎ เคชเฅเคเฅเคถเคฟเคฏเคฎ**: KCl เคฏเคพ MOP เคฒเคเคพเคเค",
|
| 153 |
-
"ideal_potassium": "โ
**เคเคฆเคฐเฅเคถ เคชเฅเคเฅเคถเคฟเคฏเคฎ**: เค
เคเฅเคเคพ เคธเฅเคคเคฐ",
|
| 154 |
-
"yield_prediction": "### ๐ เคซเคธเคฒ เคเฅ เคเคชเค เคเคพ เค
เคจเฅเคฎเคพเคจ",
|
| 155 |
-
"temp_celsius": "เคคเคพเคชเคฎเคพเคจ (ยฐC)",
|
| 156 |
-
"humidity_percent": "เคจเคฎเฅ (%)",
|
| 157 |
-
"rainfall_mm": "เคฌเคพเคฐเคฟเคถ (mm)",
|
| 158 |
-
"predict_yield": "๐ฎ เคเคชเค เคเฅ เคญเคตเคฟเคทเฅเคฏเคตเคพเคฃเฅ เคเคฐเฅเค",
|
| 159 |
-
"estimated_yield": "๐ เค
เคจเฅเคฎเคพเคจเคฟเคค เคเคชเค:",
|
| 160 |
-
"quintal_hectare": "เคเฅเคตเคฟเคเคเคฒ/เคนเฅเคเฅเคเฅเคฏเคฐ",
|
| 161 |
-
"high_yield": "โ
เคเคเฅเค เคเคชเค เคเฅ เคเคฎเฅเคฎเฅเคฆ เคนเฅ!",
|
| 162 |
-
"average_yield": "๐ เคเคธเคค เคเคชเค เคเฅ เคเคฎเฅเคฎเฅเคฆ เคนเฅ",
|
| 163 |
-
"low_yield": "โ ๏ธ เคเคฎ เคเคชเค เคนเฅ เคธเคเคคเฅ เคนเฅเฅค เคฎเคฟเคเฅเคเฅ เคเคฐ เคฎเฅเคธเคฎ เคเฅ เคเคพเคเค เคเคฐเฅเค",
|
| 164 |
-
"profile_settings": "### ๐ค เคชเฅเคฐเฅเคซเคพเคเคฒ & เคธเฅเคเคฟเคเคเฅเคธ",
|
| 165 |
-
"choose_option": "เคตเคฟเคเคฒเฅเคช เคเฅเคจเฅเค",
|
| 166 |
-
"login": "๐ เคฒเฅเคเคฟเคจ",
|
| 167 |
-
"register": "๐ เคฐเคเคฟเคธเฅเคเคฐ",
|
| 168 |
-
"login_title": "เคฒเฅเคเคฟเคจ เคเคฐเฅเค",
|
| 169 |
-
"username": "เคเคชเคฏเฅเคเคเคฐเฅเคคเคพ เคจเคพเคฎ",
|
| 170 |
-
"password": "เคชเคพเคธเคตเคฐเฅเคก",
|
| 171 |
-
"login_btn": "เคฒเฅเคเคฟเคจ",
|
| 172 |
-
"login_success": "โ
เคฒเฅเคเคฟเคจ เคธเคซเคฒ!",
|
| 173 |
-
"invalid_credentials": "โ เคเคฒเคค เคเฅเคฐเฅเคกเฅเคเคถเคฟเคฏเคฒเฅเคธ",
|
| 174 |
-
"register_title": "เคจเคฏเคพ เคเคพเคคเคพ เคฌเคจเคพเคเค",
|
| 175 |
-
"email": "เคเคฎเฅเคฒ",
|
| 176 |
-
"register_btn": "เคฐเคเคฟเคธเฅเคเคฐ",
|
| 177 |
-
"registration_success": "โ
เคฐเคเคฟเคธเฅเคเฅเคฐเฅเคถเคจ เคธเคซเคฒ! เค
เคฌ เคฒเฅเคเคฟเคจ เคเคฐเฅเค",
|
| 178 |
-
"logged_in_as": "โ
เคฒเฅเคเคฟเคจ เคเคฟเคฏเคพ เคนเฅเค:",
|
| 179 |
-
"logout_btn": "เคฒเฅเคเคเคเค",
|
| 180 |
-
"footer": "๐พ เคเคฟเคธเคพเคจ เคธเคพเคฅเฅ v4.0 - เคธเคญเฅ เคเคฟเคธเคพเคจเฅเค เคเฅ เคฒเคฟเค | ๐ เคเคธเคพเคจ, เคธเคฐเคฒ, เคเคฐ เคฎเฅเคซเฅเคค",
|
| 181 |
-
"kharif": "เคเคฐเฅเคซ (Kharif)",
|
| 182 |
-
"rabi": "เคฐเคฌเฅ (Rabi)",
|
| 183 |
-
"summer": "เคเคฐเฅเคฎเฅ (Summer)",
|
| 184 |
-
"wheat": "เคเฅเคนเฅเค (Wheat)",
|
| 185 |
-
"rice": "เคเคพเคตเคฒ (Rice)",
|
| 186 |
-
"cotton": "เคเคชเคพเคธ (Cotton)",
|
| 187 |
-
"sugarcane": "เคเคจเฅเคจเคพ (Sugarcane)",
|
| 188 |
-
"potato": "เคเคฒเฅ (Potato)",
|
| 189 |
-
"tomato": "เคเคฎเคพเคเคฐ (Tomato)",
|
| 190 |
-
"onion": "เคชเฅเคฏเคพเค (Onion)",
|
| 191 |
-
"corn": "เคฎเคเฅเคเคพ (Corn)",
|
| 192 |
-
},
|
| 193 |
-
|
| 194 |
-
"English": {
|
| 195 |
-
"title": "๐พ Farmer Copilot v4.0",
|
| 196 |
-
"subtitle": "๐ค Speak with Voice - Easy and Simple!",
|
| 197 |
-
"settings": "โ๏ธ Settings",
|
| 198 |
-
"location": "๐ Your Location",
|
| 199 |
-
"language": "๐ Language",
|
| 200 |
-
"alerts": "๐ Alerts",
|
| 201 |
-
"all_conditions_normal": "โ
All conditions normal!",
|
| 202 |
-
"frost_risk": "โ๏ธ Frost Risk! Protect delicate crops",
|
| 203 |
-
"high_temp": "๐ฅ High Temperature! Increase irrigation",
|
| 204 |
-
"high_humidity": "๐ฆ High Humidity! Watch for fungal diseases",
|
| 205 |
-
"voice_assistant": "๐ฃ๏ธ Voice Assistant",
|
| 206 |
-
"weather": "๐ค๏ธ Weather",
|
| 207 |
-
"market": "๐ฐ Market",
|
| 208 |
-
"crops": "๐ฑ Crops",
|
| 209 |
-
"pests": "๐ Pests",
|
| 210 |
-
"irrigation": "๐ง Irrigation",
|
| 211 |
-
"analytics": "๐ Analytics",
|
| 212 |
-
"disease": "๐ธ Disease",
|
| 213 |
-
"other": "๐ค Other",
|
| 214 |
-
"soil": "๐งช Soil",
|
| 215 |
-
"yield": "๐ Yield",
|
| 216 |
-
"profile": "๐ค Profile",
|
| 217 |
-
"speak_with_voice": "### ๐ค Speak with Your Voice",
|
| 218 |
-
"what_you_want": "#### What do you want to know?",
|
| 219 |
-
"rainfall_info": "Rainfall Information",
|
| 220 |
-
"pest_problem": "Pest Problem",
|
| 221 |
-
"market_prices": "Market Prices",
|
| 222 |
-
"speak_question": "๐๏ธ Ask with Your Voice",
|
| 223 |
-
"microphone_on": "๐๏ธ Turn On Microphone",
|
| 224 |
-
"hear_answer": "๐ Hear Answer",
|
| 225 |
-
"listening": "๐๏ธ Listening... Speak now!",
|
| 226 |
-
"you_said": "You said:",
|
| 227 |
-
"weather_unavailable": "Weather data not available",
|
| 228 |
-
"upload_photo_disease": "๐ธ Upload leaf photo in Disease tab",
|
| 229 |
-
"go_disease_tab": "Please go to Disease tab and upload leaf photo",
|
| 230 |
-
"browser_no_mic": "Your browser does not support microphone",
|
| 231 |
-
"weather_info": "### ๐ค๏ธ Weather Information",
|
| 232 |
-
"refresh_weather": "๐ Refresh Weather",
|
| 233 |
-
"loading": "Loading data...",
|
| 234 |
-
"temperature": "๐ก๏ธ Temperature",
|
| 235 |
-
"humidity": "๐ง Humidity",
|
| 236 |
-
"wind": "๐จ Wind",
|
| 237 |
-
"market_prices_title": "### ๐ฐ Market Prices",
|
| 238 |
-
"refresh_prices": "๐ Refresh Prices",
|
| 239 |
-
"per_quintal": "/quintal",
|
| 240 |
-
"crop_suggestions": "### ๐ฑ Crop Suggestions",
|
| 241 |
-
"best_crops": "๐ Best crops for your region: Cotton, Wheat, Rice, Sugarcane",
|
| 242 |
-
"current_season": "๐
Season:",
|
| 243 |
-
"pest_management": "### ๐ Pest Management",
|
| 244 |
-
"pest_info": "Pest identification and control tips here",
|
| 245 |
-
"irrigation_management": "### ๐ง Irrigation Management",
|
| 246 |
-
"irrigation_info": "Smart irrigation schedule and water conservation tips",
|
| 247 |
-
"farm_analytics": "### ๐ Farm Analytics",
|
| 248 |
-
"analytics_info": "Profit calculation and farm statistics here",
|
| 249 |
-
"disease_detection": "### ๐ธ Disease Detection (Upload Leaf Photo)",
|
| 250 |
-
"upload_leaf": "๐ท Choose Leaf Photo",
|
| 251 |
-
"your_photo": "Your Photo",
|
| 252 |
-
"analyze": "๐ Analyze",
|
| 253 |
-
"analysis_complete": "โ
Analysis Complete!",
|
| 254 |
-
"disease": "Disease",
|
| 255 |
-
"confidence": "Confidence",
|
| 256 |
-
"severity": "Severity",
|
| 257 |
-
"image_recognition_unavailable": "โ ๏ธ Image recognition not available",
|
| 258 |
-
"soil_check": "### ๐งช Soil Check",
|
| 259 |
-
"soil_ph": "Soil pH",
|
| 260 |
-
"nitrogen": "Nitrogen (mg/kg)",
|
| 261 |
-
"phosphorus": "Phosphorus (mg/kg)",
|
| 262 |
-
"potassium": "Potassium (mg/kg)",
|
| 263 |
-
"organic_matter": "Organic Matter (%)",
|
| 264 |
-
"moisture": "Moisture (%)",
|
| 265 |
-
"save_soil_test": "๐พ Save Soil Test",
|
| 266 |
-
"saved": "โ
Saved!",
|
| 267 |
-
"recommendations": "### ๐ Recommendations:",
|
| 268 |
-
"acidic_soil": "๐ด **Acidic Soil**: Apply lime (CaCO3)",
|
| 269 |
-
"alkaline_soil": "๐ด **Alkaline Soil**: Apply sulfur or organic matter",
|
| 270 |
-
"ideal_ph": "โ
**Ideal pH**: Between 6.5-7.5",
|
| 271 |
-
"low_nitrogen": "๐ก **Low Nitrogen**: Apply NPK 20:20:0",
|
| 272 |
-
"high_nitrogen": "๐ก **High Nitrogen**: Reduce nitrogen fertilizer",
|
| 273 |
-
"ideal_nitrogen": "โ
**Ideal Nitrogen**: Good level",
|
| 274 |
-
"low_phosphorus": "๐ก **Low Phosphorus**: Apply DAP or SSP",
|
| 275 |
-
"ideal_phosphorus": "โ
**Ideal Phosphorus**: Good level",
|
| 276 |
-
"low_potassium": "๐ก **Low Potassium**: Apply KCl or MOP",
|
| 277 |
-
"ideal_potassium": "โ
**Ideal Potassium**: Good level",
|
| 278 |
-
"yield_prediction": "### ๐ Crop Yield Prediction",
|
| 279 |
-
"temp_celsius": "Temperature (ยฐC)",
|
| 280 |
-
"humidity_percent": "Humidity (%)",
|
| 281 |
-
"rainfall_mm": "Rainfall (mm)",
|
| 282 |
-
"predict_yield": "๐ฎ Predict Yield",
|
| 283 |
-
"estimated_yield": "๐ Estimated Yield:",
|
| 284 |
-
"quintal_hectare": "quintal/hectare",
|
| 285 |
-
"high_yield": "โ
High yield expected!",
|
| 286 |
-
"average_yield": "๐ Average yield expected",
|
| 287 |
-
"low_yield": "โ ๏ธ Low yield possible. Check soil and weather",
|
| 288 |
-
"profile_settings": "### ๐ค Profile & Settings",
|
| 289 |
-
"choose_option": "Choose Option",
|
| 290 |
-
"login": "๐ Login",
|
| 291 |
-
"register": "๐ Register",
|
| 292 |
-
"login_title": "Login",
|
| 293 |
-
"username": "Username",
|
| 294 |
-
"password": "Password",
|
| 295 |
-
"login_btn": "Login",
|
| 296 |
-
"login_success": "โ
Login successful!",
|
| 297 |
-
"invalid_credentials": "โ Invalid credentials",
|
| 298 |
-
"register_title": "Create New Account",
|
| 299 |
-
"email": "Email",
|
| 300 |
-
"register_btn": "Register",
|
| 301 |
-
"registration_success": "โ
Registration successful! Login now",
|
| 302 |
-
"logged_in_as": "โ
Logged in as:",
|
| 303 |
-
"logout_btn": "Logout",
|
| 304 |
-
"footer": "๐พ Farmer Copilot v4.0 - For All Farmers | ๐ Easy, Simple, and Free",
|
| 305 |
-
"kharif": "Kharif",
|
| 306 |
-
"rabi": "Rabi",
|
| 307 |
-
"summer": "Summer",
|
| 308 |
-
"wheat": "Wheat",
|
| 309 |
-
"rice": "Rice",
|
| 310 |
-
"cotton": "Cotton",
|
| 311 |
-
"sugarcane": "Sugarcane",
|
| 312 |
-
"potato": "Potato",
|
| 313 |
-
"tomato": "Tomato",
|
| 314 |
-
"onion": "Onion",
|
| 315 |
-
"corn": "Corn",
|
| 316 |
-
},
|
| 317 |
-
|
| 318 |
-
"Marathi": {
|
| 319 |
-
"title": "๐พ เคถเฅเคคเคเคฐเฅ เคธเคนเคเคพเคฐ v4.0",
|
| 320 |
-
"subtitle": "๐ค เคเคตเคพเคเคพเคจเฅ เคฌเฅเคฒเคพ - เคธเฅเคชเฅ เคเคฃเคฟ เคธเคฐเคฒ!",
|
| 321 |
-
"settings": "โ๏ธ เคธเฅเคเคฟเคเคเฅเคธ",
|
| 322 |
-
"location": "๐ เคเคชเคฒเฅ เคธเฅเคฅเคพเคจ",
|
| 323 |
-
"language": "๐ เคญเคพเคทเคพ",
|
| 324 |
-
"alerts": "๐ เคธเฅเคเคจเคพ",
|
| 325 |
-
"all_conditions_normal": "โ
เคธเคฐเฅเคต เคธเฅเคฅเคฟเคคเฅ เคธเคพเคฎเคพเคจเฅเคฏ เคเคนเฅ!",
|
| 326 |
-
"frost_risk": "โ๏ธ เคนเคฟเคฎเคพเคเคเคพเคเคพ เคงเฅเคเคพ! เคจเคพเคเฅเค เคชเคฟเคเคพเคเคเฅ เคธเคเคฐเคเฅเคทเคฃ เคเคฐเคพ",
|
| 327 |
-
"high_temp": "๐ฅ เคเคเฅเค เคคเคพเคชเคฎเคพเคจ! เคธเคฟเคเคเคพเค เคตเคพเคขเคตเคพ",
|
| 328 |
-
"high_humidity": "๐ฆ เคเคเฅเค เคเคฐเฅเคฆเฅเคฐเคคเคพ! เคฌเฅเคฐเคถเฅ เคฐเฅเคเคพเคเคธเคพเค เฅ เคธเคพเคตเคงเคพเคจ เคฐเคนเคพ",
|
| 329 |
-
"voice_assistant": "๐ฃ๏ธ เคเคตเคพเค เคธเคนเคพเคฏเค",
|
| 330 |
-
"weather": "๐ค๏ธ เคนเคตเคพเคฎเคพเคจ",
|
| 331 |
-
"market": "๐ฐ เคฌเคพเคเคพเคฐ",
|
| 332 |
-
"crops": "๐ฑ เคชเคฟเคเฅ",
|
| 333 |
-
"pests": "๐ เคเฅเคเค",
|
| 334 |
-
"irrigation": "๐ง เคธเคฟเคเคเคจ",
|
| 335 |
-
"analytics": "๐ เคตเคฟเคถเฅเคฒเฅเคทเคฃ",
|
| 336 |
-
"disease": "๐ธ เคฐเฅเค",
|
| 337 |
-
"other": "๐ค เคเคคเคฐ",
|
| 338 |
-
"soil": "๐งช เคฎเคพเคคเฅเคเคพ",
|
| 339 |
-
"yield": "๐ เคเคคเฅเคชเคพเคฆเคจ",
|
| 340 |
-
"profile": "๐ค เคชเฅเคฐเฅเคซเคพเคเคฒ",
|
| 341 |
-
"speak_with_voice": "### ๐ค เคเคตเคพเคเคพเคจเฅ เคฌเฅเคฒเคพ",
|
| 342 |
-
"what_you_want": "#### เคคเฅเคฎเฅเคนเคพเคฒเคพ เคเคพเคฏ เคเคพเคฃเฅเคจ เคเฅเคฏเคพเคฏเคเฅ เคเคนเฅ?",
|
| 343 |
-
"rainfall_info": "เคชเคพเคเคธ เคฎเคพเคนเคฟเคคเฅ",
|
| 344 |
-
"pest_problem": "เคเฅเคเค เคธเคฎเคธเฅเคฏเคพ",
|
| 345 |
-
"market_prices": "เคฌเคพเคเคพเคฐ เคฆเคฐ",
|
| 346 |
-
"speak_question": "๐๏ธ เคเคตเคพเคเคพเคจเฅ เคชเฅเคฐเคถเฅเคจ เคตเคฟเคเคพเคฐเคพ",
|
| 347 |
-
"microphone_on": "๐๏ธ เคฎเคพเคฏเคเฅเคฐเฅเคซเฅเคจ เคเคพเคฒเฅ เคเคฐเคพ",
|
| 348 |
-
"hear_answer": "๐ เคเคคเฅเคคเคฐ เคเคเคพ",
|
| 349 |
-
"listening": "๐๏ธ เคเคเคคเฅ เคเคนเฅ... เคฌเฅเคฒเคพ!",
|
| 350 |
-
"you_said": "เคคเฅเคฎเฅเคนเฅ เคฎเฅเคนเคฃเคพเคฒเคพเคค:",
|
| 351 |
-
"weather_unavailable": "เคนเคตเคพเคฎเคพเคจ เคกเฅเคเคพ เคเคชเคฒเคฌเฅเคง เคจเคพเคนเฅ",
|
| 352 |
-
"upload_photo_disease": "๐ธ เคฐเฅเค เคเฅ
เคฌเคฎเคงเฅเคฏเฅ เคชเคพเคจ เคซเฅเคเฅ เค
เคชเคฒเฅเคก เคเคฐเคพ",
|
| 353 |
-
"go_disease_tab": "เคเฅเคชเคฏเคพ เคฐเฅเค เคเฅ
เคฌเคฎเคงเฅเคฏเฅ เคเคพ เคเคฃเคฟ เคชเคพเคจ เคซเฅเคเฅ เค
เคชเคฒเฅเคก เคเคฐเคพ",
|
| 354 |
-
"browser_no_mic": "เคเคชเคฒเฅเคฏเคพ เคฌเฅเคฐเคพเคเคเคฐเคฒเคพ เคฎเคพเคฏเคเฅเคฐเฅเคซเฅเคจ เคธเคฎเคฐเฅเคฅเคจ เคจเคพเคนเฅ",
|
| 355 |
-
"weather_info": "### ๐ค๏ธ เคนเคตเคพเคฎเคพเคจ เคฎเคพเคนเคฟเคคเฅ",
|
| 356 |
-
"refresh_weather": "๐ เคนเคตเคพเคฎเคพเคจ เคคเคพเคเฅ เคเคฐเคพ",
|
| 357 |
-
"loading": "เคกเฅเคเคพ เคฒเฅเคก เคนเฅเคค เคเคนเฅ...",
|
| 358 |
-
"temperature": "๐ก๏ธ เคคเคพเคชเคฎเคพเคจ",
|
| 359 |
-
"humidity": "๐ง เคเคฐเฅเคฆเฅเคฐเคคเคพ",
|
| 360 |
-
"wind": "๐จ เคตเคพเคฐเคพ",
|
| 361 |
-
"market_prices_title": "### ๐ฐ เคฌเคพเคเคพเคฐ เคฆเคฐ",
|
| 362 |
-
"refresh_prices": "๐ เคฆเคฐ เคคเคพเคเฅ เคเคฐเคพ",
|
| 363 |
-
"per_quintal": "/เคเฅเคตเคฟเคเคเคฒ",
|
| 364 |
-
"crop_suggestions": "### ๐ฑ เคชเคฟเคเคพเคเคเฅ เคธเฅเคเคจ",
|
| 365 |
-
"best_crops": "๐ เคเคชเคฒเฅเคฏเคพ เคชเฅเคฐเคฆเฅเคถเคพเคธเคพเค เฅ เคเคคเฅเคคเคฎ เคชเคฟเคเฅ: เคเคชเคพเคธ, เคเคนเฅ, เคคเคพเคเคฆเฅเคณ, เคเคธ",
|
| 366 |
-
"current_season": "๐
เคเคคเฅ:",
|
| 367 |
-
"pest_management": "### ๐ เคเฅเคเค เคตเฅเคฏเคตเคธเฅเคฅเคพเคชเคจ",
|
| 368 |
-
"pest_info": "เคเฅเคเค เคเคณเค ๏ฟฝ๏ฟฝเคฃเคฟ เคจเคฟเคฏเคเคคเฅเคฐเคฃ เคธเฅเคเคจเคพ เคฏเฅเคฅเฅ",
|
| 369 |
-
"irrigation_management": "### ๐ง เคธเคฟเคเคเคจ เคตเฅเคฏเคตเคธเฅเคฅเคพเคชเคจ",
|
| 370 |
-
"irrigation_info": "เคธเฅเคฎเคพเคฐเฅเค เคธเคฟเคเคเคจ เคตเฅเคณเคพเคชเคคเฅเคฐเค เคเคฃเคฟ เคเคฒ เคธเคเคฐเคเฅเคทเคฃ เคธเฅเคเคจเคพ",
|
| 371 |
-
"farm_analytics": "### ๐ เคถเฅเคค เคตเคฟเคถเฅเคฒเฅเคทเคฃ",
|
| 372 |
-
"analytics_info": "เคฒเคพเคญ เคเคฃเคจเคพ เคเคฃเคฟ เคถเฅเคค เคธเคพเคเคเฅเคฏเคฟเคเฅ เคฏเฅเคฅเฅ",
|
| 373 |
-
"disease_detection": "### ๐ธ เคฐเฅเค เคถเฅเคง (เคชเคพเคจ เคซเฅเคเฅ เค
เคชเคฒเฅเคก เคเคฐเคพ)",
|
| 374 |
-
"upload_leaf": "๐ท เคชเคพเคจ เคซเฅเคเฅ เคจเคฟเคตเคกเคพ",
|
| 375 |
-
"your_photo": "เคเคชเคฒเคพ เคซเฅเคเฅ",
|
| 376 |
-
"analyze": "๐ เคตเคฟเคถเฅเคฒเฅเคทเคฃ เคเคฐเคพ",
|
| 377 |
-
"analysis_complete": "โ
เคตเคฟเคถเฅเคฒเฅเคทเคฃ เคชเฅเคฐเฅเคฃ!",
|
| 378 |
-
"disease": "เคฐเฅเค",
|
| 379 |
-
"confidence": "เคเคคเฅเคฎเคตเคฟเคถเฅเคตเคพเคธ",
|
| 380 |
-
"severity": "เคคเฅเคตเฅเคฐเคคเคพ",
|
| 381 |
-
"image_recognition_unavailable": "โ ๏ธ เคชเฅเคฐเคคเคฟเคฎเคพ เคเคณเค เคเคชเคฒเคฌเฅเคง เคจเคพเคนเฅ",
|
| 382 |
-
"soil_check": "### ๐งช เคฎเคพเคคเฅ เคคเคชเคพเคธเคพ",
|
| 383 |
-
"soil_ph": "เคฎเคพเคคเฅเคเคพ pH",
|
| 384 |
-
"nitrogen": "เคจเคพเคฏเคเฅเคฐเฅเคเคจ (เคฎเคฟเคเฅเคฐเคพ/เคเคฟเคเฅเคฐเคพ)",
|
| 385 |
-
"phosphorus": "เคซเฅเคธเฅเคซเคฐเคธ (เคฎเคฟเคเฅเคฐเคพ/เคเคฟเคเฅเคฐเคพ)",
|
| 386 |
-
"potassium": "เคชเฅเคเฅ
เคถเคฟเคฏเคฎ (เคฎเคฟเคเฅเคฐเคพ/เคเคฟเคเฅเคฐเคพ)",
|
| 387 |
-
"organic_matter": "เคธเฅเคเคฆเฅเคฐเคฟเคฏ เคชเคฆเคพเคฐเฅเคฅ (%)",
|
| 388 |
-
"moisture": "เคเคฒเคพเคตเคพ (%)",
|
| 389 |
-
"save_soil_test": "๐พ เคฎเคพเคคเฅ เคเคพเคเคฃเฅ เคธเฅเคตเฅเคน เคเคฐเคพ",
|
| 390 |
-
"saved": "โ
เคธเฅเคตเฅเคน เคเฅเคฒเฅ!",
|
| 391 |
-
"recommendations": "### ๐ เคธเฅเคเคจเคพ:",
|
| 392 |
-
"acidic_soil": "๐ด **เค
เคฎเฅเคฒเฅเคฏ เคฎเคพเคคเฅ**: เคเฅเคจเคพ (CaCO3) เคฒเคพเคตเคพ",
|
| 393 |
-
"alkaline_soil": "๐ด **เคเฅเคทเคพเคฐเฅเคฏ เคฎเคพเคคเฅ**: เคเคเคงเค เคเคฟเคเคตเคพ เคธเฅเคเคฆเฅเคฐเคฟเคฏ เคชเคฆเคพเคฐเฅเคฅ เคฒเคพเคตเคพ",
|
| 394 |
-
"ideal_ph": "โ
**เคเคฆเคฐเฅเคถ pH**: 6.5-7.5 เคฆเคฐเคฎเฅเคฏเคพเคจ",
|
| 395 |
-
"low_nitrogen": "๐ก **เคเคฎเฅ เคจเคพเคฏเคเฅเคฐเฅเคเคจ**: NPK 20:20:0 เคฒเคพเคตเคพ",
|
| 396 |
-
"high_nitrogen": "๐ก **เคเคเฅเค เคจเคพเคฏเคเฅเคฐเฅเคเคจ**: เคจเคพเคฏเคเฅเคฐเฅเคเคจ เคเคฎเฅ เคเคฐเคพ",
|
| 397 |
-
"ideal_nitrogen": "โ
**เคเคฆเคฐเฅเคถ เคจเคพเคฏเคเฅเคฐเฅเคเคจ**: เคเคพเคเคเคฒเคพ เคธเฅเคคเคฐ",
|
| 398 |
-
"low_phosphorus": "๐ก **เคเคฎเฅ เคซเฅเคธเฅเคซเคฐเคธ**: DAP เคเคฟเคเคตเคพ SSP เคฒเคพเคตเคพ",
|
| 399 |
-
"ideal_phosphorus": "โ
**เคเคฆเคฐเฅเคถ เคซเฅเคธเฅเคซเคฐเคธ**: เคเคพเคเคเคฒเคพ เคธเฅเคคเคฐ",
|
| 400 |
-
"low_potassium": "๐ก **เคเคฎเฅ เคชเฅเคเฅ
เคถเคฟเคฏเคฎ**: KCl เคเคฟเคเคตเคพ MOP เคฒเคพเคตเคพ",
|
| 401 |
-
"ideal_potassium": "โ
**เคเคฆเคฐเฅเคถ เคชเฅเคเฅ
เคถเคฟเคฏเคฎ**: เคเคพเคเคเคฒเคพ เคธเฅเคคเคฐ",
|
| 402 |
-
"yield_prediction": "### ๐ เคชเคฟเค เคเคคเฅเคชเคพเคฆเคจ เค
เคเคฆเคพเค",
|
| 403 |
-
"temp_celsius": "เคคเคพเคชเคฎเคพเคจ (ยฐC)",
|
| 404 |
-
"humidity_percent": "เคเคฐเฅเคฆเฅเคฐเคคเคพ (%)",
|
| 405 |
-
"rainfall_mm": "เคชเคพเคเคธ (เคฎเคฟเคฎเฅ)",
|
| 406 |
-
"predict_yield": "๐ฎ เคเคคเฅเคชเคพเคฆเคจ เค
เคเคฆเคพเค เคฒเคพเคตเคพ",
|
| 407 |
-
"estimated_yield": "๐ เค
เคเคฆเคพเคเฅ เคเคคเฅเคชเคพเคฆเคจ:",
|
| 408 |
-
"quintal_hectare": "เคเฅเคตเคฟเคเคเคฒ/เคนเฅเคเฅเคเคฐ",
|
| 409 |
-
"high_yield": "โ
เคเคเฅเค เคเคคเฅเคชเคพเคฆเคจ เค
เคชเฅเคเฅเคทเคฟเคค เคเคนเฅ!",
|
| 410 |
-
"average_yield": "๐ เคธเคฐเคพเคธเคฐเฅ เคเคคเฅเคชเคพเคฆเคจ เค
เคชเฅเคเฅเคทเคฟเคค เคเคนเฅ",
|
| 411 |
-
"low_yield": "โ ๏ธ เคเคฎเฅ เคเคคเฅเคชเคพเคฆเคจ เคธเคเคญเคต เคเคนเฅเฅค เคฎเคพเคคเฅ เคเคฃเคฟ เคนเคตเคพเคฎเคพเคจ เคคเคชเคพเคธเคพ",
|
| 412 |
-
"profile_settings": "### ๐ค เคชเฅเคฐเฅเคซเคพเคเคฒ เคเคฃเคฟ เคธเฅเคเคฟเคเคเฅเคธ",
|
| 413 |
-
"choose_option": "เคชเคฐเฅเคฏเคพเคฏ เคจเคฟเคตเคกเคพ",
|
| 414 |
-
"login": "๐ เคฒเฅเคเคฟเคจ",
|
| 415 |
-
"register": "๐ เคจเฅเคเคฆเคฃเฅ",
|
| 416 |
-
"login_title": "เคฒเฅเคเคฟเคจ เคเคฐเคพ",
|
| 417 |
-
"username": "เคตเคพเคชเคฐเคเคฐเฅเคคเคพ เคจเคพเคต",
|
| 418 |
-
"password": "เคชเคพเคธเคตเคฐเฅเคก",
|
| 419 |
-
"login_btn": "เคฒเฅเคเคฟเคจ",
|
| 420 |
-
"login_success": "โ
เคฒเฅเคเคฟเคจ เคฏเคถเคธเฅเคตเฅ!",
|
| 421 |
-
"invalid_credentials": "โ เค
เคฏเฅเคเฅเคฏ เคเฅเคฐเฅเคกเฅเคเคถเคฟเคฏเคฒเฅเคธ",
|
| 422 |
-
"register_title": "เคจเคตเฅเคจ เคเคพเคคเฅ เคคเคฏเคพเคฐ เคเคฐเคพ",
|
| 423 |
-
"email": "เคเคฎเฅเคฒ",
|
| 424 |
-
"register_btn": "เคจเฅเคเคฆเคฃเฅ",
|
| 425 |
-
"registration_success": "โ
เคจเฅเคเคฆเคฃเฅ เคฏเคถเคธเฅเคตเฅ! เคเคคเคพ เคฒเฅเคเคฟเคจ เคเคฐเคพ",
|
| 426 |
-
"logged_in_as": "โ
เคฒเฅเคเคฟเคจ เคเฅเคฒเฅ เคเคนเฅ:",
|
| 427 |
-
"logout_btn": "เคฒเฅเคเคเคเค",
|
| 428 |
-
"footer": "๐พ เคถเฅเคคเคเคฐเฅ เคธเคนเคเคพเคฐ v4.0 - เคธเคฐเฅเคต เคถเฅเคคเคเคฐเฅเคฏเคพเคเคธเคพเค เฅ | ๐ เคธเฅเคชเฅ, เคธเคฐเคฒ เคเคฃเคฟ เคตเคฟเคจเคพเคฎเฅเคฒเฅเคฏ",
|
| 429 |
-
"kharif": "เคเคฐเฅเคซ",
|
| 430 |
-
"rabi": "เคฐเคฌเฅ",
|
| 431 |
-
"summer": "เคเคจเฅ๏ฟฝ๏ฟฝ๏ฟฝเคพเคณเคพ",
|
| 432 |
-
"wheat": "เคเคนเฅ",
|
| 433 |
-
"rice": "เคคเคพเคเคฆเฅเคณ",
|
| 434 |
-
"cotton": "เคเคชเคพเคธ",
|
| 435 |
-
"sugarcane": "เคเคธ",
|
| 436 |
-
"potato": "เคฌเคเคพเคเคพ",
|
| 437 |
-
"tomato": "เคเคฎเคพเคเคฐ",
|
| 438 |
-
"onion": "เคเคพเคเคฆเคพ",
|
| 439 |
-
"corn": "เคฎเคเฅเคเคพ",
|
| 440 |
-
}
|
| 441 |
-
}
|
| 442 |
-
|
| 443 |
-
def t(key):
|
| 444 |
-
"""Translate a key based on user's language preference"""
|
| 445 |
-
lang = st.session_state.get("language", "Hindi")
|
| 446 |
-
return TRANSLATIONS.get(lang, TRANSLATIONS["Hindi"]).get(key, key)
|
| 447 |
-
|
| 448 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 449 |
# STREAMLIT PAGE CONFIG
|
| 450 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 451 |
|
| 452 |
st.set_page_config(
|
| 453 |
-
page_title="๐พ Farmer Copilot
|
| 454 |
page_icon="๐",
|
| 455 |
layout="wide",
|
| 456 |
initial_sidebar_state="expanded"
|
| 457 |
)
|
| 458 |
|
| 459 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 460 |
-
# CUSTOM CSS
|
| 461 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 462 |
-
|
| 463 |
def inject_css():
|
| 464 |
st.markdown("""
|
| 465 |
<style>
|
|
@@ -480,27 +95,13 @@ def inject_css():
|
|
| 480 |
color: white;
|
| 481 |
font-weight: bold;
|
| 482 |
border: none;
|
| 483 |
-
border-radius:
|
| 484 |
-
padding:
|
| 485 |
-
font-size: 18px;
|
| 486 |
transition: all 0.3s ease;
|
| 487 |
-
cursor: pointer;
|
| 488 |
}
|
| 489 |
.stButton > button:hover {
|
| 490 |
box-shadow: 0 4px 12px rgba(45, 145, 94, 0.4);
|
| 491 |
-
transform:
|
| 492 |
-
}
|
| 493 |
-
.big-emoji {
|
| 494 |
-
font-size: 60px;
|
| 495 |
-
text-align: center;
|
| 496 |
-
margin: 20px 0;
|
| 497 |
-
}
|
| 498 |
-
.metric-card {
|
| 499 |
-
background: linear-gradient(135deg, #32B899 0%, #2180A0 100%);
|
| 500 |
-
color: white;
|
| 501 |
-
padding: 20px;
|
| 502 |
-
border-radius: 12px;
|
| 503 |
-
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
|
| 504 |
}
|
| 505 |
</style>
|
| 506 |
""", unsafe_allow_html=True)
|
|
@@ -508,47 +109,7 @@ def inject_css():
|
|
| 508 |
inject_css()
|
| 509 |
|
| 510 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 511 |
-
# FEATURE 1:
|
| 512 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 513 |
-
|
| 514 |
-
def voice_input(language="en-IN"):
|
| 515 |
-
"""Capture voice input from microphone"""
|
| 516 |
-
if not VOICE_AVAILABLE:
|
| 517 |
-
return None, "Voice feature not available"
|
| 518 |
-
|
| 519 |
-
try:
|
| 520 |
-
recognizer = sr.Recognizer()
|
| 521 |
-
with sr.Microphone() as source:
|
| 522 |
-
st.info(t("listening"))
|
| 523 |
-
recognizer.adjust_for_ambient_noise(source, duration=1)
|
| 524 |
-
audio = recognizer.listen(source, timeout=10)
|
| 525 |
-
|
| 526 |
-
text = recognizer.recognize_google(audio, language=language)
|
| 527 |
-
return text, None
|
| 528 |
-
except Exception as e:
|
| 529 |
-
return None, f"Error: {str(e)}"
|
| 530 |
-
|
| 531 |
-
def voice_output(text, language="en"):
|
| 532 |
-
"""Convert text to speech"""
|
| 533 |
-
if not VOICE_AVAILABLE:
|
| 534 |
-
return
|
| 535 |
-
|
| 536 |
-
try:
|
| 537 |
-
tts = gTTS(text=text, lang=language, slow=True)
|
| 538 |
-
audio_file = "response.mp3"
|
| 539 |
-
tts.save(audio_file)
|
| 540 |
-
|
| 541 |
-
with open(audio_file, "rb") as f:
|
| 542 |
-
audio_bytes = f.read()
|
| 543 |
-
st.audio(audio_bytes, format="audio/mp3")
|
| 544 |
-
|
| 545 |
-
if os.path.exists(audio_file):
|
| 546 |
-
os.remove(audio_file)
|
| 547 |
-
except Exception as e:
|
| 548 |
-
st.error(f"Voice error: {str(e)}")
|
| 549 |
-
|
| 550 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 551 |
-
# FEATURE 2: IMAGE RECOGNITION
|
| 552 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 553 |
|
| 554 |
@st.cache_resource
|
|
@@ -581,11 +142,11 @@ def analyze_plant_disease(image_file):
|
|
| 581 |
|
| 582 |
predictions = model.predict(image_array)
|
| 583 |
disease_map = {
|
| 584 |
-
0: "Early Blight -
|
| 585 |
-
1: "Late Blight -
|
| 586 |
-
2: "Powdery Mildew -
|
| 587 |
-
3: "Leaf Spot -
|
| 588 |
-
4: "Healthy Plant - No disease
|
| 589 |
}
|
| 590 |
|
| 591 |
predicted_disease_idx = np.argmax(predictions[0])
|
|
@@ -602,15 +163,63 @@ def analyze_plant_disease(image_file):
|
|
| 602 |
return None, f"Error: {str(e)}"
|
| 603 |
|
| 604 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 605 |
-
# FEATURE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 606 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 607 |
|
| 608 |
def init_farm_database():
|
| 609 |
"""Initialize SQLite database for farm data"""
|
| 610 |
conn = sqlite3.connect('farm_data.db')
|
| 611 |
c = conn.cursor()
|
|
|
|
| 612 |
c.execute('''CREATE TABLE IF NOT EXISTS yields
|
| 613 |
-
(id INTEGER PRIMARY KEY,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 614 |
conn.commit()
|
| 615 |
conn.close()
|
| 616 |
|
|
@@ -618,19 +227,235 @@ def save_farm_data(crop, area, yield_amount, location):
|
|
| 618 |
"""Save yield data to database"""
|
| 619 |
conn = sqlite3.connect('farm_data.db')
|
| 620 |
c = conn.cursor()
|
|
|
|
| 621 |
date = datetime.now().strftime("%Y-%m-%d")
|
| 622 |
c.execute('INSERT INTO yields VALUES (NULL, ?, ?, ?, ?, ?)',
|
| 623 |
(date, crop, area, yield_amount, location))
|
|
|
|
| 624 |
conn.commit()
|
| 625 |
conn.close()
|
| 626 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 627 |
def init_soil_database():
|
| 628 |
"""Initialize soil data database"""
|
| 629 |
conn = sqlite3.connect('soil_data.db')
|
| 630 |
c = conn.cursor()
|
|
|
|
| 631 |
c.execute('''CREATE TABLE IF NOT EXISTS soil_tests
|
| 632 |
-
(id INTEGER PRIMARY KEY,
|
| 633 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 634 |
conn.commit()
|
| 635 |
conn.close()
|
| 636 |
|
|
@@ -638,9 +463,13 @@ def save_soil_test(location, pH, nitrogen, phosphorus, potassium, organic_matter
|
|
| 638 |
"""Save soil test results"""
|
| 639 |
conn = sqlite3.connect('soil_data.db')
|
| 640 |
c = conn.cursor()
|
|
|
|
| 641 |
date = datetime.now().strftime("%Y-%m-%d")
|
| 642 |
-
|
|
|
|
|
|
|
| 643 |
(date, location, pH, nitrogen, phosphorus, potassium, organic_matter, moisture))
|
|
|
|
| 644 |
conn.commit()
|
| 645 |
conn.close()
|
| 646 |
|
|
@@ -649,33 +478,37 @@ def get_soil_recommendations(pH, nitrogen, phosphorus, potassium):
|
|
| 649 |
recommendations = []
|
| 650 |
|
| 651 |
if pH < 6.0:
|
| 652 |
-
recommendations.append(
|
| 653 |
elif pH > 8.0:
|
| 654 |
-
recommendations.append(
|
| 655 |
else:
|
| 656 |
-
recommendations.append(
|
| 657 |
|
| 658 |
if nitrogen < 200:
|
| 659 |
-
recommendations.append(
|
| 660 |
elif nitrogen > 500:
|
| 661 |
-
recommendations.append(
|
| 662 |
else:
|
| 663 |
-
recommendations.append(
|
| 664 |
|
| 665 |
if phosphorus < 10:
|
| 666 |
-
recommendations.append(
|
|
|
|
|
|
|
| 667 |
else:
|
| 668 |
-
recommendations.append(
|
| 669 |
|
| 670 |
if potassium < 100:
|
| 671 |
-
recommendations.append(
|
|
|
|
|
|
|
| 672 |
else:
|
| 673 |
-
recommendations.append(
|
| 674 |
|
| 675 |
return recommendations
|
| 676 |
|
| 677 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 678 |
-
# FEATURE
|
| 679 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 680 |
|
| 681 |
def train_yield_model():
|
|
@@ -684,7 +517,7 @@ def train_yield_model():
|
|
| 684 |
return None, None
|
| 685 |
|
| 686 |
X_train = np.array([
|
| 687 |
-
[25, 80, 250,
|
| 688 |
[28, 70, 200, 6.5, 3.0],
|
| 689 |
[22, 85, 300, 6.8, 2.8],
|
| 690 |
[26, 75, 250, 7.0, 3.2],
|
|
@@ -735,7 +568,108 @@ def predict_yield(temperature, humidity, rainfall, pH, organic_matter):
|
|
| 735 |
return max(0, yield_pred)
|
| 736 |
|
| 737 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 738 |
-
# FEATURE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 739 |
# โโโโโโโ๏ฟฝ๏ฟฝโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 740 |
|
| 741 |
def get_weather_data(location: str) -> Optional[Dict]:
|
|
@@ -783,127 +717,36 @@ def get_current_season() -> str:
|
|
| 783 |
"""Get current agricultural season"""
|
| 784 |
month = datetime.now().month
|
| 785 |
if month in [6, 7, 8, 9]:
|
| 786 |
-
return
|
| 787 |
elif month in [10, 11, 12, 1, 2]:
|
| 788 |
-
return
|
| 789 |
else:
|
| 790 |
-
return
|
| 791 |
-
|
| 792 |
-
def check_weather_alerts(weather_data):
|
| 793 |
-
"""Check weather for farming alerts"""
|
| 794 |
-
alerts = []
|
| 795 |
-
|
| 796 |
-
if weather_data:
|
| 797 |
-
temp = weather_data.get('temperature', 0)
|
| 798 |
-
humidity = weather_data.get('humidity', 0)
|
| 799 |
-
|
| 800 |
-
if temp < 0:
|
| 801 |
-
alerts.append({'message': t("frost_risk"), 'severity': 'HIGH'})
|
| 802 |
-
elif temp > 40:
|
| 803 |
-
alerts.append({'message': t("high_temp"), 'severity': 'HIGH'})
|
| 804 |
-
|
| 805 |
-
if humidity > 85:
|
| 806 |
-
alerts.append({'message': t("high_humidity"), 'severity': 'MEDIUM'})
|
| 807 |
-
|
| 808 |
-
return alerts
|
| 809 |
-
|
| 810 |
-
def display_alerts():
|
| 811 |
-
"""Display all alerts in sidebar"""
|
| 812 |
-
with st.sidebar:
|
| 813 |
-
st.markdown(f"### {t('alerts')}")
|
| 814 |
-
|
| 815 |
-
all_alerts = []
|
| 816 |
-
|
| 817 |
-
try:
|
| 818 |
-
weather = get_weather_data(st.session_state.location)
|
| 819 |
-
all_alerts.extend(check_weather_alerts(weather))
|
| 820 |
-
except:
|
| 821 |
-
pass
|
| 822 |
-
|
| 823 |
-
if all_alerts:
|
| 824 |
-
for alert in all_alerts:
|
| 825 |
-
if alert['severity'] == 'HIGH':
|
| 826 |
-
st.error(alert['message'])
|
| 827 |
-
elif alert['severity'] == 'MEDIUM':
|
| 828 |
-
st.warning(alert['message'])
|
| 829 |
-
else:
|
| 830 |
-
st.info(alert['message'])
|
| 831 |
-
else:
|
| 832 |
-
st.success(t("all_conditions_normal"))
|
| 833 |
-
|
| 834 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 835 |
-
# FEATURE 6: MARKET PRICES
|
| 836 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 837 |
|
| 838 |
-
|
| 839 |
-
|
| 840 |
-
|
| 841 |
-
|
| 842 |
-
|
| 843 |
-
t("rice"): 2650,
|
| 844 |
-
t("cotton"): 5800,
|
| 845 |
-
t("sugarcane"): 295,
|
| 846 |
-
t("potato"): 1650,
|
| 847 |
-
t("tomato"): 1350,
|
| 848 |
-
t("onion"): 1950,
|
| 849 |
-
t("corn"): 2000
|
| 850 |
}
|
| 851 |
-
|
| 852 |
-
|
| 853 |
-
|
| 854 |
-
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 855 |
-
|
| 856 |
-
def init_user_database():
|
| 857 |
-
"""Initialize user database"""
|
| 858 |
-
conn = sqlite3.connect('users.db')
|
| 859 |
-
c = conn.cursor()
|
| 860 |
-
c.execute('''CREATE TABLE IF NOT EXISTS users
|
| 861 |
-
(id INTEGER PRIMARY KEY, username TEXT UNIQUE, password TEXT, email TEXT, location TEXT, created_date TEXT)''')
|
| 862 |
-
conn.commit()
|
| 863 |
-
conn.close()
|
| 864 |
-
|
| 865 |
-
def hash_password(password):
|
| 866 |
-
"""Hash password"""
|
| 867 |
-
return hashlib.sha256(password.encode()).hexdigest()
|
| 868 |
-
|
| 869 |
-
def register_user(username, password, email, location):
|
| 870 |
-
"""Register new user"""
|
| 871 |
-
try:
|
| 872 |
-
conn = sqlite3.connect('users.db')
|
| 873 |
-
c = conn.cursor()
|
| 874 |
-
hashed_pwd = hash_password(password)
|
| 875 |
-
date = datetime.now().strftime("%Y-%m-%d")
|
| 876 |
-
c.execute('INSERT INTO users VALUES (NULL, ?, ?, ?, ?, ?)',
|
| 877 |
-
(username, hashed_pwd, email, location, date))
|
| 878 |
-
conn.commit()
|
| 879 |
-
conn.close()
|
| 880 |
-
return True, "User registered successfully!"
|
| 881 |
-
except sqlite3.IntegrityError:
|
| 882 |
-
return False, "Username already exists"
|
| 883 |
-
except Exception as e:
|
| 884 |
-
return False, str(e)
|
| 885 |
-
|
| 886 |
-
def login_user(username, password):
|
| 887 |
-
"""Login user"""
|
| 888 |
-
try:
|
| 889 |
-
conn = sqlite3.connect('users.db')
|
| 890 |
-
c = conn.cursor()
|
| 891 |
-
hashed_pwd = hash_password(password)
|
| 892 |
-
c.execute('SELECT * FROM users WHERE username=? AND password=?', (username, hashed_pwd))
|
| 893 |
-
user = c.fetchone()
|
| 894 |
-
conn.close()
|
| 895 |
-
return (True, user) if user else (False, "Invalid credentials")
|
| 896 |
-
except Exception as e:
|
| 897 |
-
return False, str(e)
|
| 898 |
|
| 899 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 900 |
# SESSION STATE INITIALIZATION
|
| 901 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 902 |
|
|
|
|
|
|
|
| 903 |
if "location" not in st.session_state:
|
| 904 |
-
st.session_state.location = "
|
| 905 |
if "language" not in st.session_state:
|
| 906 |
-
st.session_state.language = "
|
|
|
|
|
|
|
|
|
|
|
|
|
| 907 |
if "user_authenticated" not in st.session_state:
|
| 908 |
st.session_state.user_authenticated = False
|
| 909 |
st.session_state.username = None
|
|
@@ -914,28 +757,38 @@ if 'db_initialized' not in st.session_state:
|
|
| 914 |
st.session_state.db_initialized = True
|
| 915 |
|
| 916 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 917 |
-
# SIDEBAR
|
| 918 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 919 |
|
| 920 |
with st.sidebar:
|
| 921 |
-
st.markdown(
|
| 922 |
|
| 923 |
location = st.selectbox(
|
| 924 |
-
|
| 925 |
-
["
|
| 926 |
-
key="
|
| 927 |
)
|
| 928 |
st.session_state.location = location
|
| 929 |
|
| 930 |
language = st.selectbox(
|
| 931 |
-
|
| 932 |
-
["
|
| 933 |
-
|
| 934 |
-
key="sidebar_language_key"
|
| 935 |
)
|
|
|
|
| 936 |
|
| 937 |
-
|
| 938 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 939 |
st.rerun()
|
| 940 |
|
| 941 |
st.divider()
|
|
@@ -945,280 +798,253 @@ with st.sidebar:
|
|
| 945 |
# MAIN CONTENT
|
| 946 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 947 |
|
| 948 |
-
st.markdown(
|
| 949 |
-
st.markdown(
|
| 950 |
st.divider()
|
| 951 |
|
| 952 |
# DEFINE TABS WITH UNIQUE KEYS
|
| 953 |
tab1, tab2, tab3, tab4, tab5, tab6, tab7, tab8, tab9, tab10, tab11, tab12 = st.tabs([
|
| 954 |
-
|
| 955 |
-
|
| 956 |
-
|
| 957 |
])
|
| 958 |
|
| 959 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 960 |
-
# TAB 1:
|
| 961 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 962 |
|
| 963 |
with tab1:
|
| 964 |
-
st.markdown(
|
| 965 |
-
st.markdown(t("what_you_want"))
|
| 966 |
-
|
| 967 |
-
col1, col2, col3 = st.columns(3)
|
| 968 |
|
| 969 |
-
|
| 970 |
-
st.
|
| 971 |
-
if st.button(t("rainfall_info"), key="voice_rainfall_btn", use_container_width=True):
|
| 972 |
-
with st.spinner("..."):
|
| 973 |
-
weather = get_weather_data(st.session_state.location)
|
| 974 |
-
if weather:
|
| 975 |
-
msg = f"Temperature {weather['temperature']:.0f}ยฐC, Humidity {weather['humidity']}%"
|
| 976 |
-
st.success(msg)
|
| 977 |
-
if VOICE_AVAILABLE:
|
| 978 |
-
lang_code = "hi" if st.session_state.language == "Hindi" else "mr" if st.session_state.language == "Marathi" else "en"
|
| 979 |
-
voice_output(msg, language=lang_code)
|
| 980 |
-
else:
|
| 981 |
-
st.info(t("weather_unavailable"))
|
| 982 |
-
|
| 983 |
-
with col2:
|
| 984 |
-
st.markdown("<div class='big-emoji'>๐</div>", unsafe_allow_html=True)
|
| 985 |
-
if st.button(t("pest_problem"), key="voice_pest_btn", use_container_width=True):
|
| 986 |
-
st.info(t("upload_photo_disease"))
|
| 987 |
-
if VOICE_AVAILABLE:
|
| 988 |
-
lang_code = "hi" if st.session_state.language == "Hindi" else "mr" if st.session_state.language == "Marathi" else "en"
|
| 989 |
-
voice_output(t("go_disease_tab"), language=lang_code)
|
| 990 |
-
|
| 991 |
-
with col3:
|
| 992 |
-
st.markdown("<div class='big-emoji'>๐ฑ</div>", unsafe_allow_html=True)
|
| 993 |
-
if st.button(t("market_prices"), key="voice_market_btn", use_container_width=True):
|
| 994 |
-
prices = get_live_market_prices()
|
| 995 |
-
price_list = ", ".join([f"{crop}: โน{price}" for crop, price in list(prices.items())[:3]])
|
| 996 |
-
st.success(price_list)
|
| 997 |
-
if VOICE_AVAILABLE:
|
| 998 |
-
lang_code = "hi" if st.session_state.language == "Hindi" else "mr" if st.session_state.language == "Marathi" else "en"
|
| 999 |
-
voice_output(price_list, language=lang_code)
|
| 1000 |
-
|
| 1001 |
-
st.divider()
|
| 1002 |
|
| 1003 |
-
|
| 1004 |
|
| 1005 |
-
|
| 1006 |
-
|
| 1007 |
-
|
| 1008 |
-
|
| 1009 |
-
|
| 1010 |
-
|
| 1011 |
-
|
| 1012 |
-
|
| 1013 |
-
|
| 1014 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1015 |
|
| 1016 |
-
|
| 1017 |
-
st.
|
| 1018 |
-
|
| 1019 |
-
|
| 1020 |
-
|
| 1021 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1022 |
|
| 1023 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1024 |
# TAB 2: WEATHER
|
| 1025 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1026 |
|
| 1027 |
with tab2:
|
| 1028 |
-
st.markdown(
|
| 1029 |
|
| 1030 |
-
if st.button(
|
| 1031 |
-
with st.spinner(
|
| 1032 |
weather = get_weather_data(st.session_state.location)
|
| 1033 |
if weather:
|
| 1034 |
-
col1, col2, col3
|
| 1035 |
-
col1.metric(
|
| 1036 |
-
col2.metric(
|
| 1037 |
-
col3.metric(
|
| 1038 |
-
|
| 1039 |
-
|
| 1040 |
-
|
|
|
|
|
|
|
| 1041 |
|
| 1042 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1043 |
# TAB 3: MARKET PRICES
|
| 1044 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1045 |
|
| 1046 |
with tab3:
|
| 1047 |
-
st.markdown(
|
| 1048 |
|
| 1049 |
-
if st.button(
|
| 1050 |
live_prices = get_live_market_prices()
|
| 1051 |
if live_prices:
|
| 1052 |
-
|
| 1053 |
crops_list = list(live_prices.keys())
|
| 1054 |
|
| 1055 |
-
|
| 1056 |
-
|
| 1057 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1058 |
|
| 1059 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1060 |
-
# TAB 4-7: PLACEHOLDER TABS
|
| 1061 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1062 |
|
| 1063 |
with tab4:
|
| 1064 |
-
st.markdown(
|
| 1065 |
-
st.info(
|
| 1066 |
-
st.write(
|
| 1067 |
|
| 1068 |
with tab5:
|
| 1069 |
-
st.markdown(
|
| 1070 |
-
st.info(
|
| 1071 |
|
| 1072 |
with tab6:
|
| 1073 |
-
st.markdown(
|
| 1074 |
-
st.info(
|
| 1075 |
|
| 1076 |
with tab7:
|
| 1077 |
-
st.markdown(
|
| 1078 |
-
st.info(
|
| 1079 |
|
| 1080 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1081 |
-
# TAB 8: IMAGE RECOGNITION
|
| 1082 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1083 |
|
| 1084 |
with tab8:
|
| 1085 |
-
st.markdown(
|
| 1086 |
-
|
| 1087 |
-
uploaded_file = st.file_uploader(t("upload_leaf"), type=['jpg', 'jpeg', 'png'], key="image_uploader_key")
|
| 1088 |
|
| 1089 |
-
if uploaded_file:
|
| 1090 |
-
|
| 1091 |
-
|
| 1092 |
-
|
| 1093 |
-
|
| 1094 |
-
|
| 1095 |
-
|
| 1096 |
-
|
| 1097 |
-
|
| 1098 |
-
|
| 1099 |
-
|
| 1100 |
-
|
| 1101 |
-
st.error(error)
|
| 1102 |
-
else:
|
| 1103 |
-
st.success(t("analysis_complete"))
|
| 1104 |
-
st.metric(t("disease"), result['disease'].split('-')[0])
|
| 1105 |
-
st.metric(t("confidence"), f"{result['confidence']:.1f}%")
|
| 1106 |
-
st.metric(t("severity"), result['severity'])
|
| 1107 |
-
else:
|
| 1108 |
-
st.warning(t("image_recognition_unavailable"))
|
| 1109 |
|
| 1110 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1111 |
-
# TAB 9:
|
| 1112 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1113 |
|
| 1114 |
with tab9:
|
| 1115 |
-
st.markdown(
|
| 1116 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1117 |
|
| 1118 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1119 |
-
# TAB 10: SOIL HEALTH
|
| 1120 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1121 |
|
| 1122 |
with tab10:
|
| 1123 |
-
st.markdown(
|
| 1124 |
|
| 1125 |
col1, col2, col3 = st.columns(3)
|
| 1126 |
with col1:
|
| 1127 |
-
pH = st.slider(
|
| 1128 |
-
nitrogen = st.slider(
|
| 1129 |
with col2:
|
| 1130 |
-
phosphorus = st.slider(
|
| 1131 |
-
potassium = st.slider(
|
| 1132 |
with col3:
|
| 1133 |
-
organic_matter = st.slider(
|
| 1134 |
-
moisture = st.slider(
|
| 1135 |
|
| 1136 |
-
if st.button(
|
| 1137 |
save_soil_test(st.session_state.location, pH, nitrogen, phosphorus, potassium, organic_matter, moisture)
|
| 1138 |
-
st.success(
|
| 1139 |
|
| 1140 |
recommendations = get_soil_recommendations(pH, nitrogen, phosphorus, potassium)
|
| 1141 |
-
st.markdown(t("recommendations"))
|
| 1142 |
for rec in recommendations:
|
| 1143 |
st.markdown(rec)
|
| 1144 |
|
| 1145 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1146 |
-
# TAB 11: YIELD PREDICTION
|
| 1147 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1148 |
|
| 1149 |
with tab11:
|
| 1150 |
-
st.markdown(
|
| 1151 |
|
| 1152 |
col1, col2, col3 = st.columns(3)
|
| 1153 |
with col1:
|
| 1154 |
-
temp = st.slider(
|
| 1155 |
-
humidity = st.slider(
|
| 1156 |
with col2:
|
| 1157 |
-
rainfall = st.slider(
|
| 1158 |
-
pH = st.slider(
|
| 1159 |
with col3:
|
| 1160 |
-
org_matter = st.slider(
|
| 1161 |
|
| 1162 |
-
if st.button(
|
| 1163 |
yield_pred = predict_yield(temp, humidity, rainfall, pH, org_matter)
|
| 1164 |
-
st.
|
| 1165 |
-
|
| 1166 |
-
if yield_pred > 25:
|
| 1167 |
-
st.info(t("high_yield"))
|
| 1168 |
-
elif yield_pred > 20:
|
| 1169 |
-
st.info(t("average_yield"))
|
| 1170 |
-
else:
|
| 1171 |
-
st.warning(t("low_yield"))
|
| 1172 |
|
| 1173 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1174 |
-
# TAB 12: USER PROFILE
|
| 1175 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1176 |
|
| 1177 |
with tab12:
|
| 1178 |
-
st.markdown(
|
| 1179 |
|
| 1180 |
if not st.session_state.user_authenticated:
|
| 1181 |
-
auth_choice = st.radio(
|
| 1182 |
|
| 1183 |
-
if auth_choice ==
|
| 1184 |
-
st.
|
| 1185 |
-
|
| 1186 |
-
username = st.text_input(t("username"), key="login_username_tab12")
|
| 1187 |
-
password = st.text_input(t("password"), type="password", key="login_password_tab12")
|
| 1188 |
|
| 1189 |
-
if st.button(
|
| 1190 |
success, result = login_user(username, password)
|
| 1191 |
-
|
| 1192 |
if success:
|
| 1193 |
st.session_state.user_authenticated = True
|
| 1194 |
st.session_state.username = username
|
| 1195 |
-
st.success(
|
| 1196 |
st.rerun()
|
| 1197 |
else:
|
| 1198 |
-
st.error(
|
| 1199 |
-
|
| 1200 |
else:
|
| 1201 |
-
st.
|
| 1202 |
-
|
| 1203 |
-
|
| 1204 |
-
new_email = st.text_input(t("email"), key="register_email_tab12")
|
| 1205 |
-
new_password = st.text_input(t("password"), type="password", key="register_password_tab12")
|
| 1206 |
|
| 1207 |
-
if st.button(
|
| 1208 |
success, msg = register_user(new_username, new_password, new_email, st.session_state.location)
|
| 1209 |
-
|
| 1210 |
-
if success:
|
| 1211 |
-
st.success(t("registration_success"))
|
| 1212 |
-
else:
|
| 1213 |
-
st.error(f"โ {msg}")
|
| 1214 |
-
|
| 1215 |
else:
|
| 1216 |
-
st.success(f"
|
| 1217 |
-
|
| 1218 |
-
if st.button(t("logout_btn"), key="logout_btn_tab12", use_container_width=True):
|
| 1219 |
st.session_state.user_authenticated = False
|
| 1220 |
-
st.session_state.username = None
|
| 1221 |
st.rerun()
|
| 1222 |
|
| 1223 |
st.divider()
|
| 1224 |
-
st.markdown(
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
from datetime import datetime, timedelta
|
| 5 |
import logging
|
|
|
|
| 6 |
import requests
|
| 7 |
+
from typing import Optional, Dict, List, Any
|
| 8 |
import json
|
| 9 |
from io import BytesIO
|
| 10 |
from PIL import Image
|
|
|
|
| 13 |
import sqlite3
|
| 14 |
import hashlib
|
| 15 |
|
| 16 |
+
# OpenAI Integration
|
| 17 |
+
try:
|
| 18 |
+
from openai import OpenAI
|
| 19 |
+
OPENAI_AVAILABLE = True
|
| 20 |
+
except ImportError:
|
| 21 |
+
OPENAI_AVAILABLE = False
|
| 22 |
|
| 23 |
# Image Recognition
|
| 24 |
try:
|
|
|
|
| 64 |
logging.basicConfig(level=logging.INFO)
|
| 65 |
logger = logging.getLogger(__name__)
|
| 66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 68 |
# STREAMLIT PAGE CONFIG
|
| 69 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 70 |
|
| 71 |
st.set_page_config(
|
| 72 |
+
page_title="๐พ Farmer Copilot v3.0 - Complete",
|
| 73 |
page_icon="๐",
|
| 74 |
layout="wide",
|
| 75 |
initial_sidebar_state="expanded"
|
| 76 |
)
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
def inject_css():
|
| 79 |
st.markdown("""
|
| 80 |
<style>
|
|
|
|
| 95 |
color: white;
|
| 96 |
font-weight: bold;
|
| 97 |
border: none;
|
| 98 |
+
border-radius: 8px;
|
| 99 |
+
padding: 10px 24px;
|
|
|
|
| 100 |
transition: all 0.3s ease;
|
|
|
|
| 101 |
}
|
| 102 |
.stButton > button:hover {
|
| 103 |
box-shadow: 0 4px 12px rgba(45, 145, 94, 0.4);
|
| 104 |
+
transform: translateY(-2px);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
}
|
| 106 |
</style>
|
| 107 |
""", unsafe_allow_html=True)
|
|
|
|
| 109 |
inject_css()
|
| 110 |
|
| 111 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 112 |
+
# FEATURE 1: IMAGE RECOGNITION
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 114 |
|
| 115 |
@st.cache_resource
|
|
|
|
| 142 |
|
| 143 |
predictions = model.predict(image_array)
|
| 144 |
disease_map = {
|
| 145 |
+
0: "Early Blight - Use fungicide",
|
| 146 |
+
1: "Late Blight - Spray mancozeb",
|
| 147 |
+
2: "Powdery Mildew - Apply sulfur",
|
| 148 |
+
3: "Leaf Spot - Spray neem oil",
|
| 149 |
+
4: "Healthy Plant - No disease"
|
| 150 |
}
|
| 151 |
|
| 152 |
predicted_disease_idx = np.argmax(predictions[0])
|
|
|
|
| 163 |
return None, f"Error: {str(e)}"
|
| 164 |
|
| 165 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 166 |
+
# FEATURE 2: VOICE I/O
|
| 167 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 168 |
+
|
| 169 |
+
def voice_input():
|
| 170 |
+
"""Capture voice input from microphone"""
|
| 171 |
+
if not VOICE_AVAILABLE:
|
| 172 |
+
return None, "Voice feature not available"
|
| 173 |
+
|
| 174 |
+
try:
|
| 175 |
+
recognizer = sr.Recognizer()
|
| 176 |
+
with sr.Microphone() as source:
|
| 177 |
+
st.info("๐๏ธ Listening...")
|
| 178 |
+
recognizer.adjust_for_ambient_noise(source, duration=1)
|
| 179 |
+
audio = recognizer.listen(source, timeout=10)
|
| 180 |
+
|
| 181 |
+
text = recognizer.recognize_google(audio, language='en-IN')
|
| 182 |
+
return text, None
|
| 183 |
+
|
| 184 |
+
except Exception as e:
|
| 185 |
+
return None, f"Error: {str(e)}"
|
| 186 |
+
|
| 187 |
+
def voice_output(text, language="en"):
|
| 188 |
+
"""Convert text to speech"""
|
| 189 |
+
if not VOICE_AVAILABLE:
|
| 190 |
+
return
|
| 191 |
+
|
| 192 |
+
try:
|
| 193 |
+
tts = gTTS(text=text, lang=language, slow=False)
|
| 194 |
+
audio_file = "response.mp3"
|
| 195 |
+
tts.save(audio_file)
|
| 196 |
+
|
| 197 |
+
with open(audio_file, "rb") as f:
|
| 198 |
+
audio_bytes = f.read()
|
| 199 |
+
st.audio(audio_bytes, format="audio/mp3")
|
| 200 |
+
|
| 201 |
+
if os.path.exists(audio_file):
|
| 202 |
+
os.remove(audio_file)
|
| 203 |
+
except Exception as e:
|
| 204 |
+
st.error(f"Voice error: {str(e)}")
|
| 205 |
+
|
| 206 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 207 |
+
# FEATURE 3: HISTORICAL DATA TRACKING
|
| 208 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 209 |
|
| 210 |
def init_farm_database():
|
| 211 |
"""Initialize SQLite database for farm data"""
|
| 212 |
conn = sqlite3.connect('farm_data.db')
|
| 213 |
c = conn.cursor()
|
| 214 |
+
|
| 215 |
c.execute('''CREATE TABLE IF NOT EXISTS yields
|
| 216 |
+
(id INTEGER PRIMARY KEY,
|
| 217 |
+
date TEXT,
|
| 218 |
+
crop TEXT,
|
| 219 |
+
area REAL,
|
| 220 |
+
yield REAL,
|
| 221 |
+
location TEXT)''')
|
| 222 |
+
|
| 223 |
conn.commit()
|
| 224 |
conn.close()
|
| 225 |
|
|
|
|
| 227 |
"""Save yield data to database"""
|
| 228 |
conn = sqlite3.connect('farm_data.db')
|
| 229 |
c = conn.cursor()
|
| 230 |
+
|
| 231 |
date = datetime.now().strftime("%Y-%m-%d")
|
| 232 |
c.execute('INSERT INTO yields VALUES (NULL, ?, ?, ?, ?, ?)',
|
| 233 |
(date, crop, area, yield_amount, location))
|
| 234 |
+
|
| 235 |
conn.commit()
|
| 236 |
conn.close()
|
| 237 |
|
| 238 |
+
def get_historical_yields(crop=None, days=90):
|
| 239 |
+
"""Get historical yield data"""
|
| 240 |
+
conn = sqlite3.connect('farm_data.db')
|
| 241 |
+
|
| 242 |
+
if crop:
|
| 243 |
+
df = pd.read_sql_query(
|
| 244 |
+
f"SELECT * FROM yields WHERE crop='{crop}' ORDER BY date DESC LIMIT 10",
|
| 245 |
+
conn
|
| 246 |
+
)
|
| 247 |
+
else:
|
| 248 |
+
df = pd.read_sql_query(
|
| 249 |
+
f"SELECT * FROM yields ORDER BY date DESC LIMIT 10",
|
| 250 |
+
conn
|
| 251 |
+
)
|
| 252 |
+
|
| 253 |
+
conn.close()
|
| 254 |
+
return df
|
| 255 |
+
|
| 256 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 257 |
+
# FEATURE 4: DATA EXPORT
|
| 258 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 259 |
+
|
| 260 |
+
def export_to_csv(data_dict, filename="farm_report"):
|
| 261 |
+
"""Export data to CSV"""
|
| 262 |
+
df = pd.DataFrame(data_dict)
|
| 263 |
+
csv_buffer = BytesIO()
|
| 264 |
+
df.to_csv(csv_buffer, index=False)
|
| 265 |
+
csv_buffer.seek(0)
|
| 266 |
+
return csv_buffer, f"{filename}.csv"
|
| 267 |
+
|
| 268 |
+
def export_to_excel(data_dict, filename="farm_report"):
|
| 269 |
+
"""Export data to Excel"""
|
| 270 |
+
df = pd.DataFrame(data_dict)
|
| 271 |
+
excel_buffer = BytesIO()
|
| 272 |
+
|
| 273 |
+
try:
|
| 274 |
+
with pd.ExcelWriter(excel_buffer, engine='openpyxl') as writer:
|
| 275 |
+
df.to_excel(writer, sheet_name='Farm Data', index=False)
|
| 276 |
+
except:
|
| 277 |
+
df.to_excel(excel_buffer, sheet_name='Farm Data', index=False)
|
| 278 |
+
|
| 279 |
+
excel_buffer.seek(0)
|
| 280 |
+
return excel_buffer, f"{filename}.xlsx"
|
| 281 |
+
|
| 282 |
+
def export_to_pdf(report_text, filename="farm_report"):
|
| 283 |
+
"""Export report to PDF"""
|
| 284 |
+
if not EXPORT_AVAILABLE:
|
| 285 |
+
return None, None
|
| 286 |
+
|
| 287 |
+
pdf_buffer = BytesIO()
|
| 288 |
+
c = canvas.Canvas(pdf_buffer, pagesize=letter)
|
| 289 |
+
|
| 290 |
+
width, height = letter
|
| 291 |
+
y_position = height - 50
|
| 292 |
+
|
| 293 |
+
c.setFont("Helvetica-Bold", 16)
|
| 294 |
+
c.drawString(50, y_position, "Farmer Copilot Report")
|
| 295 |
+
y_position -= 30
|
| 296 |
+
|
| 297 |
+
c.setFont("Helvetica", 10)
|
| 298 |
+
for line in report_text.split('\n'):
|
| 299 |
+
if y_position < 50:
|
| 300 |
+
c.showPage()
|
| 301 |
+
y_position = height - 50
|
| 302 |
+
c.drawString(50, y_position, line[:80])
|
| 303 |
+
y_position -= 15
|
| 304 |
+
|
| 305 |
+
c.save()
|
| 306 |
+
pdf_buffer.seek(0)
|
| 307 |
+
return pdf_buffer, f"{filename}.pdf"
|
| 308 |
+
|
| 309 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 310 |
+
# FEATURE 5: SMART NOTIFICATIONS
|
| 311 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 312 |
+
|
| 313 |
+
def check_weather_alerts(weather_data):
|
| 314 |
+
"""Check weather for farming alerts"""
|
| 315 |
+
alerts = []
|
| 316 |
+
|
| 317 |
+
if weather_data:
|
| 318 |
+
temp = weather_data.get('temperature', 0)
|
| 319 |
+
humidity = weather_data.get('humidity', 0)
|
| 320 |
+
|
| 321 |
+
if temp < 0:
|
| 322 |
+
alerts.append({'message': 'โ๏ธ Frost Risk! Protect delicate crops', 'severity': 'HIGH'})
|
| 323 |
+
elif temp > 40:
|
| 324 |
+
alerts.append({'message': '๐ฅ High Temperature! Increase irrigation', 'severity': 'HIGH'})
|
| 325 |
+
|
| 326 |
+
if humidity > 85:
|
| 327 |
+
alerts.append({'message': '๐ฆ High Humidity! Watch for fungal diseases', 'severity': 'MEDIUM'})
|
| 328 |
+
|
| 329 |
+
return alerts
|
| 330 |
+
|
| 331 |
+
def display_alerts():
|
| 332 |
+
"""Display all alerts in sidebar"""
|
| 333 |
+
with st.sidebar:
|
| 334 |
+
st.markdown("### ๐ Smart Alerts")
|
| 335 |
+
|
| 336 |
+
all_alerts = []
|
| 337 |
+
|
| 338 |
+
try:
|
| 339 |
+
weather = get_weather_data(st.session_state.location)
|
| 340 |
+
all_alerts.extend(check_weather_alerts(weather))
|
| 341 |
+
except:
|
| 342 |
+
pass
|
| 343 |
+
|
| 344 |
+
if all_alerts:
|
| 345 |
+
for alert in all_alerts:
|
| 346 |
+
if alert['severity'] == 'HIGH':
|
| 347 |
+
st.error(alert['message'])
|
| 348 |
+
elif alert['severity'] == 'MEDIUM':
|
| 349 |
+
st.warning(alert['message'])
|
| 350 |
+
else:
|
| 351 |
+
st.info(alert['message'])
|
| 352 |
+
else:
|
| 353 |
+
st.success("โ
All conditions normal!")
|
| 354 |
+
|
| 355 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 356 |
+
# FEATURE 6: REAL-TIME MARKET PRICES
|
| 357 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 358 |
+
|
| 359 |
+
@st.cache_data(ttl=3600)
|
| 360 |
+
def get_live_market_prices():
|
| 361 |
+
"""Get live market prices"""
|
| 362 |
+
return {
|
| 363 |
+
"Wheat": 2250, "Rice": 2650, "Cotton": 5800, "Sugarcane": 295,
|
| 364 |
+
"Potato": 1650, "Tomato": 1350, "Onion": 1950, "Corn": 2000
|
| 365 |
+
}
|
| 366 |
+
|
| 367 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 368 |
+
# FEATURE 7: USER AUTHENTICATION
|
| 369 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 370 |
+
|
| 371 |
+
def init_user_database():
|
| 372 |
+
"""Initialize user database"""
|
| 373 |
+
conn = sqlite3.connect('users.db')
|
| 374 |
+
c = conn.cursor()
|
| 375 |
+
|
| 376 |
+
c.execute('''CREATE TABLE IF NOT EXISTS users
|
| 377 |
+
(id INTEGER PRIMARY KEY,
|
| 378 |
+
username TEXT UNIQUE,
|
| 379 |
+
password TEXT,
|
| 380 |
+
email TEXT,
|
| 381 |
+
location TEXT,
|
| 382 |
+
created_date TEXT)''')
|
| 383 |
+
|
| 384 |
+
conn.commit()
|
| 385 |
+
conn.close()
|
| 386 |
+
|
| 387 |
+
def hash_password(password):
|
| 388 |
+
"""Hash password"""
|
| 389 |
+
return hashlib.sha256(password.encode()).hexdigest()
|
| 390 |
+
|
| 391 |
+
def register_user(username, password, email, location):
|
| 392 |
+
"""Register new user"""
|
| 393 |
+
try:
|
| 394 |
+
conn = sqlite3.connect('users.db')
|
| 395 |
+
c = conn.cursor()
|
| 396 |
+
|
| 397 |
+
hashed_pwd = hash_password(password)
|
| 398 |
+
date = datetime.now().strftime("%Y-%m-%d")
|
| 399 |
+
|
| 400 |
+
c.execute('INSERT INTO users VALUES (NULL, ?, ?, ?, ?, ?)',
|
| 401 |
+
(username, hashed_pwd, email, location, date))
|
| 402 |
+
|
| 403 |
+
conn.commit()
|
| 404 |
+
conn.close()
|
| 405 |
+
return True, "User registered successfully!"
|
| 406 |
+
except sqlite3.IntegrityError:
|
| 407 |
+
return False, "Username already exists"
|
| 408 |
+
except Exception as e:
|
| 409 |
+
return False, str(e)
|
| 410 |
+
|
| 411 |
+
def login_user(username, password):
|
| 412 |
+
"""Login user"""
|
| 413 |
+
try:
|
| 414 |
+
conn = sqlite3.connect('users.db')
|
| 415 |
+
c = conn.cursor()
|
| 416 |
+
|
| 417 |
+
hashed_pwd = hash_password(password)
|
| 418 |
+
c.execute('SELECT * FROM users WHERE username=? AND password=?',
|
| 419 |
+
(username, hashed_pwd))
|
| 420 |
+
|
| 421 |
+
user = c.fetchone()
|
| 422 |
+
conn.close()
|
| 423 |
+
|
| 424 |
+
return (True, user) if user else (False, "Invalid credentials")
|
| 425 |
+
except Exception as e:
|
| 426 |
+
return False, str(e)
|
| 427 |
+
|
| 428 |
+
def get_user_profile(username):
|
| 429 |
+
"""Get user profile"""
|
| 430 |
+
conn = sqlite3.connect('users.db')
|
| 431 |
+
c = conn.cursor()
|
| 432 |
+
|
| 433 |
+
c.execute('SELECT * FROM users WHERE username=?', (username,))
|
| 434 |
+
user = c.fetchone()
|
| 435 |
+
conn.close()
|
| 436 |
+
|
| 437 |
+
return user
|
| 438 |
+
|
| 439 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 440 |
+
# FEATURE 8: SOIL HEALTH MONITORING
|
| 441 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 442 |
+
|
| 443 |
def init_soil_database():
|
| 444 |
"""Initialize soil data database"""
|
| 445 |
conn = sqlite3.connect('soil_data.db')
|
| 446 |
c = conn.cursor()
|
| 447 |
+
|
| 448 |
c.execute('''CREATE TABLE IF NOT EXISTS soil_tests
|
| 449 |
+
(id INTEGER PRIMARY KEY,
|
| 450 |
+
date TEXT,
|
| 451 |
+
location TEXT,
|
| 452 |
+
pH REAL,
|
| 453 |
+
nitrogen INTEGER,
|
| 454 |
+
phosphorus INTEGER,
|
| 455 |
+
potassium INTEGER,
|
| 456 |
+
organic_matter REAL,
|
| 457 |
+
moisture REAL)''')
|
| 458 |
+
|
| 459 |
conn.commit()
|
| 460 |
conn.close()
|
| 461 |
|
|
|
|
| 463 |
"""Save soil test results"""
|
| 464 |
conn = sqlite3.connect('soil_data.db')
|
| 465 |
c = conn.cursor()
|
| 466 |
+
|
| 467 |
date = datetime.now().strftime("%Y-%m-%d")
|
| 468 |
+
|
| 469 |
+
c.execute('''INSERT INTO soil_tests
|
| 470 |
+
VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?)''',
|
| 471 |
(date, location, pH, nitrogen, phosphorus, potassium, organic_matter, moisture))
|
| 472 |
+
|
| 473 |
conn.commit()
|
| 474 |
conn.close()
|
| 475 |
|
|
|
|
| 478 |
recommendations = []
|
| 479 |
|
| 480 |
if pH < 6.0:
|
| 481 |
+
recommendations.append("๐ด **Acidic Soil**: Apply lime (CaCO3)")
|
| 482 |
elif pH > 8.0:
|
| 483 |
+
recommendations.append("๐ด **Alkaline Soil**: Apply sulfur or organic matter")
|
| 484 |
else:
|
| 485 |
+
recommendations.append("โ
**Ideal pH**: Between 6.5-7.5")
|
| 486 |
|
| 487 |
if nitrogen < 200:
|
| 488 |
+
recommendations.append("๐ก **Low Nitrogen**: Apply NPK 20:20:0")
|
| 489 |
elif nitrogen > 500:
|
| 490 |
+
recommendations.append("๐ก **High Nitrogen**: Reduce nitrogen fertilizer")
|
| 491 |
else:
|
| 492 |
+
recommendations.append("โ
**Optimal Nitrogen**: Good")
|
| 493 |
|
| 494 |
if phosphorus < 10:
|
| 495 |
+
recommendations.append("๐ก **Low Phosphorus**: Apply DAP or SSP")
|
| 496 |
+
elif phosphorus > 30:
|
| 497 |
+
recommendations.append("๐ก **High Phosphorus**: No additional needed")
|
| 498 |
else:
|
| 499 |
+
recommendations.append("โ
**Optimal Phosphorus**: Good")
|
| 500 |
|
| 501 |
if potassium < 100:
|
| 502 |
+
recommendations.append("๐ก **Low Potassium**: Apply KCl or MOP")
|
| 503 |
+
elif potassium > 300:
|
| 504 |
+
recommendations.append("๐ก **High Potassium**: Reduce fertilizer")
|
| 505 |
else:
|
| 506 |
+
recommendations.append("โ
**Optimal Potassium**: Good")
|
| 507 |
|
| 508 |
return recommendations
|
| 509 |
|
| 510 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 511 |
+
# FEATURE 9: YIELD PREDICTION ML
|
| 512 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 513 |
|
| 514 |
def train_yield_model():
|
|
|
|
| 517 |
return None, None
|
| 518 |
|
| 519 |
X_train = np.array([
|
| 520 |
+
[25, 80, 250, 20, 2.5],
|
| 521 |
[28, 70, 200, 6.5, 3.0],
|
| 522 |
[22, 85, 300, 6.8, 2.8],
|
| 523 |
[26, 75, 250, 7.0, 3.2],
|
|
|
|
| 568 |
return max(0, yield_pred)
|
| 569 |
|
| 570 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 571 |
+
# FEATURE 10: 7-DAY WEATHER FORECAST
|
| 572 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 573 |
+
|
| 574 |
+
def get_7day_forecast(location):
|
| 575 |
+
"""Get 7-day weather forecast"""
|
| 576 |
+
try:
|
| 577 |
+
api_key = st.secrets.get("OPENWEATHER_API_KEY")
|
| 578 |
+
|
| 579 |
+
if not api_key:
|
| 580 |
+
return None
|
| 581 |
+
|
| 582 |
+
geo_url = "https://api.openweathermap.org/geo/1.0/direct"
|
| 583 |
+
geo_params = {"q": location, "limit": 1, "appid": api_key}
|
| 584 |
+
geo_resp = requests.get(geo_url, params=geo_params)
|
| 585 |
+
|
| 586 |
+
if not geo_resp.json():
|
| 587 |
+
return None
|
| 588 |
+
|
| 589 |
+
lat, lon = geo_resp.json()[0]['lat'], geo_resp.json()[0]['lon']
|
| 590 |
+
|
| 591 |
+
forecast_url = "https://api.openweathermap.org/data/2.5/forecast"
|
| 592 |
+
forecast_params = {
|
| 593 |
+
"lat": lat, "lon": lon, "appid": api_key,
|
| 594 |
+
"units": "metric", "cnt": 56
|
| 595 |
+
}
|
| 596 |
+
|
| 597 |
+
forecast_resp = requests.get(forecast_url, params=forecast_params)
|
| 598 |
+
forecast_data = forecast_resp.json()
|
| 599 |
+
|
| 600 |
+
forecast_list = []
|
| 601 |
+
|
| 602 |
+
for item in forecast_data['list'][::8]:
|
| 603 |
+
forecast_list.append({
|
| 604 |
+
'Date': datetime.fromtimestamp(item['dt']).strftime("%a, %d %b"),
|
| 605 |
+
'Temp': f"{item['main']['temp']:.1f}ยฐC",
|
| 606 |
+
'Humidity': f"{item['main']['humidity']}%",
|
| 607 |
+
'Condition': item['weather'][0]['main'],
|
| 608 |
+
'Wind': f"{item['wind']['speed']:.1f} m/s"
|
| 609 |
+
})
|
| 610 |
+
|
| 611 |
+
return pd.DataFrame(forecast_list)
|
| 612 |
+
|
| 613 |
+
except Exception as e:
|
| 614 |
+
return None
|
| 615 |
+
|
| 616 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 617 |
+
# OPENAI SETUP
|
| 618 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 619 |
+
|
| 620 |
+
def initialize_openai():
|
| 621 |
+
"""Initialize OpenAI client"""
|
| 622 |
+
if not OPENAI_AVAILABLE:
|
| 623 |
+
return None, "OpenAI library not installed"
|
| 624 |
+
|
| 625 |
+
api_key = None
|
| 626 |
+
|
| 627 |
+
try:
|
| 628 |
+
if hasattr(st, 'secrets') and "OPENAI_API_KEY" in st.secrets:
|
| 629 |
+
api_key = st.secrets["OPENAI_API_KEY"]
|
| 630 |
+
except:
|
| 631 |
+
pass
|
| 632 |
+
|
| 633 |
+
if not api_key:
|
| 634 |
+
api_key = os.environ.get("OPENAI_API_KEY")
|
| 635 |
+
|
| 636 |
+
if api_key and api_key.strip():
|
| 637 |
+
try:
|
| 638 |
+
client = OpenAI(api_key=api_key.strip())
|
| 639 |
+
return client, None
|
| 640 |
+
except Exception as e:
|
| 641 |
+
return None, f"Failed: {str(e)}"
|
| 642 |
+
else:
|
| 643 |
+
return None, "No API key found"
|
| 644 |
+
|
| 645 |
+
def get_ai_response(client, user_message: str, context: Dict, language: str = "English") -> str:
|
| 646 |
+
"""Get response from OpenAI GPT"""
|
| 647 |
+
try:
|
| 648 |
+
if not client:
|
| 649 |
+
return "AI service not available."
|
| 650 |
+
|
| 651 |
+
system_prompt = "You are an expert agricultural advisor. Provide helpful farming advice."
|
| 652 |
+
location = context.get("location", "India")
|
| 653 |
+
|
| 654 |
+
messages = [
|
| 655 |
+
{"role": "system", "content": system_prompt},
|
| 656 |
+
{"role": "user", "content": f"Location: {location}\n\n{user_message}"}
|
| 657 |
+
]
|
| 658 |
+
|
| 659 |
+
response = client.chat.completions.create(
|
| 660 |
+
model="gpt-3.5-turbo",
|
| 661 |
+
messages=messages,
|
| 662 |
+
temperature=0.7,
|
| 663 |
+
max_tokens=500
|
| 664 |
+
)
|
| 665 |
+
|
| 666 |
+
return response.choices[0].message.content
|
| 667 |
+
|
| 668 |
+
except Exception as e:
|
| 669 |
+
return f"Error: {str(e)}"
|
| 670 |
+
|
| 671 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 672 |
+
# HELPER FUNCTIONS
|
| 673 |
# โโโโโโโ๏ฟฝ๏ฟฝโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 674 |
|
| 675 |
def get_weather_data(location: str) -> Optional[Dict]:
|
|
|
|
| 717 |
"""Get current agricultural season"""
|
| 718 |
month = datetime.now().month
|
| 719 |
if month in [6, 7, 8, 9]:
|
| 720 |
+
return "Kharif"
|
| 721 |
elif month in [10, 11, 12, 1, 2]:
|
| 722 |
+
return "Rabi"
|
| 723 |
else:
|
| 724 |
+
return "Summer"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 725 |
|
| 726 |
+
def get_market_prices(crop: str) -> Dict:
|
| 727 |
+
"""Get market prices"""
|
| 728 |
+
prices = {
|
| 729 |
+
"Wheat": 2200, "Rice": 2500, "Cotton": 5500, "Sugarcane": 290,
|
| 730 |
+
"Potato": 1500, "Tomato": 1200, "Onion": 1800, "Corn": 1900
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 731 |
}
|
| 732 |
+
|
| 733 |
+
base = prices.get(crop, 2000)
|
| 734 |
+
return {'crop': crop, 'price': base, 'min': base * 0.85, 'max': base * 1.15}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 735 |
|
| 736 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 737 |
# SESSION STATE INITIALIZATION
|
| 738 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 739 |
|
| 740 |
+
if "messages" not in st.session_state:
|
| 741 |
+
st.session_state.messages = []
|
| 742 |
if "location" not in st.session_state:
|
| 743 |
+
st.session_state.location = "Maharashtra"
|
| 744 |
if "language" not in st.session_state:
|
| 745 |
+
st.session_state.language = "English"
|
| 746 |
+
if "openai_client" not in st.session_state:
|
| 747 |
+
client, error = initialize_openai()
|
| 748 |
+
st.session_state.openai_client = client
|
| 749 |
+
st.session_state.openai_error = error
|
| 750 |
if "user_authenticated" not in st.session_state:
|
| 751 |
st.session_state.user_authenticated = False
|
| 752 |
st.session_state.username = None
|
|
|
|
| 757 |
st.session_state.db_initialized = True
|
| 758 |
|
| 759 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 760 |
+
# SIDEBAR
|
| 761 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 762 |
|
| 763 |
with st.sidebar:
|
| 764 |
+
st.markdown("### โ๏ธ SETTINGS")
|
| 765 |
|
| 766 |
location = st.selectbox(
|
| 767 |
+
"๐ Your Location",
|
| 768 |
+
["Maharashtra", "Punjab", "Haryana", "Uttar Pradesh", "Karnataka"],
|
| 769 |
+
key="sidebar_location"
|
| 770 |
)
|
| 771 |
st.session_state.location = location
|
| 772 |
|
| 773 |
language = st.selectbox(
|
| 774 |
+
"๐ Language",
|
| 775 |
+
["English", "Hindi", "Marathi"],
|
| 776 |
+
key="sidebar_language"
|
|
|
|
| 777 |
)
|
| 778 |
+
st.session_state.language = language
|
| 779 |
|
| 780 |
+
st.divider()
|
| 781 |
+
st.markdown("### ๐ค AI STATUS")
|
| 782 |
+
|
| 783 |
+
if st.session_state.openai_client:
|
| 784 |
+
st.success("โ
AI Enabled")
|
| 785 |
+
else:
|
| 786 |
+
st.error("โ AI Disabled")
|
| 787 |
+
|
| 788 |
+
if st.button("๐ Reinitialize AI"):
|
| 789 |
+
client, error = initialize_openai()
|
| 790 |
+
st.session_state.openai_client = client
|
| 791 |
+
st.session_state.openai_error = error
|
| 792 |
st.rerun()
|
| 793 |
|
| 794 |
st.divider()
|
|
|
|
| 798 |
# MAIN CONTENT
|
| 799 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 800 |
|
| 801 |
+
st.markdown("# ๐พ FARMER COPILOT v3.0 - COMPLETE")
|
| 802 |
+
st.markdown("### AI Agricultural Intelligence Platform with 15 Features ๐")
|
| 803 |
st.divider()
|
| 804 |
|
| 805 |
# DEFINE TABS WITH UNIQUE KEYS
|
| 806 |
tab1, tab2, tab3, tab4, tab5, tab6, tab7, tab8, tab9, tab10, tab11, tab12 = st.tabs([
|
| 807 |
+
"๐ฌ AI Chat", "๐ค๏ธ Weather", "๐ฐ Market", "๐ฑ Crops",
|
| 808 |
+
"๐ Pests", "๐ง Irrigation", "๐ Analytics", "๐ธ Image",
|
| 809 |
+
"๐ค Voice", "๐งช Soil", "๐ Yield", "๐ค Profile"
|
| 810 |
])
|
| 811 |
|
| 812 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 813 |
+
# TAB 1: AI CHAT
|
| 814 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 815 |
|
| 816 |
with tab1:
|
| 817 |
+
st.markdown("### ๐ฌ Talk to Your AI Copilot")
|
|
|
|
|
|
|
|
|
|
| 818 |
|
| 819 |
+
if not st.session_state.openai_client:
|
| 820 |
+
st.warning("โ ๏ธ AI is disabled! Add OPENAI_API_KEY to secrets.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 821 |
|
| 822 |
+
user_input = st.text_input("Your question...", key="chat_input_main")
|
| 823 |
|
| 824 |
+
if st.button("๐ Send", key="chat_send_btn"):
|
| 825 |
+
if user_input:
|
| 826 |
+
st.session_state.messages.append(("user", user_input))
|
| 827 |
+
|
| 828 |
+
if st.session_state.openai_client:
|
| 829 |
+
context = {"location": st.session_state.location, "season": get_current_season()}
|
| 830 |
+
with st.spinner("๐ค Thinking..."):
|
| 831 |
+
ai_response = get_ai_response(
|
| 832 |
+
st.session_state.openai_client,
|
| 833 |
+
user_input,
|
| 834 |
+
context,
|
| 835 |
+
st.session_state.language
|
| 836 |
+
)
|
| 837 |
+
else:
|
| 838 |
+
ai_response = "AI is disabled."
|
| 839 |
+
|
| 840 |
+
st.session_state.messages.append(("ai", ai_response))
|
| 841 |
+
st.rerun()
|
| 842 |
|
| 843 |
+
if st.session_state.messages:
|
| 844 |
+
for msg_type, content in st.session_state.messages[-10:]:
|
| 845 |
+
if msg_type == "user":
|
| 846 |
+
st.info(f"๐จโ๐พ You: {content}")
|
| 847 |
+
else:
|
| 848 |
+
st.success(f"๐ค Copilot: {content}")
|
| 849 |
+
|
| 850 |
+
if st.button("๐๏ธ Clear Chat", key="clear_chat_btn"):
|
| 851 |
+
st.session_state.messages = []
|
| 852 |
+
st.rerun()
|
| 853 |
|
| 854 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 855 |
# TAB 2: WEATHER
|
| 856 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 857 |
|
| 858 |
with tab2:
|
| 859 |
+
st.markdown("### ๐ค๏ธ Weather & Climate")
|
| 860 |
|
| 861 |
+
if st.button("๐ Refresh Weather", key="weather_refresh"):
|
| 862 |
+
with st.spinner("Fetching..."):
|
| 863 |
weather = get_weather_data(st.session_state.location)
|
| 864 |
if weather:
|
| 865 |
+
col1, col2, col3 = st.columns(3)
|
| 866 |
+
col1.metric("๐ก๏ธ Temperature", f"{weather['temperature']:.1f}ยฐC")
|
| 867 |
+
col2.metric("๐ง Humidity", f"{weather['humidity']}%")
|
| 868 |
+
col3.metric("๐จ Wind", f"{weather['wind_speed']:.1f} m/s")
|
| 869 |
+
|
| 870 |
+
if st.button("๐
Get 7-Day Forecast", key="weather_forecast"):
|
| 871 |
+
forecast_df = get_7day_forecast(st.session_state.location)
|
| 872 |
+
if forecast_df is not None:
|
| 873 |
+
st.dataframe(forecast_df, use_container_width=True)
|
| 874 |
|
| 875 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 876 |
# TAB 3: MARKET PRICES
|
| 877 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 878 |
|
| 879 |
with tab3:
|
| 880 |
+
st.markdown("### ๐ฐ Live Market Prices")
|
| 881 |
|
| 882 |
+
if st.button("๐ Refresh Prices", key="market_refresh"):
|
| 883 |
live_prices = get_live_market_prices()
|
| 884 |
if live_prices:
|
| 885 |
+
col1, col2 = st.columns(2)
|
| 886 |
crops_list = list(live_prices.keys())
|
| 887 |
|
| 888 |
+
with col1:
|
| 889 |
+
for crop in crops_list[:4]:
|
| 890 |
+
st.metric(crop, f"โน{live_prices[crop]}")
|
| 891 |
+
|
| 892 |
+
with col2:
|
| 893 |
+
for crop in crops_list[4:]:
|
| 894 |
+
st.metric(crop, f"โน{live_prices[crop]}")
|
| 895 |
|
| 896 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 897 |
+
# TAB 4-7: PLACEHOLDER TABS (Crops, Pests, Irrigation, Analytics)
|
| 898 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 899 |
|
| 900 |
with tab4:
|
| 901 |
+
st.markdown("### ๐ฑ Crop Recommendations")
|
| 902 |
+
st.info("๐พ Cotton, Wheat, Rice, Sugarcane - Select based on season")
|
| 903 |
+
st.write("Current Season:", get_current_season())
|
| 904 |
|
| 905 |
with tab5:
|
| 906 |
+
st.markdown("### ๐ Pest & Disease Management")
|
| 907 |
+
st.info("Pest management tips and identification guide")
|
| 908 |
|
| 909 |
with tab6:
|
| 910 |
+
st.markdown("### ๐ง Irrigation Management")
|
| 911 |
+
st.info("Smart irrigation scheduling and water conservation")
|
| 912 |
|
| 913 |
with tab7:
|
| 914 |
+
st.markdown("### ๐ Farm Analytics")
|
| 915 |
+
st.info("Profit calculations and farm statistics")
|
| 916 |
|
| 917 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 918 |
+
# TAB 8: IMAGE RECOGNITION (UNIQUE KEYS!)
|
| 919 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 920 |
|
| 921 |
with tab8:
|
| 922 |
+
st.markdown("### ๐ธ Pest & Disease Detection")
|
| 923 |
+
uploaded_file = st.file_uploader("Upload leaf photo", type=['jpg', 'jpeg', 'png'], key="image_uploader")
|
|
|
|
| 924 |
|
| 925 |
+
if uploaded_file and st.button("๐ Analyze", key="image_analyze_btn"):
|
| 926 |
+
if IMAGE_RECOGNITION_AVAILABLE:
|
| 927 |
+
result, error = analyze_plant_disease(uploaded_file)
|
| 928 |
+
if error:
|
| 929 |
+
st.error(error)
|
| 930 |
+
else:
|
| 931 |
+
col1, col2, col3 = st.columns(3)
|
| 932 |
+
col1.metric("Disease", result['disease'].split('-')[0])
|
| 933 |
+
col2.metric("Confidence", f"{result['confidence']:.1f}%")
|
| 934 |
+
col3.metric("Severity", result['severity'])
|
| 935 |
+
else:
|
| 936 |
+
st.warning("Image recognition not available")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 937 |
|
| 938 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 939 |
+
# TAB 9: VOICE (UNIQUE KEYS!)
|
| 940 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 941 |
|
| 942 |
with tab9:
|
| 943 |
+
st.markdown("### ๐ค Voice Interaction")
|
| 944 |
+
col1, col2 = st.columns(2)
|
| 945 |
+
|
| 946 |
+
with col1:
|
| 947 |
+
if st.button("๐๏ธ Speak Question", key="voice_input_btn"):
|
| 948 |
+
if VOICE_AVAILABLE:
|
| 949 |
+
text, error = voice_input()
|
| 950 |
+
if error:
|
| 951 |
+
st.error(error)
|
| 952 |
+
elif text:
|
| 953 |
+
st.success(f"You said: {text}")
|
| 954 |
+
else:
|
| 955 |
+
st.warning("Voice not available")
|
| 956 |
+
|
| 957 |
+
with col2:
|
| 958 |
+
if st.button("๐ Play Response", key="voice_output_btn"):
|
| 959 |
+
if VOICE_AVAILABLE and st.session_state.messages:
|
| 960 |
+
last_response = st.session_state.messages[-1][1]
|
| 961 |
+
voice_output(last_response)
|
| 962 |
+
else:
|
| 963 |
+
st.warning("No response to play")
|
| 964 |
|
| 965 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 966 |
+
# TAB 10: SOIL HEALTH (UNIQUE KEYS!)
|
| 967 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 968 |
|
| 969 |
with tab10:
|
| 970 |
+
st.markdown("### ๐งช Soil Health Monitoring")
|
| 971 |
|
| 972 |
col1, col2, col3 = st.columns(3)
|
| 973 |
with col1:
|
| 974 |
+
pH = st.slider("Soil pH", 4.0, 9.0, 6.5, key="soil_pH_slider")
|
| 975 |
+
nitrogen = st.slider("Nitrogen (mg/kg)", 0, 1000, 250, key="soil_nitrogen_slider")
|
| 976 |
with col2:
|
| 977 |
+
phosphorus = st.slider("Phosphorus (mg/kg)", 0, 100, 20, key="soil_phosphorus_slider")
|
| 978 |
+
potassium = st.slider("Potassium (mg/kg)", 0, 500, 150, key="soil_potassium_slider")
|
| 979 |
with col3:
|
| 980 |
+
organic_matter = st.slider("Organic Matter (%)", 0.0, 10.0, 2.5, key="soil_organic_slider")
|
| 981 |
+
moisture = st.slider("Soil Moisture (%)", 0.0, 50.0, 25.0, key="soil_moisture_slider")
|
| 982 |
|
| 983 |
+
if st.button("๐พ Save Soil Test", key="soil_save_btn"):
|
| 984 |
save_soil_test(st.session_state.location, pH, nitrogen, phosphorus, potassium, organic_matter, moisture)
|
| 985 |
+
st.success("Saved!")
|
| 986 |
|
| 987 |
recommendations = get_soil_recommendations(pH, nitrogen, phosphorus, potassium)
|
|
|
|
| 988 |
for rec in recommendations:
|
| 989 |
st.markdown(rec)
|
| 990 |
|
| 991 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 992 |
+
# TAB 11: YIELD PREDICTION (UNIQUE KEYS!)
|
| 993 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 994 |
|
| 995 |
with tab11:
|
| 996 |
+
st.markdown("### ๐ Yield Prediction")
|
| 997 |
|
| 998 |
col1, col2, col3 = st.columns(3)
|
| 999 |
with col1:
|
| 1000 |
+
temp = st.slider("Temperature (ยฐC)", 0, 45, 25, key="yield_temp_slider")
|
| 1001 |
+
humidity = st.slider("Humidity (%)", 0, 100, 70, key="yield_humidity_slider")
|
| 1002 |
with col2:
|
| 1003 |
+
rainfall = st.slider("Rainfall (mm)", 0, 500, 250, key="yield_rainfall_slider")
|
| 1004 |
+
pH = st.slider("Soil pH", 4.0, 9.0, 6.8, key="yield_pH_slider")
|
| 1005 |
with col3:
|
| 1006 |
+
org_matter = st.slider("Organic Matter (%)", 0.0, 10.0, 2.5, key="yield_orgmatter_slider")
|
| 1007 |
|
| 1008 |
+
if st.button("๐ฎ Predict Yield", key="yield_predict_btn"):
|
| 1009 |
yield_pred = predict_yield(temp, humidity, rainfall, pH, org_matter)
|
| 1010 |
+
st.metric("Predicted Yield", f"{yield_pred:.1f} q/hectare")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1011 |
|
| 1012 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1013 |
+
# TAB 12: USER PROFILE (UNIQUE KEYS!)
|
| 1014 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 1015 |
|
| 1016 |
with tab12:
|
| 1017 |
+
st.markdown("### ๐ค User Profile & Settings")
|
| 1018 |
|
| 1019 |
if not st.session_state.user_authenticated:
|
| 1020 |
+
auth_choice = st.radio("Choose", ["๐ Login", "๐ Register"], key="auth_choice_radio")
|
| 1021 |
|
| 1022 |
+
if auth_choice == "๐ Login":
|
| 1023 |
+
username = st.text_input("Username", key="login_username")
|
| 1024 |
+
password = st.text_input("Password", type="password", key="login_password")
|
|
|
|
|
|
|
| 1025 |
|
| 1026 |
+
if st.button("Login", key="login_btn"):
|
| 1027 |
success, result = login_user(username, password)
|
|
|
|
| 1028 |
if success:
|
| 1029 |
st.session_state.user_authenticated = True
|
| 1030 |
st.session_state.username = username
|
| 1031 |
+
st.success("Logged in!")
|
| 1032 |
st.rerun()
|
| 1033 |
else:
|
| 1034 |
+
st.error("Invalid credentials")
|
|
|
|
| 1035 |
else:
|
| 1036 |
+
new_username = st.text_input("Username", key="register_username")
|
| 1037 |
+
new_email = st.text_input("Email", key="register_email")
|
| 1038 |
+
new_password = st.text_input("Password", type="password", key="register_password")
|
|
|
|
|
|
|
| 1039 |
|
| 1040 |
+
if st.button("Register", key="register_btn"):
|
| 1041 |
success, msg = register_user(new_username, new_password, new_email, st.session_state.location)
|
| 1042 |
+
st.success(msg) if success else st.error(msg)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1043 |
else:
|
| 1044 |
+
st.success(f"Logged in as: {st.session_state.username}")
|
| 1045 |
+
if st.button("Logout", key="logout_btn"):
|
|
|
|
| 1046 |
st.session_state.user_authenticated = False
|
|
|
|
| 1047 |
st.rerun()
|
| 1048 |
|
| 1049 |
st.divider()
|
| 1050 |
+
st.markdown("<div style='text-align: center'><p>๐พ FARMER COPILOT v3.0 - All 15 Features | Powered by OpenAI</p></div>", unsafe_allow_html=True)
|