diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..18e4d7f5
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,11 @@
+.venv/
+venv/
+__pycache__/
+*.pyc
+*.pyo
+*.pyd
+.Python
+.env
+.env.*
+.idea/
+.vscode/
diff --git a/KishanMitra.py b/KishanMitra.py
deleted file mode 100644
index 620f2d1c..00000000
--- a/KishanMitra.py
+++ /dev/null
@@ -1,171 +0,0 @@
-import streamlit as st
-from datetime import datetime
-from gtts import gTTS
-import base64
-import os
-
-# ------------------ Utility Function ------------------
-def play_audio(text, lang_code='en'):
- tts = gTTS(text=text, lang=lang_code)
- filename = "temp_audio.mp3"
- tts.save(filename)
- with open(filename, "rb") as audio_file:
- audio_bytes = audio_file.read()
- b64 = base64.b64encode(audio_bytes).decode()
- audio_html = f''
- st.markdown(audio_html, unsafe_allow_html=True)
- os.remove(filename)
-
-# ------------------ Language Data ------------------
-LANGUAGE_DATA = {
- "English": {
- "welcome": "🌾 Welcome to KrishiMitra!",
- "fertilizer": "🌱 Fertilizer Recommendation",
- "loan": "🏦 Loan/Subsidy Checker",
- "weather_alert": "🌦️ Weather Alerts",
- "crop_calendar": "📅 Crop Calendar",
- "tts_lang": "en"
- },
- "Hindi": {
- "welcome": "🌾 कृषि मित्र में आपका स्वागत है!",
- "fertilizer": "🌱 उर्वरक सिफारिश",
- "loan": "🏦 ऋण/सब्सिडी जांच",
- "weather_alert": "🌦️ मौसम अलर्ट",
- "crop_calendar": "📅 फसल कैलेंडर",
- "tts_lang": "hi"
- },
- "Bhojpuri": {
- "welcome": "🌾 कृषिमित्र में रउआ स्वागत बा!",
- "fertilizer": "🌱 खाद सिफारिश",
- "loan": "🏦 कर्ज/सब्सिडी जांच",
- "weather_alert": "🌦️ मौसम चेतावनी",
- "crop_calendar": "📅 फसल कैलेंडर",
- "tts_lang": "hi"
- },
- "Punjabi": {
- "welcome": "🌾 ਕ੍ਰਿਸ਼ੀ ਮਿਤਰ ਵਿੱਚ ਤੁਹਾਡਾ ਸੁਆਗਤ ਹੈ!",
- "fertilizer": "🌱 ਖਾਦ ਸਿਫਾਰਸ਼",
- "loan": "🏦 ਕਰਜ਼ਾ ਜਾਂ ਸਬਸਿਡੀ ਚੈੱਕਰ",
- "weather_alert": "🌦️ ਮੌਸਮ ਚੇਤਾਵਨੀ",
- "crop_calendar": "📅 ਫਸਲ ਕੈਲੰਡਰ",
- "tts_lang": "pa"
- },
- "Tamil": {
- "welcome": "🌾 கிருஷிமித்ராவிற்கு வரவேற்கிறோம்!",
- "fertilizer": "🌱 உர பரிந்துரை",
- "loan": "🏦 கடன்/தொகை சரிபார்ப்பு",
- "weather_alert": "🌦️ வானிலை எச்சரிக்கை",
- "crop_calendar": "📅 பயிர் நாட்காட்டி",
- "tts_lang": "ta"
- },
- "Telugu": {
- "welcome": "🌾 కృషిమిత్రా కు స్వాగతం!",
- "fertilizer": "🌱 ఎరువు సిఫార్సు",
- "loan": "🏦 రుణం/సబ్సిడీ తనిఖీ",
- "weather_alert": "🌦️ వాతావరణ హెచ్చరికలు",
- "crop_calendar": "📅 పంట క్యాలెండర్",
- "tts_lang": "te"
- },
- "Kannada": {
- "welcome": "🌾 ಕೃಷಿ ಮಿತ್ರಕ್ಕೆ ಸ್ವಾಗತ!",
- "fertilizer": "🌱 ರಸಗೊಬ್ಬರ ಶಿಫಾರಸು",
- "loan": "🏦 ಸಾಲ/ಸಬ್ಸಿಡಿ ತಪಾಸಣೆ",
- "weather_alert": "🌦️ ಹವಾಮಾನ ಎಚ್ಚರಿಕೆ",
- "crop_calendar": "📅 ಬೆಳೆ ದಿನದರ್ಶಿ",
- "tts_lang": "kn"
- },
- "Awadhi": {
- "welcome": "🌾 कृषिमित्र मा तोहार स्वागत बा!",
- "fertilizer": "🌱 खाद सिफारिश",
- "loan": "🏦 कर्ज/सब्सिडी जांच",
- "weather_alert": "🌦️ मौसम चेतावनी",
- "crop_calendar": "📅 फसल कैलेंडर",
- "tts_lang": "hi"
- }
-}
-
-# ------------------ Sidebar for Language ------------------
-st.sidebar.title("🌐 Select Language")
-language = st.sidebar.selectbox("Choose your preferred language:", list(LANGUAGE_DATA.keys()))
-lang_content = LANGUAGE_DATA[language]
-
-# ------------------ Main UI ------------------
-st.title(lang_content["welcome"])
-
-if st.button("🔊 Read Aloud"):
- play_audio(lang_content["welcome"], lang_content["tts_lang"])
-
-
-
-# ------------------ Fertilizer Recommendation ------------------
-st.header(lang_content["fertilizer"])
-crop = st.selectbox("Select Crop", ["Wheat", "Rice", "Maize", "Cereals", "Sugarcane", "Potato", "Tomato"])
-soil = st.selectbox("Soil Type", ["Black", "Red", "Sandy", "Brown"])
-if st.button("Get Recommendation"):
- rec = f"For {crop} in {soil} soil, use NPK 20:20:0 at 50kg/acre."
- st.success(rec)
- if st.button("🔊 Listen Recommendation"):
- play_audio(rec, lang_content["tts_lang"])
-
-# ------------------ Loan/Subsidy Checker ------------------
-st.header(lang_content["loan"])
-age = st.number_input("Enter your age", min_value=18, max_value=80)
-holding = st.selectbox("Land holding (acres)", ["<1", "1-5", ">5"])
-if st.button("Check Eligibility"):
- eligible = "You are eligible for KCC and PM-KISAN schemes."
- st.info(eligible)
- if st.button("🔊 Listen Eligibility"):
- play_audio(eligible, lang_content["tts_lang"])
-
-# ------------------ Weather Alerts ------------------
-st.header(lang_content["weather_alert"])
-today = datetime.now().strftime("%d-%m-%Y")
-st.write(f"Today's Date: {today}")
-st.warning("⚠️ Heavy Rain Expected in your region today.")
-
-# ------------------ Crop Calendar ------------------
-st.header(lang_content["crop_calendar"])
-season = st.selectbox("Choose Season", ["Rabi", "Kharif", "Zaid"])
-if st.button("Show Calendar"):
- calendar = f"For {season}, sow Wheat, Mustard, and Barley."
- st.success(calendar)
- if st.button("🔊 Listen Calendar"):
- play_audio(calendar, lang_content["tts_lang"])
-
-
-
-# ------------------ Mandi Prices ------------------
-st.subheader(['price_info'])
-mandi_data ={
- "wheat": "₹2200/qtl",
- "rice": "₹1800/qtl",
- "mustard": "₹5500/qtl",
- "maize": "₹1700/qtl",
- "barley": "₹1600/qtl",
- "soybean": "₹4800/qtl",
- "cotton": "₹6600/qtl",
- "groundnut": "₹5500/qtl",
- "sugarcane": "₹340/qtl",
- "potato": "₹1200/qtl",
- "onion": "₹900/qtl",
- "tomato": "₹1100/qtl",
- "bajra": "₹2150/qtl",
- "jowar": "₹2738/qtl",
- "urad dal": "₹6600/qtl",
- "moong dal": "₹7275/qtl",
- "chana": "₹5400/qtl",
- "masoor dal": "₹6000/qtl",
- "banana": "₹1500/qtl",
- "apple": "₹3000/qtl",
- "brinjal": "₹900/qtl",
- "carrot": "₹1100/qtl",
- "cabbage": "₹850/qtl",
- "peas": "₹1400/qtl"
-
-}
-st.table(mandi_data)
-# ------------------ Footer ------------------
-st.markdown("---")
-st.markdown("Made with ❤️ for Indian Farmers - KrishiMitra")
-
-
diff --git a/KrishiMitra.py b/KrishiMitra.py
index ebd3b840..40681bed 100644
--- a/KrishiMitra.py
+++ b/KrishiMitra.py
@@ -3,6 +3,13 @@
from gtts import gTTS
import base64
import os
+import pandas as pd
+from chatbot import ask_groq
+from weather import get_weather
+import streamlit.components.v1 as components
+
+API_KEY = "Your_OpenWeather_API_Key" # Replace with your actual OpenWeather API key
+GROQ_API_KEY = "Your_Groq_API_Key" # Replace with your actual Groq API key
# ------------------ Utility Function ------------------
def play_audio(text, lang_code='en'):
@@ -34,142 +41,112 @@ def play_audio(text, lang_code='en'):
"crop_calendar": "📅 फसल कैलेंडर",
"tts_lang": "hi"
},
- "Bhojpuri": {
- "welcome": "🌾 कृषिमित्र में रउआ स्वागत बा!",
- "fertilizer": "🌱 खाद सिफारिश",
- "loan": "🏦 कर्ज/सब्सिडी जांच",
- "weather_alert": "🌦️ मौसम चेतावनी",
- "crop_calendar": "📅 फसल कैलेंडर",
- "tts_lang": "hi"
- },
- "Punjabi": {
- "welcome": "🌾 ਕ੍ਰਿਸ਼ੀ ਮਿਤਰ ਵਿੱਚ ਤੁਹਾਡਾ ਸੁਆਗਤ ਹੈ!",
- "fertilizer": "🌱 ਖਾਦ ਸਿਫਾਰਸ਼",
- "loan": "🏦 ਕਰਜ਼ਾ ਜਾਂ ਸਬਸਿਡੀ ਚੈੱਕਰ",
- "weather_alert": "🌦️ ਮੌਸਮ ਚੇਤਾਵਨੀ",
- "crop_calendar": "📅 ਫਸਲ ਕੈਲੰਡਰ",
- "tts_lang": "pa"
- },
- "Tamil": {
- "welcome": "🌾 கிருஷிமித்ராவிற்கு வரவேற்கிறோம்!",
- "fertilizer": "🌱 உர பரிந்துரை",
- "loan": "🏦 கடன்/தொகை சரிபார்ப்பு",
- "weather_alert": "🌦️ வானிலை எச்சரிக்கை",
- "crop_calendar": "📅 பயிர் நாட்காட்டி",
- "tts_lang": "ta"
- },
- "Telugu": {
- "welcome": "🌾 కృషిమిత్రా కు స్వాగతం!",
- "fertilizer": "🌱 ఎరువు సిఫార్సు",
- "loan": "🏦 రుణం/సబ్సిడీ తనిఖీ",
- "weather_alert": "🌦️ వాతావరణ హెచ్చరికలు",
- "crop_calendar": "📅 పంట క్యాలెండర్",
- "tts_lang": "te"
- },
- "Kannada": {
- "welcome": "🌾 ಕೃಷಿ ಮಿತ್ರಕ್ಕೆ ಸ್ವಾಗತ!",
- "fertilizer": "🌱 ರಸಗೊಬ್ಬರ ಶಿಫಾರಸು",
- "loan": "🏦 ಸಾಲ/ಸಬ್ಸಿಡಿ ತಪಾಸಣೆ",
- "weather_alert": "🌦️ ಹವಾಮಾನ ಎಚ್ಚರಿಕೆ",
- "crop_calendar": "📅 ಬೆಳೆ ದಿನದರ್ಶಿ",
- "tts_lang": "kn"
- },
- "Awadhi": {
- "welcome": "🌾 कृषिमित्र मा तोहार स्वागत बा!",
- "fertilizer": "🌱 खाद सिफारिश",
- "loan": "🏦 कर्ज/सब्सिडी जांच",
- "weather_alert": "🌦️ मौसम चेतावनी",
- "crop_calendar": "📅 फसल कैलेंडर",
- "tts_lang": "hi"
- }
+ # other languages...
}
# ------------------ Sidebar for Language ------------------
st.sidebar.title("🌐 Select Language")
language = st.sidebar.selectbox("Choose your preferred language:", list(LANGUAGE_DATA.keys()))
lang_content = LANGUAGE_DATA[language]
+tts_lang = lang_content["tts_lang"]
# ------------------ Main UI ------------------
st.title(lang_content["welcome"])
-
if st.button("🔊 Read Aloud"):
- play_audio(lang_content["welcome"], lang_content["tts_lang"])
+ play_audio(lang_content["welcome"], tts_lang)
+# ------------------ Fertilizer Recommendation ------------------
+with st.expander(lang_content["fertilizer"]):
+ crop = st.selectbox("Select Crop", ["Wheat", "Rice", "Maize", "Cereals", "Sugarcane", "Potato", "Tomato"])
+ soil = st.selectbox("Soil Type", ["Black", "Red", "Sandy", "Brown"])
+ if st.button("Get Recommendation"):
+ rec = f"For {crop} in {soil} soil, use NPK 20:20:0 at 50kg/acre."
+ st.session_state["recommendation"] = rec
+ st.success(rec)
-# ------------------ Fertilizer Recommendation ------------------
-st.header(lang_content["fertilizer"])
-crop = st.selectbox("Select Crop", ["Wheat", "Rice", "Maize", "Cereals", "Sugarcane", "Potato", "Tomato"])
-soil = st.selectbox("Soil Type", ["Black", "Red", "Sandy", "Brown"])
-if st.button("Get Recommendation"):
- rec = f"For {crop} in {soil} soil, use NPK 20:20:0 at 50kg/acre."
- st.success(rec)
- if st.button("🔊 Listen Recommendation"):
- play_audio(rec, lang_content["tts_lang"])
+ if "recommendation" in st.session_state and st.button("🔊 Listen Recommendation"):
+ play_audio(st.session_state["recommendation"], tts_lang)
# ------------------ Loan/Subsidy Checker ------------------
-st.header(lang_content["loan"])
-age = st.number_input("Enter your age", min_value=18, max_value=80)
-holding = st.selectbox("Land holding (acres)", ["<1", "1-5", ">5"])
-if st.button("Check Eligibility"):
- eligible = "You are eligible for KCC and PM-KISAN schemes."
- st.info(eligible)
- if st.button("🔊 Listen Eligibility"):
- play_audio(eligible, lang_content["tts_lang"])
+with st.expander(lang_content["loan"]):
+ age = st.number_input("Enter your age", min_value=18, max_value=80)
+ holding = st.selectbox("Land holding (acres)", ["<1", "1-5", ">5"])
+
+ if st.button("Check Eligibility"):
+ eligible = "You are eligible for KCC and PM-KISAN schemes."
+ st.session_state["eligibility"] = eligible
+ st.info(eligible)
+
+ if "eligibility" in st.session_state and st.button("🔊 Listen Eligibility"):
+ play_audio(st.session_state["eligibility"], tts_lang)
# ------------------ Weather Alerts ------------------
-st.header(lang_content["weather_alert"])
-today = datetime.now().strftime("%d-%m-%Y")
-st.write(f"Today's Date: {today}")
-st.warning("⚠️ Heavy Rain Expected in your region today.")
+with st.expander(lang_content["weather_alert"]):
+ today = datetime.now().strftime("%d-%m-%Y")
+ st.write(f"📅 Today's Date: {today}")
+
+ city = st.text_input("Enter your city for weather updates", value="")
+ if city:
+ weather = get_weather(city, API_KEY)
+ if weather:
+ st.success(f"🌤️ Weather in {city}: {weather['description']}")
+ st.info(f"🌡️ Temperature: {weather['temp']}°C (Feels like {weather['feels_like']}°C)")
+ st.info(f"💧 Humidity: {weather['humidity']}%")
+ st.info(f"🌬️ Wind Speed: {weather['wind_speed']} m/s")
+ if "rain" in weather["description"].lower():
+ st.warning("⚠️ Rain Alert! Please take precautions.")
+ else:
+ st.error("❌ Failed to fetch weather data. Please check the city name or API key.")
# ------------------ Crop Calendar ------------------
-st.header(lang_content["crop_calendar"])
-season = st.selectbox("Choose Season", ["Rabi", "Kharif", "Zaid"])
-if st.button("Show Calendar"):
- calendar = f"For {season}, sow Wheat, Mustard, and Barley."
- st.success(calendar)
- if st.button("🔊 Listen Calendar"):
- play_audio(calendar, lang_content["tts_lang"])
+with st.expander(lang_content["crop_calendar"]):
+ season = st.selectbox("Choose Season", ["Rabi", "Kharif", "Zaid"])
+ if st.button("Show Calendar"):
+ calendar = f"For {season}, sow Wheat, Mustard, and Barley."
+ st.session_state["calendar"] = calendar
+ st.success(calendar)
+ if "calendar" in st.session_state and st.button("🔊 Listen Calendar"):
+ play_audio(st.session_state["calendar"], tts_lang)
# ------------------ Mandi Prices ------------------
-st.subheader(['price_info'])
-mandi_data ={
- "wheat": "₹2200/qtl",
- "rice": "₹1800/qtl",
- "mustard": "₹5500/qtl",
- "maize": "₹1700/qtl",
- "barley": "₹1600/qtl",
- "soybean": "₹4800/qtl",
- "cotton": "₹6600/qtl",
- "groundnut": "₹5500/qtl",
- "sugarcane": "₹340/qtl",
- "potato": "₹1200/qtl",
- "onion": "₹900/qtl",
- "tomato": "₹1100/qtl",
- "bajra": "₹2150/qtl",
- "jowar": "₹2738/qtl",
- "urad dal": "₹6600/qtl",
- "moong dal": "₹7275/qtl",
- "chana": "₹5400/qtl",
- "masoor dal": "₹6000/qtl",
- "banana": "₹1500/qtl",
- "apple": "₹3000/qtl",
- "brinjal": "₹900/qtl",
- "carrot": "₹1100/qtl",
- "cabbage": "₹850/qtl",
- "peas": "₹1400/qtl"
+with st.expander('📈 Mandi Prices'):
+ mandi_data = {
+ "Crop": ["Wheat", "Rice", "Mustard", "Maize", "Barley", "Soybean", "Cotton", "Groundnut", "Sugarcane",
+ "Potato", "Onion", "Tomato", "Bajra", "Jowar", "Urad Dal", "Moong Dal", "Chana", "Masoor Dal",
+ "Banana", "Apple", "Brinjal", "Carrot", "Cabbage", "Peas"],
+ "Price (₹/qtl)": [
+ "₹2200", "₹1800", "₹5500", "₹1700", "₹1600", "₹4800", "₹6600", "₹5500", "₹340",
+ "₹1200", "₹900", "₹1100", "₹2150", "₹2738", "₹6600", "₹7275", "₹5400", "₹6000",
+ "₹1500", "₹3000", "₹900", "₹1100", "₹850", "₹1400"
+ ]
+ }
+ st.table(pd.DataFrame(mandi_data))
-}
-st.table(mandi_data)
-# ------------------ Footer ------------------
-st.markdown("---")
-st.markdown("Made with ❤️ for Indian Farmers - KrishiMitra")
+# ------------------ Chatbot (Subtle Integration) ------------------
+with st.expander("💬 Chat Assistant"):
+ if "chat_history" not in st.session_state:
+ st.session_state.chat_history = []
+ user_input = st.chat_input("Ask your question...")
+ if user_input:
+ with st.spinner("Thinking..."):
+ ai_response = ask_groq(user_input, GROQ_API_KEY)
+ st.session_state.chat_history.append(("You", user_input))
+ st.session_state.chat_history.append(("AI", ai_response))
+ st.session_state["last_ai_response"] = ai_response # ✅ Store last response
+ if "last_ai_response" in st.session_state and st.button("🔊 Listen to AI Response"):
+ play_audio(st.session_state["last_ai_response"], tts_lang)
+ for sender, msg in st.session_state.chat_history:
+ with st.chat_message("user" if sender == "You" else "assistant"):
+ st.markdown(msg)
+# ------------------ Footer ------------------
+st.markdown("---")
+st.markdown("Made with ❤️ for Indian Farmers - KrishiMitra")
diff --git a/KrishiMitraa.py b/KrishiMitraa.py
deleted file mode 100644
index 9c907e04..00000000
--- a/KrishiMitraa.py
+++ /dev/null
@@ -1,261 +0,0 @@
-import streamlit as st
-from datetime import datetime
-import base64
-# ------------------ Language Data ------------------
-LANGUAGE_DATA = {
- "English": {
- "welcome": "🌾 Welcome to KrishiMitra!",
- "fertilizer": "🌱 Fertilizer Recommendation",
- "loan": "🏦 Loan/Subsidy Checker",
- "weather_alert": "🌦️ Weather Alerts",
- "crop_calendar": "📅 Crop Calendar"
- },
- "Hindi": {
- "welcome": "🌾 कृषि मित्र में आपका स्वागत है!",
- "fertilizer": "🌱 उर्वरक सिफारिश",
- "loan": "🏦 ऋण/सब्सिडी जांच",
- "weather_alert": "🌦️ मौसम अलर्ट",
- "crop_calendar": "📅 फसल कैलेंडर",
- },
- "Bhojpuri": {
- "welcome": "🌾 कृषिमित्र में रउआ स्वागत बा!",
- "fertilizer": "🌱 खाद सिफारिश",
- "loan": "🏦 कर्ज/सब्सिडी जांच",
- "weather_alert": "🌦️ मौसम चेतावनी",
- "crop_calendar": "📅 फसल कैलेंडर",
- },
- "Punjabi": {
- "welcome": "🌾 ਕ੍ਰਿਸ਼ੀ ਮਿਤਰ ਵਿੱਚ ਤੁਹਾਡਾ ਸੁਆਗਤ ਹੈ!",
- "fertilizer": "🌱 ਖਾਦ ਸਿਫਾਰਸ਼",
- "loan": "🏦 ਕਰਜ਼ਾ ਜਾਂ ਸਬਸਿਡੀ ਚੈੱਕਰ",
- "weather_alert": "🌦️ ਮੌਸਮ ਚੇਤਾਵਨੀ",
- "crop_calendar": "📅 ਫਸਲ ਕੈਲੰਡਰ",
- },
- "Tamil": {
- "welcome": "🌾 கிருஷிமித்ராவிற்கு வரவேற்கிறோம்!",
- "fertilizer": "🌱 உர பரிந்துரை",
- "loan": "🏦 கடன்/தொகை சரிபார்ப்பு",
- "weather_alert": "🌦️ வானிலை எச்சரிக்கை",
- "crop_calendar": "📅 பயிர் நாட்காட்டி",
- },
- "Telugu": {
- "welcome": "🌾 కృషిమిత్రా కు స్వాగతం!",
- "fertilizer": "🌱 ఎరువు సిఫార్సు",
- "loan": "🏦 రుణం/సబ్సిడీ తనిఖీ",
- "weather_alert": "🌦️ వాతావరణ హెచ్చరికలు",
- "crop_calendar": "📅 పంట క్యాలెండర్",
- },
- "Kannada": {
- "welcome": "🌾 ಕೃಷಿ ಮಿತ್ರಕ್ಕೆ ಸ್ವಾಗತ!",
- "fertilizer": "🌱 ರಸಗೊಬ್ಬರ ಶಿಫಾರಸು",
- "loan": "🏦 ಸಾಲ/ಸಬ್ಸಿಡಿ ತಪಾಸಣೆ",
- "weather_alert": "🌦️ ಹವಾಮಾನ ಎಚ್ಚರಿಕೆ",
- "crop_calendar": "📅 ಬೆಳೆ ದಿನದರ್ಶಿ",
- },
- "Awadhi": {
- "welcome": "🌾 कृषिमित्र मा तोहार स्वागत बा!",
- "fertilizer": "🌱 खाद सिफारिश",
- "loan": "🏦 कर्ज/सब्सिडी जांच",
- "weather_alert": "🌦️ मौसम चेतावनी",
- "crop_calendar": "📅 फसल कैलेंडर",
- }
- # Add other languages here as needed
-}
-
-# ------------------ Sidebar for Language ------------------
-st.sidebar.title("🌐 Select Language")
-language = st.sidebar.selectbox("Choose your preferred language:", list(LANGUAGE_DATA.keys()))
-lang_content = LANGUAGE_DATA[language]
-
-# ------------------ Main UI ------------------
-st.title(lang_content["welcome"])
-
-# ------------------ Fertilizer Recommendation ------------------
-st.header(lang_content["fertilizer"])
-fertilizer_info = {
- "Wheat": {
- "Black": "Apply 120 kg N, 60 kg P₂O₅, 40 kg K₂O per hectare. Use Urea, DAP, and MOP.",
- "Red": "Apply 100 kg N, 50 kg P₂O₅, 30 kg K₂O per hectare. Add 5 tonnes FYM before sowing.",
- "Sandy": "Use 90 kg N, 45 kg P₂O₅, and 25 kg K₂O. Split N into 2–3 doses.",
- "Brown": "Apply 110 kg N, 55 kg P₂O₅, 35 kg K₂O per hectare. Include organic manure."
- },
- "Rice": {
- "Black": "Apply 100 kg N, 50 kg P₂O₅, 50 kg K₂O per hectare. Use split application for N.",
- "Red": "Use 90 kg N, 40 kg P₂O₅, and 40 kg K₂O. Add zinc sulphate @ 25 kg/ha.",
- "Sandy": "Apply 80 kg N, 30 kg P₂O₅, and 30 kg K₂O. Water management is essential.",
- "Brown": "Use 90:45:45 NPK with green manure incorporation before transplanting."
- },
- "Maize": {
- "Black": "Apply 120 kg N, 60 kg P₂O₅, 40 kg K₂O. Use basal + top dressing method.",
- "Red": "Use 100:50:30 NPK with 5 tonnes FYM. Zinc and Boron may be needed.",
- "Sandy": "Apply 80 kg N, 40 kg P₂O₅, 20 kg K₂O. Split nitrogen application in 3 stages.",
- "Brown": "100 kg N, 50 kg P₂O₅, 30 kg K₂O per hectare. Use organic compost pre-sowing."
- },
- "Potato": {
- "Black": "150:80:120 NPK kg/ha. Apply FYM @ 25 tons/ha before sowing.",
- "Red": "120:60:100 NPK + 2 tonnes of compost. Potassium is critical for tuber growth.",
- "Sandy": "100:40:80 NPK. Add micronutrients like Boron if deficiency appears.",
- "Brown": "130:70:110 NPK. Ensure deep ploughing and ridge formation."
- },
- "Sugarcane": {
- "Black": "Apply 250:115:115 NPK. Apply in 3 split doses with organic matter.",
- "Red": "Use 225:100:100 NPK with 10 tonnes FYM. Micronutrients essential.",
- "Sandy": "200:90:90 NPK. Add press mud or compost for better results.",
- "Brown": "240:110:110 NPK + green manure or biofertilizer for soil enrichment."
- },
- "Tomato": {
- "Black": "100:60:60 NPK per ha. Add 10–15 tonnes FYM. Split nitrogen.",
- "Red": "80:40:50 NPK + Boron and Magnesium. Add neem cake for pest resistance.",
- "Sandy": "70:35:45 NPK. Frequent irrigation needed.",
- "Brown": "90:50:50 NPK + Trichoderma enriched compost for disease control."
- },
- "Mustard": {
- "Black": "80:40:30 NPK + 5 kg Zinc Sulphate. Ideal for higher oil yield.",
- "Red": "70:35:25 NPK. Sulphur application helps oil quality.",
- "Sandy": "60:30:20 NPK. Add FYM and maintain moisture.",
- "Brown": "75:40:25 NPK. Use neem-coated urea."
- }
-}
-crop = st.selectbox("Select Crop", list(fertilizer_info.keys()))
-soil = st.selectbox("Soil Type", list(fertilizer_info[crop].keys()))
-if st.button("Get Recommendation"):
- st.success(fertilizer_info[crop][soil])
-
-# ------------------ Loan/Subsidy Info ------------------
-# ------------------ Loan/Subsidy Info ------------------
-st.header(lang_content["loan"])
-age = st.number_input("Enter your age", min_value=18, max_value=80)
-holding = st.selectbox("Land holding (acres)", ["<1", "1-5", ">5"])
-
-if st.button("Check Eligibility"):
- schemes = []
-
- # Age-based
- if age < 40:
- schemes.append("Kisan Credit Card (KCC)")
- schemes.append("PM-KISAN")
- schemes.append("Youth Agri Loan (NABARD)")
- elif age >= 60:
- schemes.append("Senior Farmer Pension Scheme")
-
- # Landholding-based
- if holding == "<1":
- schemes.extend([
- "PM-KISAN",
- "KALIA Scheme (Odisha)",
- "YSR Rythu Bharosa (Andhra Pradesh)",
- "Mukhya Mantri Krishi Ashirwad (Jharkhand)"
- ])
- elif holding == "1-5":
- schemes.extend([
- "NABARD Subsidized Loans",
- "Solar Pump Subsidy",
- "Crop Insurance Scheme (PMFBY)",
- "Fasal Bima Yojana"
- ])
- elif holding == ">5":
- schemes.extend([
- "NABARD Long-Term Projects",
- "Warehouse Construction Loans",
- "Tractor Subsidy Scheme"
- ])
-
- # Remove duplicates
- schemes = list(set(schemes))
-
- if schemes:
- st.success("✅ You are eligible for the following schemes:")
- for scheme in schemes:
- st.markdown(f"- {scheme}")
- else:
- st.warning("❌ Not eligible for current subsidies based on given inputs.")
-
-# ------------------ Government Schemes ------------------
-st.subheader("📜 Government Schemes")
-schemes = {
- "PM-KISAN": "₹6000/year in 3 installments",
- "PMFBY": "Crop insurance at low premium",
- "KCC": "Credit up to ₹3 lakh @ 4% interest",
- "NABARD": "Irrigation and farm infra support",
- "Mahila Kisan Sashaktikaran": "Skill, input and support for women farmers"
-}
-st.json(schemes)
-
-# ------------------ Weather Alerts ------------------
-st.header(lang_content["weather_alert"])
-region = st.selectbox("Select Region", ["Punjab", "UP", "MP", "Bihar"])
-weather_data = {
- "Punjab": "🌧️ Light rain expected tomorrow",
- "UP": "☀️ Clear skies today",
- "MP": "⛈️ Thunderstorms likely in evening",
- "Bihar": "🌦️ Cloudy with chances of rain"
-}
-st.warning(weather_data[region])
-
-# ------------------ Crop Calendar ------------------
-st.header(lang_content["crop_calendar"])
-season = st.selectbox("Choose Season", ["Rabi", "Kharif", "Zaid"])
-calendar_data = {
- "Rabi": "Wheat, Mustard, Barley",
- "Kharif": "Paddy, Maize, Bajra",
- "Zaid": "Watermelon, Cucumber"
-}
-st.success(calendar_data[season])
-
-# ------------------ Mandi Prices ------------------
-st.subheader("💸 Mandi Prices")
-mandi_data = {
- "wheat": "₹2200/qtl",
- "rice": "₹1800/qtl",
- "mustard": "₹5500/qtl",
- "maize": "₹1700/qtl",
- "barley": "₹1600/qtl",
- "soybean": "₹4800/qtl",
- "cotton": "₹6600/qtl",
- "groundnut": "₹5500/qtl",
- "sugarcane": "₹340/qtl",
- "potato": "₹1200/qtl",
- "onion": "₹900/qtl",
- "tomato": "₹1100/qtl",
- "bajra": "₹2150/qtl",
- "jowar": "₹2738/qtl",
- "urad dal": "₹6600/qtl",
- "moong dal": "₹7275/qtl",
- "chana": "₹5400/qtl",
- "masoor dal": "₹6000/qtl",
- "banana": "₹1500/qtl",
- "apple": "₹3000/qtl",
- "brinjal": "₹900/qtl",
- "carrot": "₹1100/qtl",
- "cabbage": "₹850/qtl",
- "peas": "₹1400/qtl"
-}
-st.table(mandi_data)
-# Place this right after your imports and before any UI code
-
-def set_bg_from_url(image_url):
- st.markdown(
- f"""
-
- """,
- unsafe_allow_html=True
- )
-
-# Example usage:
-set_bg_from_url("https://ibb.co/n4w8k5F.jpg")
-
-
-# ------------------ Task Selection ------------------
-st.subheader("📋 Task for Today")
-tasks = ["Irrigation", "Apply pesticide to paddy", "Harvest tomatoes"]
-task = st.selectbox("Select Task", tasks)
-st.success(f"Your task for today: {task}")
-
-# ------------------ Footer ------------------
-st.markdown("---")
-st.markdown("Made with ❤️ for Indian Farmers - KrishiMitra")
diff --git a/README.md b/README.md
index cf16cee3..701d739a 100644
--- a/README.md
+++ b/README.md
@@ -1,110 +1,90 @@
-# KrishiMitra - Empowering Farmers with Smart Agriculture Tools
+Here's a clean and professional `README.md` for **KrishiMitra** without any emojis or images:
-**KrishiMitra** is an all-in-one AI-powered digital assistant tailored to support Indian farmers by providing vital agricultural insights,
-government schemes, real-time mandi prices, weather updates, crop disease detection, and multilingual support. It aims to bridge the technology
-gap for rural farmers and help improve productivity and decision-making in agriculture.
+---
-## Features
+# KrishiMitra – Empowering Farmers with Smart Agriculture Tools
-### Multi-Language Support
-- Supports regional languages including **Hindi**, **Punjabi**, **Bhojpuri**, **Tamil**, **Telugu**, **Kannada**, and **Awadhi**.
-- Text-to-speech and translated messages using `gTTS` and custom dictionaries.
+**KrishiMitra** is an AI-powered digital assistant designed to help Indian farmers by providing essential agricultural information such as mandi prices, weather updates, farming tasks, and government schemes. It supports multilingual interaction to make agricultural knowledge accessible to farmers in their native languages.
-### Daily Task Reminders
-- Farmers can select and schedule daily agricultural tasks.
-- Tasks are displayed prominently for better time and farm management.
+---
-### Mandi Prices
-- Real-time mandi prices for crops like wheat, rice, mustard, pulses, vegetables, fruits, and more.
-- Helps farmers make informed decisions on crop selling.
+## Key Features
-### Weather Forecast
-- Location-based weather forecasts and alerts to prevent crop damage and plan irrigation.
+### Multi-Language Support
-### Crop Disease Detection
-- Upload crop images to detect diseases using machine learning models (coming soon).
-- Early diagnosis improves crop yield and reduces loss.
+* Supports regional languages: Hindi, Punjabi, Bhojpuri, Tamil, Telugu, Kannada, Awadhi
+* Uses translation mappings and text-to-speech for accessibility
+* Designed to assist farmers regardless of literacy level
-### BhashaBuddy (Language Helper)
-- Converts agricultural messages into native languages to support low-literacy farmers.
+### Daily Task Reminders
-### Chatbot (Coming Soon)
-- An intelligent chatbot for answering agricultural queries, farming techniques, and more.
+* Farmers can set reminders for tasks like irrigation, fertilization, sowing, harvesting, and pest control
+* Helps in planning and staying organized throughout the farming season
-### Government Schemes
-- Lists both men and women-centric schemes for financial assistance, insurance, and innovation.
+### Real-Time Mandi Prices
-### Map Locator (Planned)
-- Integration of location-based mandi locators and nearest agriculture centers.
-
-KrishiMitra/
-
-├── assets
-
-├── data/
+* Provides current market prices for major crops such as rice, wheat, pulses, vegetables, and fruits
+* Location-based pricing helps farmers decide where and when to sell
-├── modules/
+### Weather Forecasts
-├── krishimitra_app.py
+* Fetches weather information based on the user's region
+* Assists in making better decisions about irrigation, pesticide application, and harvesting
-├── README.md
+### AI Chatbot Assistance
- Tech Stack
-Frontend: Streamlit
+* Integrated chatbot using Groq’s LLaMA3 model
+* Offers crisp, relevant answers to farming-related queries
+* Works entirely offline except for chatbot queries that require internet access
-Backend: Python
+---
-Libraries:
+## How to Run
-gTTS for text-to-speech
+1. Install the required packages:
-Pillow for image processing
+ ```bash
+ pip install groq gtts pygame
+ ```
-requests, geopy for weather/location
+2. Set up your files:
-OpenCV and ML models for disease detection (future)
+ * `KrishiMitra.py`: Main application
+ * `chatbot.py`: Handles chatbot responses using Groq
- Getting Started
-Prerequisites
-Python 3.8+
+3. Run the main application:
-Install dependencies:
+ ```bash
+ python KrishiMitra.py
+ ```
-bash
-Copy
-Edit
-pip install -r requirements.txt
-Run the App
-bash
-Copy
-Edit
-streamlit run krishimitra_app.py
-Government Schemes Included
-PM-KISAN, PMFBY, KCC, Soil Health Card, eNAM, RKVY, PUSA Krishi
+---
-Women-specific schemes: Mahila Kisan Sashaktikaran, Annapurna Scheme, and more.
+## Folder Structure
- Future Improvements
-Chatbot with NLP
-
-Smart crop recommendation system
+```
+KrishiMitra/
+├── KrishiMitra.py # Main UI application
+├── chatbot.py # Chatbot handler
+├── requirements.txt # Optional: list of dependencies
+├── README.md # This file
+```
-Automated SMS alerts
+---
-Real-time news and alerts for farmers
+## Future Enhancements
- Contributing
-Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
+* Add image-based crop disease detection
+* Offline voice-to-text integration
+* Integration with government scheme databases
+* Smart irrigation recommendations using weather data
- License
-This project is licensed under the MIT License. See the LICENSE file for details.
+---
- Acknowledgements
-NumFOCUS and Open Science Labs
+## License
-Indian Council of Agricultural Research (ICAR)
+This project is for educational purposes. You're free to use, modify, and distribute it with proper attribution.
-Government of India Open Data APIs
+---
-Farmers who inspire innovation every day 🌾
-Made with love for our Farmer!!
+Let me know if you'd like to export this as a downloadable `README.md` file or host it on GitHub.
diff --git a/chatbot.py b/chatbot.py
new file mode 100644
index 00000000..c5ef4b1a
--- /dev/null
+++ b/chatbot.py
@@ -0,0 +1,27 @@
+# chatbot.py
+from groq import Groq
+
+def ask_groq(prompt, api_key):
+ client = Groq(api_key=api_key)
+
+ try:
+ response = client.chat.completions.create(
+ model="llama3-8b-8192",
+ messages=[
+ {
+ "role": "system",
+ "content": (
+ "You are KrishiMitra, an AI assistant who only answers farming-related questions. "
+ "Keep your replies short, helpful, and easy to understand — suitable for farmers in India. "
+ "Avoid technical jargon unless needed."
+ )
+ },
+ {
+ "role": "user",
+ "content": prompt
+ }
+ ]
+ )
+ return response.choices[0].message.content.strip()
+ except Exception as e:
+ return f"❌ Error: {e}"
diff --git a/python_file b/python_file
deleted file mode 100644
index 1d49750a..00000000
--- a/python_file
+++ /dev/null
@@ -1,175 +0,0 @@
-import streamlit as st
-from datetime import datetime
-from gtts import gTTS
-import base64
-import os
-
-# ------------------ Utility Function ------------------
-def play_audio(text, lang_code='en'):
- tts = gTTS(text=text, lang=lang_code)
- filename = "temp_audio.mp3"
- tts.save(filename)
- with open(filename, "rb") as audio_file:
- audio_bytes = audio_file.read()
- b64 = base64.b64encode(audio_bytes).decode()
- audio_html = f''
- st.markdown(audio_html, unsafe_allow_html=True)
- os.remove(filename)
-
-# ------------------ Language Data ------------------
-LANGUAGE_DATA = {
- "English": {
- "welcome": "🌾 Welcome to KrishiMitra!",
- "fertilizer": "🌱 Fertilizer Recommendation",
- "loan": "🏦 Loan/Subsidy Checker",
- "weather_alert": "🌦️ Weather Alerts",
- "crop_calendar": "📅 Crop Calendar",
- "tts_lang": "en"
- },
- "Hindi": {
- "welcome": "🌾 कृषि मित्र में आपका स्वागत है!",
- "fertilizer": "🌱 उर्वरक सिफारिश",
- "loan": "🏦 ऋण/सब्सिडी जांच",
- "weather_alert": "🌦️ मौसम अलर्ट",
- "crop_calendar": "📅 फसल कैलेंडर",
- "tts_lang": "hi"
- },
- "Bhojpuri": {
- "welcome": "🌾 कृषिमित्र में रउआ स्वागत बा!",
- "fertilizer": "🌱 खाद सिफारिश",
- "loan": "🏦 कर्ज/सब्सिडी जांच",
- "weather_alert": "🌦️ मौसम चेतावनी",
- "crop_calendar": "📅 फसल कैलेंडर",
- "tts_lang": "hi"
- },
- "Punjabi": {
- "welcome": "🌾 ਕ੍ਰਿਸ਼ੀ ਮਿਤਰ ਵਿੱਚ ਤੁਹਾਡਾ ਸੁਆਗਤ ਹੈ!",
- "fertilizer": "🌱 ਖਾਦ ਸਿਫਾਰਸ਼",
- "loan": "🏦 ਕਰਜ਼ਾ ਜਾਂ ਸਬਸਿਡੀ ਚੈੱਕਰ",
- "weather_alert": "🌦️ ਮੌਸਮ ਚੇਤਾਵਨੀ",
- "crop_calendar": "📅 ਫਸਲ ਕੈਲੰਡਰ",
- "tts_lang": "pa"
- },
- "Tamil": {
- "welcome": "🌾 கிருஷிமித்ராவிற்கு வரவேற்கிறோம்!",
- "fertilizer": "🌱 உர பரிந்துரை",
- "loan": "🏦 கடன்/தொகை சரிபார்ப்பு",
- "weather_alert": "🌦️ வானிலை எச்சரிக்கை",
- "crop_calendar": "📅 பயிர் நாட்காட்டி",
- "tts_lang": "ta"
- },
- "Telugu": {
- "welcome": "🌾 కృషిమిత్రా కు స్వాగతం!",
- "fertilizer": "🌱 ఎరువు సిఫార్సు",
- "loan": "🏦 రుణం/సబ్సిడీ తనిఖీ",
- "weather_alert": "🌦️ వాతావరణ హెచ్చరికలు",
- "crop_calendar": "📅 పంట క్యాలెండర్",
- "tts_lang": "te"
- },
- "Kannada": {
- "welcome": "🌾 ಕೃಷಿ ಮಿತ್ರಕ್ಕೆ ಸ್ವಾಗತ!",
- "fertilizer": "🌱 ರಸಗೊಬ್ಬರ ಶಿಫಾರಸು",
- "loan": "🏦 ಸಾಲ/ಸಬ್ಸಿಡಿ ತಪಾಸಣೆ",
- "weather_alert": "🌦️ ಹವಾಮಾನ ಎಚ್ಚರಿಕೆ",
- "crop_calendar": "📅 ಬೆಳೆ ದಿನದರ್ಶಿ",
- "tts_lang": "kn"
- },
- "Awadhi": {
- "welcome": "🌾 कृषिमित्र मा तोहार स्वागत बा!",
- "fertilizer": "🌱 खाद सिफारिश",
- "loan": "🏦 कर्ज/सब्सिडी जांच",
- "weather_alert": "🌦️ मौसम चेतावनी",
- "crop_calendar": "📅 फसल कैलेंडर",
- "tts_lang": "hi"
- }
-}
-
-# ------------------ Sidebar for Language ------------------
-st.sidebar.title("🌐 Select Language")
-language = st.sidebar.selectbox("Choose your preferred language:", list(LANGUAGE_DATA.keys()))
-lang_content = LANGUAGE_DATA[language]
-
-# ------------------ Main UI ------------------
-st.title(lang_content["welcome"])
-
-if st.button("🔊 Read Aloud"):
- play_audio(lang_content["welcome"], lang_content["tts_lang"])
-
-
-
-# ------------------ Fertilizer Recommendation ------------------
-st.header(lang_content["fertilizer"])
-crop = st.selectbox("Select Crop", ["Wheat", "Rice", "Maize", "Cereals", "Sugarcane", "Potato", "Tomato"])
-soil = st.selectbox("Soil Type", ["Black", "Red", "Sandy", "Brown"])
-if st.button("Get Recommendation"):
- rec = f"For {crop} in {soil} soil, use NPK 20:20:0 at 50kg/acre."
- st.success(rec)
- if st.button("🔊 Listen Recommendation"):
- play_audio(rec, lang_content["tts_lang"])
-
-# ------------------ Loan/Subsidy Checker ------------------
-st.header(lang_content["loan"])
-age = st.number_input("Enter your age", min_value=18, max_value=80)
-holding = st.selectbox("Land holding (acres)", ["<1", "1-5", ">5"])
-if st.button("Check Eligibility"):
- eligible = "You are eligible for KCC and PM-KISAN schemes."
- st.info(eligible)
- if st.button("🔊 Listen Eligibility"):
- play_audio(eligible, lang_content["tts_lang"])
-
-# ------------------ Weather Alerts ------------------
-st.header(lang_content["weather_alert"])
-today = datetime.now().strftime("%d-%m-%Y")
-st.write(f"Today's Date: {today}")
-st.warning("⚠️ Heavy Rain Expected in your region today.")
-
-# ------------------ Crop Calendar ------------------
-st.header(lang_content["crop_calendar"])
-season = st.selectbox("Choose Season", ["Rabi", "Kharif", "Zaid"])
-if st.button("Show Calendar"):
- calendar = f"For {season}, sow Wheat, Mustard, and Barley."
- st.success(calendar)
- if st.button("🔊 Listen Calendar"):
- play_audio(calendar, lang_content["tts_lang"])
-
-
-
-# ------------------ Mandi Prices ------------------
-st.subheader(['Mandi_Data'])
-mandi_data ={
- "wheat": "₹2200/qtl",
- "rice": "₹1800/qtl",
- "mustard": "₹5500/qtl",
- "maize": "₹1700/qtl",
- "barley": "₹1600/qtl",
- "soybean": "₹4800/qtl",
- "cotton": "₹6600/qtl",
- "groundnut": "₹5500/qtl",
- "sugarcane": "₹340/qtl",
- "potato": "₹1200/qtl",
- "onion": "₹900/qtl",
- "tomato": "₹1100/qtl",
- "bajra": "₹2150/qtl",
- "jowar": "₹2738/qtl",
- "urad dal": "₹6600/qtl",
- "moong dal": "₹7275/qtl",
- "chana": "₹5400/qtl",
- "masoor dal": "₹6000/qtl",
- "banana": "₹1500/qtl",
- "apple": "₹3000/qtl",
- "brinjal": "₹900/qtl",
- "carrot": "₹1100/qtl",
- "cabbage": "₹850/qtl",
- "peas": "₹1400/qtl"
-
-}
-st.table(mandi_data)
-# ------------------ Footer ------------------
-st.markdown("---")
-st.markdown("Made with ❤️ for Indian Farmers - KrishiMitra")
-
-
-
-
-
-
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 00000000..e69de29b
diff --git a/weather.py b/weather.py
new file mode 100644
index 00000000..bb0087cc
--- /dev/null
+++ b/weather.py
@@ -0,0 +1,30 @@
+# weather.py
+import requests
+
+def get_weather(city, api_key):
+ url = "http://api.openweathermap.org/data/2.5/weather"
+ params = {
+ "q": city,
+ "appid": api_key,
+ "units": "metric"
+ }
+
+ try:
+ response = requests.get(url, params=params)
+ print("DEBUG: Status Code =", response.status_code) # 👈 Add this
+ print("DEBUG: Response Text =", response.text) # 👈 And this
+
+ if response.status_code == 200:
+ data = response.json()
+ return {
+ "description": data["weather"][0]["description"],
+ "temp": data["main"]["temp"],
+ "feels_like": data["main"]["feels_like"],
+ "humidity": data["main"]["humidity"],
+ "wind_speed": data["wind"]["speed"]
+ }
+ else:
+ return None
+ except Exception as e:
+ print("DEBUG: Exception occurred:", e) # 👈 Add this
+ return None