surfiniaburger commited on
Commit
c31173b
·
1 Parent(s): 1ee6962
Files changed (1) hide show
  1. app.py +7 -21
app.py CHANGED
@@ -80,22 +80,16 @@ def create_field_mode_ui():
80
  diagnosis = DIAGNOSIS_TOOL(temp_file_path)
81
  print(f"Diagnosis received: {diagnosis}")
82
 
83
- # The diagnosis from the tool should ideally be one of:
84
- # "Healthy Maize Plant", "Maize Phosphorus Deficiency", or an error.
85
-
86
  if "Could not parse" in diagnosis:
87
- search_query = "Comic Relief"
88
- report_title = "Unknown Condition"
89
- else:
90
- search_query = diagnosis
91
- report_title = diagnosis
92
 
93
  results = KB.search(search_query)
94
 
95
  if not results:
96
- # Fallback to comic relief if no specific remedy is found
97
- results = KB.search("Comic Relief")
98
- remedy = results[0]['content'] if results else "I couldn't find a specific remedy, and I'm out of jokes."
99
  else:
100
  remedy = results[0]['content']
101
 
@@ -352,17 +346,9 @@ def create_kb_management_ui():
352
  yield "Rebuilding knowledge base..."
353
  try:
354
  docs = {
355
- "Healthy Maize Plant": "",
356
- "Maize Phosphorus Deficiency": "",
357
- "Comic Relief": ""
358
  }
359
- with open(os.path.join("knowledge_base_data", "healthy_maize_remedy.txt")) as f:
360
- docs["Healthy Maize Plant"] = f.read()
361
- with open(os.path.join("knowledge_base_data", "maize_phosphorus_deficiency_remedy.txt")) as f:
362
- docs["Maize Phosphorus Deficiency"] = f.read()
363
- with open(os.path.join("knowledge_base_data", "comic_relief.txt")) as f:
364
- docs["Comic Relief"] = f.read()
365
-
366
  KB.create_initial_index(docs)
367
  yield "Knowledge base rebuilt successfully."
368
  except Exception as e:
 
80
  diagnosis = DIAGNOSIS_TOOL(temp_file_path)
81
  print(f"Diagnosis received: {diagnosis}")
82
 
 
 
 
83
  if "Could not parse" in diagnosis:
84
+ return f"Sorry, I couldn't identify the condition from the image. Raw output: {diagnosis}"
85
+
86
+ search_query = diagnosis
87
+ report_title = diagnosis
 
88
 
89
  results = KB.search(search_query)
90
 
91
  if not results:
92
+ remedy = "No remedy found in the local knowledge base."
 
 
93
  else:
94
  remedy = results[0]['content']
95
 
 
346
  yield "Rebuilding knowledge base..."
347
  try:
348
  docs = {
349
+ "Healthy Maize Plant": "For a Healthy Maize Plant, ensure proper watering and sunlight. No special remedy is needed. Continue good farming practices.",
350
+ "Maize Phosphorus Deficiency": "Phosphorus deficiency in maize is characterized by stunted growth and purplish discoloration of leaves. To remedy this, apply a phosphorus-rich fertilizer like DAP (Di-Ammonium Phosphate) or bone meal to the soil. Follow package instructions for application rates."
 
351
  }
 
 
 
 
 
 
 
352
  KB.create_initial_index(docs)
353
  yield "Knowledge base rebuilt successfully."
354
  except Exception as e: