bhanusAI commited on
Commit
660bb15
·
verified ·
1 Parent(s): 509133e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -28
app.py CHANGED
@@ -6,7 +6,7 @@ import cv2
6
  import json
7
  import os
8
 
9
- def analyse(img, plant_type):
10
  # Load label_disease.json
11
  with open('data/label_disease.json', 'r') as f:
12
  label_disease = json.load(f)
@@ -33,32 +33,16 @@ def analyse(img, plant_type):
33
  y_pred = dnn_model.predict(process_img)
34
  y_pred = y_pred[0]
35
 
36
- # Identify plant-specific predictions
37
- plant_label_ids = plant_label_disease[plant_type.lower()]
38
- plant_predicted_id = plant_label_ids[0]
39
- for disease in plant_label_ids:
40
- if y_pred[disease] > y_pred[plant_predicted_id]:
41
- plant_predicted_id = disease
42
-
43
- # Determine overall prediction
44
  overall_predicted_id = int(np.argmax(y_pred))
45
  overall_predicted_name = label_disease[str(overall_predicted_id)]
46
  overall_predicted_confidence = float(y_pred[overall_predicted_id])
47
 
48
- # Determine plant-specific prediction
49
- plant_predicted_name = label_disease[str(plant_predicted_id)]
50
- plant_predicted_confidence = float(y_pred[plant_predicted_id])
51
-
52
  # Determine health status
53
- is_plant_specific_healthy = "healthy" in plant_predicted_name.lower()
54
  is_overall_healthy = "healthy" in overall_predicted_name.lower()
55
 
56
  # Return results as a JSON object
57
  result = {
58
- "plant_specific_prediction_id": plant_predicted_id,
59
- "plant_specific_prediction_name": plant_predicted_name,
60
- "plant_specific_confidence": plant_predicted_confidence,
61
- "is_plant_specific_healthy": is_plant_specific_healthy,
62
  "overall_prediction_id": overall_predicted_id,
63
  "overall_prediction_name": overall_predicted_name,
64
  "overall_confidence": overall_predicted_confidence,
@@ -70,17 +54,11 @@ def analyse(img, plant_type):
70
  # Build the Gradio Blocks interface
71
  with gr.Blocks() as demo:
72
  gr.Markdown("## Plant Disease Detection")
73
- gr.Markdown("Upload an image of a plant leaf and select the plant type to detect diseases.")
74
 
75
  with gr.Row():
76
- with gr.Column():
77
- input_image = gr.Image(label="Upload Image", type="numpy")
78
- plant_type = gr.Radio(
79
- ["Apple", "Blueberry", "Cherry", "Corn", "Grape", "Orange", "Peach",
80
- "Pepper", "Potato", "Raspberry", "Soybean", "Squash", "Strawberry", "Tomato"],
81
- label="Plant Type"
82
- )
83
- submit = gr.Button("Analyze")
84
 
85
  with gr.Column():
86
  result_json = gr.JSON(label="Analysis Result")
@@ -95,7 +73,7 @@ with gr.Blocks() as demo:
95
  )
96
 
97
  # Define interaction
98
- submit.click(fn=analyse, inputs=[input_image, plant_type], outputs=result_json)
99
 
100
  # Launch the application
101
  demo.launch(share=True, show_error=True)
 
6
  import json
7
  import os
8
 
9
+ def analyse(img):
10
  # Load label_disease.json
11
  with open('data/label_disease.json', 'r') as f:
12
  label_disease = json.load(f)
 
33
  y_pred = dnn_model.predict(process_img)
34
  y_pred = y_pred[0]
35
 
36
+ # Identify overall prediction
 
 
 
 
 
 
 
37
  overall_predicted_id = int(np.argmax(y_pred))
38
  overall_predicted_name = label_disease[str(overall_predicted_id)]
39
  overall_predicted_confidence = float(y_pred[overall_predicted_id])
40
 
 
 
 
 
41
  # Determine health status
 
42
  is_overall_healthy = "healthy" in overall_predicted_name.lower()
43
 
44
  # Return results as a JSON object
45
  result = {
 
 
 
 
46
  "overall_prediction_id": overall_predicted_id,
47
  "overall_prediction_name": overall_predicted_name,
48
  "overall_confidence": overall_predicted_confidence,
 
54
  # Build the Gradio Blocks interface
55
  with gr.Blocks() as demo:
56
  gr.Markdown("## Plant Disease Detection")
57
+ gr.Markdown("Upload an image of a plant leaf to detect diseases.")
58
 
59
  with gr.Row():
60
+ input_image = gr.Image(label="Upload Image", type="numpy")
61
+ submit = gr.Button("Analyze")
 
 
 
 
 
 
62
 
63
  with gr.Column():
64
  result_json = gr.JSON(label="Analysis Result")
 
73
  )
74
 
75
  # Define interaction
76
+ submit.click(fn=analyse, inputs=[input_image], outputs=result_json)
77
 
78
  # Launch the application
79
  demo.launch(share=True, show_error=True)