Spaces:
Runtime error
Runtime error
percentage update app.py
Browse filesreformatted the percentage breakdown to look neater
app.py
CHANGED
@@ -34,7 +34,13 @@ def predict(image):
|
|
34 |
# Calculate the percentage breakdown of predicted diseases
|
35 |
percentage_breakdown = {disease: round(float(probability[0, index]) * 100, 2) for index, disease in enumerate(model.config.label2id)}
|
36 |
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
# Gradio interface setup with separate boxes for Leaf Type, Identified Disease, and Percentage Breakdown
|
40 |
interface = gr.Interface(
|
@@ -43,10 +49,10 @@ interface = gr.Interface(
|
|
43 |
outputs=[
|
44 |
gr.Textbox(label="Leaf Type:"),
|
45 |
gr.Textbox(label="Identified Disease:"),
|
46 |
-
gr.
|
47 |
],
|
48 |
title="Plant Disease Identifier",
|
49 |
description="Quick Tip: If the image results do not match, consider taking a picture of the leaf against a clean white background for improved accuracy and better identification of plant diseases."
|
50 |
)
|
51 |
|
52 |
-
interface.launch(debug=True) # Start server and launch the UI
|
|
|
34 |
# Calculate the percentage breakdown of predicted diseases
|
35 |
percentage_breakdown = {disease: round(float(probability[0, index]) * 100, 2) for index, disease in enumerate(model.config.label2id)}
|
36 |
|
37 |
+
# Sort the percentage breakdown dictionary by values in descending order
|
38 |
+
sorted_percentage = dict(sorted(percentage_breakdown.items(), key=lambda item: item[1], reverse=True))
|
39 |
+
|
40 |
+
# Format the percentage breakdown for printing
|
41 |
+
formatted_percentage = '\n'.join([f"{disease.replace('___', ' Leaf - ').replace('_', ' ').capitalize()}: {percentage}%" for disease, percentage in sorted_percentage.items()])
|
42 |
+
|
43 |
+
return leaf_category.capitalize(), disease_name.replace('_', ' ').capitalize(), formatted_percentage
|
44 |
|
45 |
# Gradio interface setup with separate boxes for Leaf Type, Identified Disease, and Percentage Breakdown
|
46 |
interface = gr.Interface(
|
|
|
49 |
outputs=[
|
50 |
gr.Textbox(label="Leaf Type:"),
|
51 |
gr.Textbox(label="Identified Disease:"),
|
52 |
+
gr.Textbox(label="Percentage Breakdown:")
|
53 |
],
|
54 |
title="Plant Disease Identifier",
|
55 |
description="Quick Tip: If the image results do not match, consider taking a picture of the leaf against a clean white background for improved accuracy and better identification of plant diseases."
|
56 |
)
|
57 |
|
58 |
+
interface.launch(debug=True) # Start server and launch the UI
|