Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 #
|
| 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.
|
| 26 |
-
gr.
|
| 27 |
-
gr.
|
| 28 |
-
gr.
|
| 29 |
-
gr.
|
| 30 |
-
gr.
|
| 31 |
-
gr.
|
| 32 |
],
|
| 33 |
-
outputs=gr.
|
| 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 |
)
|