import streamlit as st import requests import os st.set_page_config(page_title="Agri Advisory Chatbot", page_icon="🌾", layout="centered") st.markdown("""
زراعت کے متعلق سوال کریں: فصل، کھاد، کیڑے، موسم، منڈی کی قیمتیں
""", unsafe_allow_html=True) # Set your GROQ API key here GROQ_API_KEY = st.secrets.get("GROQ_API_KEY", "your-groq-api-key") # Replace with your key or use secrets def ask_groq(prompt): url = "https://api.groq.com/openai/v1/chat/completions" headers = { "Authorization": f"Bearer {GROQ_API_KEY}", "Content-Type": "application/json" } payload = { "model": "mixtral-8x7b-32768", "messages": [ {"role": "system", "content": "You are an agricultural advisor who replies in the same language as the farmer (Urdu, Pashto, Sindhi). Give simple and useful farming advice about crop care, pest control, weather, and market rates."}, {"role": "user", "content": prompt} ] } response = requests.post(url, headers=headers, json=payload) return response.json()['choices'][0]['message']['content'] # Input section user_query = st.text_area("اپنا سوال یہاں لکھیں", placeholder="مثال: گندم کی بوائی کا بہترین وقت کیا ہے؟", height=100) if st.button("سوال پوچھیں"): if user_query.strip() != "": with st.spinner("جواب تیار ہو رہا ہے..."): try: reply = ask_groq(user_query) st.success("ماہر زرعی مشورہ:") st.markdown(f"