Spaces:
Sleeping
Sleeping
Commit
·
1ee6962
1
Parent(s):
b1be81c
bug fix
Browse files
app.py
CHANGED
|
@@ -80,38 +80,21 @@ def create_field_mode_ui():
|
|
| 80 |
diagnosis = DIAGNOSIS_TOOL(temp_file_path)
|
| 81 |
print(f"Diagnosis received: {diagnosis}")
|
| 82 |
|
|
|
|
|
|
|
|
|
|
| 83 |
if "Could not parse" in diagnosis:
|
| 84 |
-
search_query = "
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
**Condition Identified:**
|
| 90 |
-
### Unknown
|
| 91 |
-
|
| 92 |
-
---
|
| 93 |
-
|
| 94 |
-
## Suggested Remedy
|
| 95 |
-
|
| 96 |
-
{remedy}"""
|
| 97 |
-
|
| 98 |
-
# Default to comic relief
|
| 99 |
-
search_query = "Wetin My Eye See So?"
|
| 100 |
-
report_title = diagnosis # Default title
|
| 101 |
|
| 102 |
-
healthy_keywords = ["Healthy", "harvested", "drying"]
|
| 103 |
-
if any(keyword in diagnosis for keyword in healthy_keywords):
|
| 104 |
-
search_query = "Better Ways to Enjoy Your Healthy Corn (Maize)"
|
| 105 |
-
report_title = "Healthy Maize Plant"
|
| 106 |
-
elif "phosphorus deficiency" in diagnosis.lower():
|
| 107 |
-
search_query = "How You Fit Solve Phosphorus Problem for Your Corn (Maize)"
|
| 108 |
-
report_title = "Phosphorus Deficiency"
|
| 109 |
-
|
| 110 |
results = KB.search(search_query)
|
| 111 |
|
| 112 |
if not results:
|
| 113 |
# Fallback to comic relief if no specific remedy is found
|
| 114 |
-
results = KB.search("
|
| 115 |
remedy = results[0]['content'] if results else "I couldn't find a specific remedy, and I'm out of jokes."
|
| 116 |
else:
|
| 117 |
remedy = results[0]['content']
|
|
@@ -368,11 +351,18 @@ def create_kb_management_ui():
|
|
| 368 |
def rebuild_kb():
|
| 369 |
yield "Rebuilding knowledge base..."
|
| 370 |
try:
|
| 371 |
-
docs = {
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 376 |
KB.create_initial_index(docs)
|
| 377 |
yield "Knowledge base rebuilt successfully."
|
| 378 |
except Exception as e:
|
|
|
|
| 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']
|
|
|
|
| 351 |
def rebuild_kb():
|
| 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:
|