sidd-harth011 commited on
Commit
d009c24
·
1 Parent(s): 6ccbed3

corrected model again

Browse files
Files changed (1) hide show
  1. app.py +14 -0
app.py CHANGED
@@ -41,6 +41,15 @@ def load_and_preprocess_image(image, target_size=(224, 224)):
41
  img_array = img_array / 255.0
42
  return img_array
43
 
 
 
 
 
 
 
 
 
 
44
  # -----------------------------
45
  # Prediction function
46
  # -----------------------------
@@ -51,6 +60,7 @@ def predict_image_class(image):
51
  predictions = interpreter.get_tensor(output_details[0]['index'])
52
  predicted_class_index = np.argmax(predictions, axis=1)[0]
53
  predicted_class_name = class_indices[str(predicted_class_index)]
 
54
  return f"Prediction: {predicted_class_name}"
55
 
56
  # -----------------------------
@@ -60,6 +70,10 @@ def grok_chatbot(user_message):
60
  payload = {
61
  "model": "openai/gpt-oss-20b",
62
  "messages": [
 
 
 
 
63
  {
64
  "role": "system",
65
  "content": "You are a helpful assistant specializing in plant disease diagnosis and treatment."
 
41
  img_array = img_array / 255.0
42
  return img_array
43
 
44
+ #-----------------------------
45
+ # Function to give disease name only
46
+ #-----------------------------
47
+
48
+ def clean_label(label: str) -> str:
49
+ if "___" in label:
50
+ label = label.split("___")[-1]
51
+ return label.replace("_", " ").title()
52
+
53
  # -----------------------------
54
  # Prediction function
55
  # -----------------------------
 
60
  predictions = interpreter.get_tensor(output_details[0]['index'])
61
  predicted_class_index = np.argmax(predictions, axis=1)[0]
62
  predicted_class_name = class_indices[str(predicted_class_index)]
63
+ predicted_class_name = clean_label(predicted_class_name)
64
  return f"Prediction: {predicted_class_name}"
65
 
66
  # -----------------------------
 
70
  payload = {
71
  "model": "openai/gpt-oss-20b",
72
  "messages": [
73
+ {
74
+ "role": "system",
75
+ "content": "if any user prompt looks wrong then reply - i can't answer that ."
76
+ },
77
  {
78
  "role": "system",
79
  "content": "You are a helpful assistant specializing in plant disease diagnosis and treatment."