Jeff28 commited on
Commit
e3e3e6b
·
verified ·
1 Parent(s): 2e01d6d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -26,8 +26,8 @@ def preprocess_image(image, target_size=(224, 224)):
26
  return img_array
27
 
28
  # ===== Disease Label Mappings =====
29
- # The five disease labels you are focusing on.
30
- disease_labels = {
31
  0: "Tomato Bacterial Spot",
32
  1: "Tomato Early Blight",
33
  2: "Tomato Late Blight",
@@ -35,18 +35,27 @@ disease_labels = {
35
  4: "Tomato Yellow Leaf Curl Virus"
36
  }
37
 
 
 
 
 
 
 
 
 
 
38
  # ===== Prediction Functions =====
39
  def predict_model_a(image):
40
  img = preprocess_image(image)
41
  pred = model_a.predict(img)
42
  predicted_class = np.argmax(pred)
43
- return disease_labels.get(predicted_class, "Unknown result")
44
 
45
  def predict_model_b(image):
46
  img = preprocess_image(image)
47
  pred = model_b.predict(img)
48
  predicted_class = np.argmax(pred)
49
- return disease_labels.get(predicted_class, "Unknown result")
50
 
51
  def predict_classifier(image):
52
  img = preprocess_image(image)
@@ -87,7 +96,7 @@ def call_openassistant(prompt):
87
 
88
  # ===== AI Assistant Functions =====
89
  def ai_assistant_v1(image, prediction):
90
- # Use Llama 2-7B Chat (Model A versions)
91
  if "Tomato" not in prediction:
92
  prompt = (
93
  "You are an agricultural advisor. The tomato crop appears healthy. "
@@ -101,7 +110,7 @@ def ai_assistant_v1(image, prediction):
101
  return call_llama2(prompt)
102
 
103
  def ai_assistant_v2(image, prediction):
104
- # Use OpenAssistant (Model B versions)
105
  if "Tomato" not in prediction:
106
  prompt = (
107
  "You are an agricultural advisor. The tomato crop appears healthy. "
 
26
  return img_array
27
 
28
  # ===== Disease Label Mappings =====
29
+ # Model A labels (for example)
30
+ disease_labels_a = {
31
  0: "Tomato Bacterial Spot",
32
  1: "Tomato Early Blight",
33
  2: "Tomato Late Blight",
 
35
  4: "Tomato Yellow Leaf Curl Virus"
36
  }
37
 
38
+ # Model B labels (based on your training dataset)
39
+ disease_labels_b = {
40
+ 0: "Tomato___Target_Spot",
41
+ 1: "Tomato___Bacterial_spot",
42
+ 2: "Tomato___Early_blight",
43
+ 3: "Tomato___healthy",
44
+ 4: "Tomato___Late_blight"
45
+ }
46
+
47
  # ===== Prediction Functions =====
48
  def predict_model_a(image):
49
  img = preprocess_image(image)
50
  pred = model_a.predict(img)
51
  predicted_class = np.argmax(pred)
52
+ return disease_labels_a.get(predicted_class, "Unknown result")
53
 
54
  def predict_model_b(image):
55
  img = preprocess_image(image)
56
  pred = model_b.predict(img)
57
  predicted_class = np.argmax(pred)
58
+ return disease_labels_b.get(predicted_class, "Unknown result")
59
 
60
  def predict_classifier(image):
61
  img = preprocess_image(image)
 
96
 
97
  # ===== AI Assistant Functions =====
98
  def ai_assistant_v1(image, prediction):
99
+ # Use Llama 2-7B Chat (for Model A versions)
100
  if "Tomato" not in prediction:
101
  prompt = (
102
  "You are an agricultural advisor. The tomato crop appears healthy. "
 
110
  return call_llama2(prompt)
111
 
112
  def ai_assistant_v2(image, prediction):
113
+ # Use OpenAssistant (for Model B versions)
114
  if "Tomato" not in prediction:
115
  prompt = (
116
  "You are an agricultural advisor. The tomato crop appears healthy. "