Vinit710 commited on
Commit
fbf6023
·
verified ·
1 Parent(s): 41d8f20

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  import numpy as np
3
  import tensorflow as tf
4
  import joblib
5
- import sklearn # Ensure scikit-learn is installed
6
 
7
  # Load the saved model and label encoder
8
  model = tf.keras.models.load_model("crop_recommendation_model.h5")
@@ -18,19 +18,19 @@ def predict_crop(N, P, K, temperature, humidity, ph, rainfall):
18
  predicted_crop = label_encoder.inverse_transform([pred_class])[0]
19
  return predicted_crop
20
 
21
- # Define Gradio Interface
22
  iface = gr.Interface(
23
  fn=predict_crop,
24
  inputs=[
25
- gr.inputs.Number(label="Nitrogen (N)"),
26
- gr.inputs.Number(label="Phosphorous (P)"),
27
- gr.inputs.Number(label="Potassium (K)"),
28
- gr.inputs.Number(label="Temperature (°C)"),
29
- gr.inputs.Number(label="Humidity (%)"),
30
- gr.inputs.Number(label="pH"),
31
- gr.inputs.Number(label="Rainfall (mm)")
32
  ],
33
- outputs=gr.outputs.Textbox(label="Recommended Crop"),
34
  title="Crop Recommendation System",
35
  description="Enter soil and climate parameters to get the recommended crop."
36
  )
 
2
  import numpy as np
3
  import tensorflow as tf
4
  import joblib
5
+ import sklearn # Required for unpickling label_encoder
6
 
7
  # Load the saved model and label encoder
8
  model = tf.keras.models.load_model("crop_recommendation_model.h5")
 
18
  predicted_crop = label_encoder.inverse_transform([pred_class])[0]
19
  return predicted_crop
20
 
21
+ # Define Gradio Interface using the updated API
22
  iface = gr.Interface(
23
  fn=predict_crop,
24
  inputs=[
25
+ gr.Number(label="Nitrogen (N)"),
26
+ gr.Number(label="Phosphorous (P)"),
27
+ gr.Number(label="Potassium (K)"),
28
+ gr.Number(label="Temperature (°C)"),
29
+ gr.Number(label="Humidity (%)"),
30
+ gr.Number(label="pH"),
31
+ gr.Number(label="Rainfall (mm)")
32
  ],
33
+ outputs=gr.Textbox(label="Recommended Crop"),
34
  title="Crop Recommendation System",
35
  description="Enter soil and climate parameters to get the recommended crop."
36
  )