iamomtiwari commited on
Commit
c2cea5f
·
verified ·
1 Parent(s): 94ffad8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -25
app.py CHANGED
@@ -1,32 +1,26 @@
1
- import gradio as gr
2
- import torch
3
- from transformers import ViTForImageClassification, ViTFeatureExtractor
4
- from PIL import Image
5
-
6
- # Load model and feature extractor
7
- model = ViTForImageClassification.from_pretrained("iamomtiwari/VITPEST")
8
- feature_extractor = ViTFeatureExtractor.from_pretrained("iamomtiwari/VITPEST")
9
-
10
  # Define class labels and treatment advice with a numeric index
11
  class_labels = {
12
- 1: {"label": "Corn___Common_Rust", "treatment": "Apply fungicides as soon as symptoms are noticed. Practice crop rotation and remove infected plants."},
13
- 2: {"label": "Corn___Gray_Leaf_Spot", "treatment": "Rotate crops to non-host plants, apply resistant varieties, and use fungicides as needed."},
14
- 3: {"label": "Corn___Healthy", "treatment": "Continue good agricultural practices: ensure proper irrigation, nutrient supply, and monitor for pests."},
15
- 4: {"label": "Corn___Northern_Leaf_Blight", "treatment": "Remove and destroy infected plant debris, apply fungicides, and rotate crops."},
16
- 5: {"label": "Rice___Brown_Spot", "treatment": "Use resistant varieties, improve field drainage, and apply fungicides if necessary."},
17
- 6: {"label": "Rice___Healthy", "treatment": "Maintain proper irrigation, fertilization, and pest control measures."},
18
- 7: {"label": "Rice___Leaf_Blast", "treatment": "Use resistant varieties, apply fungicides during high-risk periods, and practice good field management."},
19
- 8: {"label": "Rice___Neck_Blast", "treatment": "Plant resistant varieties, improve nutrient management, and apply fungicides if symptoms appear."},
20
- 9: {"label": "Wheat___Brown_Rust", "treatment": "Apply fungicides and practice crop rotation with non-host crops."},
21
- 10: {"label": "Wheat___Healthy", "treatment": "Continue with good management practices, including proper fertilization and weed control."},
22
- 11: {"label": "Wheat___Yellow_Rust", "treatment": "Use resistant varieties, apply fungicides, and rotate crops."},
23
- 12: {"label": "Sugarcane__Red_Rot", "treatment": "Plant resistant varieties and ensure good drainage."},
24
- 13: {"label": "Sugarcane__Healthy", "treatment": "Maintain healthy soil conditions and proper irrigation."},
25
- 14: {"label": "Sugarcane__Bacterial Blight", "treatment": "Use disease-free planting material, practice crop rotation, and destroy infected plants."}
 
 
 
26
  }
27
 
28
  # Mapping label indices to class labels
29
- labels_list = [class_labels[i]["label"] for i in range(1, 15)]
30
 
31
  # Inference function
32
  def predict(image):
@@ -43,4 +37,4 @@ def predict(image):
43
 
44
  # Create Gradio Interface
45
  interface = gr.Interface(fn=predict, inputs="image", outputs="text")
46
- interface.launch()
 
 
 
 
 
 
 
 
 
 
1
  # Define class labels and treatment advice with a numeric index
2
  class_labels = {
3
+ 1: {"label": "Stage Corn___Common_Rust", "treatment": "Apply fungicides as soon as symptoms are noticed. Practice crop rotation and remove infected plants."},
4
+ 2: {"label": "Stage Corn___Gray_Leaf_Spot", "treatment": "Rotate crops to non-host plants, apply resistant varieties, and use fungicides as needed."},
5
+ 3: {"label": "Stage Corn___Healthy", "treatment": "Continue good agricultural practices: ensure proper irrigation, nutrient supply, and monitor for pests."},
6
+ 4: {"label": "Stage Corn___Northern_Leaf_Blight", "treatment": "Remove and destroy infected plant debris, apply fungicides, and rotate crops."},
7
+ 5: {"label": "Stage Potato___Early_Blight", "treatment": "Apply fungicides and remove infected plant debris. Practice crop rotation to reduce disease pressure."},
8
+ 6: {"label": "Stage Potato___Healthy", "treatment": "Maintain proper irrigation and fertility practices, and monitor for pests and diseases."},
9
+ 7: {"label": "Stage Potato___Late_Blight", "treatment": "Apply fungicides, remove infected plant material, and use resistant potato varieties."},
10
+ 8: {"label": "Stage Rice___Brown_Spot", "treatment": "Use resistant varieties, improve field drainage, and apply fungicides if necessary."},
11
+ 9: {"label": "Stage Rice___Healthy", "treatment": "Maintain proper irrigation, fertilization, and pest control measures."},
12
+ 10: {"label": "Stage Rice___Leaf_Blast", "treatment": "Use resistant varieties, apply fungicides during high-risk periods, and practice good field management."},
13
+ 11: {"label": "Stage Rice___Neck_Blast", "treatment": "Plant resistant varieties, improve nutrient management, and apply fungicides if symptoms appear."},
14
+ 12: {"label": "Stage Sugarcane__Bacterial Blight", "treatment": "Use disease-free planting material, practice crop rotation, and destroy infected plants."},
15
+ 13: {"label": "Stage Sugarcane__Healthy", "treatment": "Maintain healthy soil conditions and proper irrigation."},
16
+ 14: {"label": "Stage Sugarcane__Red_Rot", "treatment": "Plant resistant varieties and ensure good drainage."},
17
+ 15: {"label": "Stage Wheat___Brown_Rust", "treatment": "Apply fungicides and practice crop rotation with non-host crops."},
18
+ 16: {"label": "Stage Wheat___Healthy", "treatment": "Continue with good management practices, including proper fertilization and weed control."},
19
+ 17: {"label": "Stage Wheat___Yellow_Rust", "treatment": "Use resistant varieties, apply fungicides, and rotate crops."}
20
  }
21
 
22
  # Mapping label indices to class labels
23
+ labels_list = [class_labels[i]["label"] for i in range(1, 18)]
24
 
25
  # Inference function
26
  def predict(image):
 
37
 
38
  # Create Gradio Interface
39
  interface = gr.Interface(fn=predict, inputs="image", outputs="text")
40
+ interface.launch()