crop_prediction / app.py
Biswa000's picture
Update app.py
ca44128 verified
import gradio as gr
import joblib
import pandas as pd
# Load the trained model (make sure the model file is named correctly)
model = joblib.load('crop_recommendation_model.joblib')
def predict_crop(temperature, humidity, rainfall):
"""
Predict the recommended crop based on temperature, humidity, and rainfall.
"""
# Create a DataFrame from the input values
user_input = pd.DataFrame({
'temperature': [temperature],
'humidity': [humidity],
'rainfall': [rainfall]
})
# Make prediction
prediction = model.predict(user_input)
# Return the first (and only) prediction
return prediction[0]
# Define the Gradio interface
iface = gr.Interface(
fn=predict_crop,
inputs=[
gr.Number(label="Temperature (°C)"),
gr.Number(label="Humidity (%)"),
gr.Number(label="Rainfall (mm)")
],
outputs=gr.Textbox(label="Recommended Crop"),
title="🌾 Crop Recommendation System",
description="Enter the temperature, humidity, and rainfall to get a crop recommendation."
)
# Launch the Gradio app
if __name__ == "__main__":
iface.launch()