Unable to make a clear diagnosis. Please upload a sharper, close-up photo of the leaf under better lighting.
"
return msg
system_prompt = (
"You are a helpful tropical agronomist providing organic advice to smallholder farmers. "
"Based on the identified plant condition, provide a simple description and a 2-3 step treatment plan. "
"Only recommend accessible, local natural remedies like neem oil, wood ash, or removing damaged leaves. "
"Never recommend synthetic chemical pesticides. Provide everything strictly in clear, plain English. Be direct and action-oriented."
)
user_prompt = f"Plant Condition: {clean_disease_name}. Confidence: {confidence_pct}%."
formatted_prompt = f"<|im_start|>system\n{system_prompt}<|im_end|>\n<|im_start|>user\n{user_prompt}<|im_end|>\n<|im_start|>assistant\n"
if llm:
output = llm(formatted_prompt, max_tokens=350, temperature=0.2, stop=["<|im_end|>"])
ai_response = output["choices"][0]["text"].strip()
# Convert simple markdown to HTML for rendering
ai_response = ai_response.replace("\n", " ")
else:
ai_response = "Fallback Report: Model engine offline.
1. Isolate the damaged crop foliage immediately. 2. Ensure neem solution application to prevent further spread."
report_html = (
f"
"
f"
📋 Diagnostics Report
"
f"
Condition Identified:{clean_disease_name}
"
f"
Confidence Level: {confidence_pct}%
"
f""
f"
🌿 Agronomist Prescription
"
f"
{ai_response}
"
f"
"
f""
f""
f"
"
f"
"
)
return report_html
except Exception as error:
return f"
Get instant analysis and treatment advice for your crops and garden plants.
""")
with gr.Column(elem_id="image-upload-box"):
camera_input = gr.Image(label="Field Photo Input", sources=["upload", "webcam"], type="filepath")
with gr.Row():
analyze_button = gr.Button("Analyze ➔", variant="primary", elem_classes=["action-btn-primary"])
# The results will magically appear right here below the button!
output_display = gr.HTML()
gr.HTML("""
verified_user
98% Accuracy
Powered by advanced agricultural computer vision.
local_library
Local Remedies
Treatment plans curated for your specific soil and climate.
forum
Expert Support
Connect with local agronomists if a disease is detected.
""")
# Connect the button directly to the output display
analyze_button.click(
fn=process_field_analysis,
inputs=[camera_input],
outputs=[output_display]
)
if __name__ == "__main__":
demo.launch()