Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import joblib
|
3 |
+
|
4 |
+
# Load the model and label encoder
|
5 |
+
model = joblib.load("soil.pkl")
|
6 |
+
label_encoder = joblib.load("label_encoder.pkl")
|
7 |
+
|
8 |
+
def predict_crop(N, P, K, temperature, humidity, ph, rainfall):
|
9 |
+
input_data = [[N, P, K, temperature, humidity, ph, rainfall]]
|
10 |
+
prediction = model.predict(input_data)
|
11 |
+
crop = label_encoder.inverse_transform(prediction)[0]
|
12 |
+
return f"Recommended Crop: {crop}"
|
13 |
+
|
14 |
+
demo = gr.Interface(
|
15 |
+
fn=predict_crop,
|
16 |
+
inputs=[
|
17 |
+
gr.Number(label="Nitrogen"),
|
18 |
+
gr.Number(label="Phosphorus"),
|
19 |
+
gr.Number(label="Potassium"),
|
20 |
+
gr.Number(label="Temperature (°C)"),
|
21 |
+
gr.Number(label="Humidity (%)"),
|
22 |
+
gr.Number(label="pH"),
|
23 |
+
gr.Number(label="Rainfall (mm)")
|
24 |
+
],
|
25 |
+
outputs="text",
|
26 |
+
title="Crop Recommendation System",
|
27 |
+
description="Enter your soil and weather data to get a crop suggestion!"
|
28 |
+
)
|
29 |
+
|
30 |
+
demo.launch()
|