sikeaditya commited on
Commit
d1e172b
·
verified ·
1 Parent(s): db96a98

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -8
app.py CHANGED
@@ -66,9 +66,12 @@ TRANSLATIONS = {
66
 
67
  def translate_text(text):
68
  if st.session_state.get("language", "English") == "Marathi":
 
 
69
  return TRANSLATIONS.get(text, text)
70
  return text
71
 
 
72
  # Custom CSS for styling
73
  # Update custom CSS
74
  custom_css = """
@@ -183,7 +186,6 @@ def get_plant_info(disease, plant_type="Unknown"):
183
  prompt = f"""
184
  Disease Name: {disease}
185
  Plant Type: {plant_type}
186
-
187
  Explain this disease in a very simple way for a farmer. Include:
188
  - Symptoms
189
  - Causes
@@ -192,6 +194,7 @@ def get_plant_info(disease, plant_type="Unknown"):
192
  - Treatment & Prevention
193
  """
194
  try:
 
195
  API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-3.2-1B-Instruct/v1/chat/completions"
196
  headers = {"Authorization": f"Bearer {os.getenv('HUGGINGFACE_API_TOKEN')}"}
197
  try:
@@ -201,7 +204,8 @@ def get_plant_info(disease, plant_type="Unknown"):
201
  {"role": "user", "content": prompt},
202
  ]
203
  }
204
- response = requests.post(API_URL, headers=headers, json=data)
 
205
  response.raise_for_status()
206
  print("Response:", data)
207
  except requests.exceptions.HTTPError as http_err:
@@ -221,8 +225,8 @@ def get_web_pesticide_info(disease, plant_type="Unknown"):
221
  query = f"site:agrowon.esakal.com {disease} in {plant_type}"
222
  url = "https://www.googleapis.com/customsearch/v1"
223
  params = {
224
- "key": os.getenv("GOOGLE_API_KEY"),
225
- "cx": os.getenv("GOOGLE_CX"),
226
  "q": query,
227
  "num": 3
228
  }
@@ -243,8 +247,8 @@ def get_web_pesticide_info(disease, plant_type="Unknown"):
243
  def get_more_web_info(query):
244
  url = "https://www.googleapis.com/customsearch/v1"
245
  params = {
246
- "key": os.getenv("GOOGLE_API_KEY"),
247
- "cx": os.getenv("GOOGLE_CX"),
248
  "q": query,
249
  "num": 3
250
  }
@@ -289,16 +293,25 @@ def translate_text(text):
289
 
290
 
291
  def main():
 
 
 
 
292
  st.sidebar.title(translate_text("Settings"))
293
  st.sidebar.info(translate_text("Choose language and plant type, then upload an image to classify the disease."))
294
- language_option = st.sidebar.radio(translate_text("Language"), options=["English", "Marathi"], index=0)
295
- st.session_state.language = language_option
 
 
 
 
296
  plant_type = st.sidebar.selectbox(translate_text("Select Plant Type"), options=['sugarcane', 'maize', 'cotton', 'rice', 'wheat'])
297
  uploaded_file = st.sidebar.file_uploader(
298
  translate_text("Upload a plant image..."),
299
  type=["jpg", "jpeg", "png"],
300
  help=translate_text("Select an image of your plant to detect diseases")
301
  )
 
302
  st.title(translate_text("Krushi Mitra"))
303
  st.write(translate_text("Plant Disease Classification and Pesticide Recommendation.\n\nUpload an image, select plant type, and click on Classify."))
304
 
 
66
 
67
  def translate_text(text):
68
  if st.session_state.get("language", "English") == "Marathi":
69
+ if text == "Krushi Mitra":
70
+ return "कृषी मित्र"
71
  return TRANSLATIONS.get(text, text)
72
  return text
73
 
74
+
75
  # Custom CSS for styling
76
  # Update custom CSS
77
  custom_css = """
 
186
  prompt = f"""
187
  Disease Name: {disease}
188
  Plant Type: {plant_type}
 
189
  Explain this disease in a very simple way for a farmer. Include:
190
  - Symptoms
191
  - Causes
 
194
  - Treatment & Prevention
195
  """
196
  try:
197
+ # API_URL = "http://192.168.56.1:1234/v1/chat/completions"
198
  API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-3.2-1B-Instruct/v1/chat/completions"
199
  headers = {"Authorization": f"Bearer {os.getenv('HUGGINGFACE_API_TOKEN')}"}
200
  try:
 
204
  {"role": "user", "content": prompt},
205
  ]
206
  }
207
+ # response = requests.post(API_URL, headers=headers, json=data)
208
+ response = requests.post(API_URL, json=data)
209
  response.raise_for_status()
210
  print("Response:", data)
211
  except requests.exceptions.HTTPError as http_err:
 
225
  query = f"site:agrowon.esakal.com {disease} in {plant_type}"
226
  url = "https://www.googleapis.com/customsearch/v1"
227
  params = {
228
+ "key": "AIzaSyCp9j5OGZb5hlykMIAJhbDII3IHYJWCrnQ",
229
+ "cx": "41b10936a10424ac2",
230
  "q": query,
231
  "num": 3
232
  }
 
247
  def get_more_web_info(query):
248
  url = "https://www.googleapis.com/customsearch/v1"
249
  params = {
250
+ "key": "AIzaSyCp9j5OGZb5hlykMIAJhbDII3IHYJWCrnQ",
251
+ "cx": "41b10936a10424ac2",
252
  "q": query,
253
  "num": 3
254
  }
 
293
 
294
 
295
  def main():
296
+ # Initialize language in session state if not present
297
+ if "language" not in st.session_state:
298
+ st.session_state.language = "English"
299
+
300
  st.sidebar.title(translate_text("Settings"))
301
  st.sidebar.info(translate_text("Choose language and plant type, then upload an image to classify the disease."))
302
+
303
+ # Update language state only when radio button changes
304
+ new_language = st.sidebar.radio(translate_text("Language"), options=["English", "Marathi"], index=["English", "Marathi"].index(st.session_state.language))
305
+ if new_language != st.session_state.language:
306
+ st.session_state.language = new_language
307
+
308
  plant_type = st.sidebar.selectbox(translate_text("Select Plant Type"), options=['sugarcane', 'maize', 'cotton', 'rice', 'wheat'])
309
  uploaded_file = st.sidebar.file_uploader(
310
  translate_text("Upload a plant image..."),
311
  type=["jpg", "jpeg", "png"],
312
  help=translate_text("Select an image of your plant to detect diseases")
313
  )
314
+
315
  st.title(translate_text("Krushi Mitra"))
316
  st.write(translate_text("Plant Disease Classification and Pesticide Recommendation.\n\nUpload an image, select plant type, and click on Classify."))
317