Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import joblib | |
| # Load the model and label encoder | |
| model = joblib.load("soil.pkl") | |
| label_encoder = joblib.load("label_encoder.pkl") | |
| def predict_crop(N, P, K, temperature, humidity, ph, rainfall): | |
| input_data = [[N, P, K, temperature, humidity, ph, rainfall]] | |
| prediction = model.predict(input_data) | |
| crop = label_encoder.inverse_transform(prediction)[0] | |
| return f"Recommended Crop: {crop}" | |
| demo = gr.Interface( | |
| fn=predict_crop, | |
| inputs=[ | |
| gr.Number(label="Nitrogen"), | |
| gr.Number(label="Phosphorus"), | |
| gr.Number(label="Potassium"), | |
| gr.Number(label="Temperature (°C)"), | |
| gr.Number(label="Humidity (%)"), | |
| gr.Number(label="pH"), | |
| gr.Number(label="Rainfall (mm)") | |
| ], | |
| outputs="text", | |
| title="Crop Recommendation System", | |
| description="Enter your soil and weather data to get a crop suggestion!" | |
| ) | |
| demo.launch(share=True) | |