Acres-CR / app.py
JohanBeytell's picture
Create app.py
e4cf7c3 verified
raw
history blame
1.42 kB
import gradio as gr
import numpy as np
from sklearn.preprocessing import LabelEncoder
from xgboost import XGBClassifier
import pickle
model = pickle.load('crop_recommendation_model.pkl')
le = pickle.load('label_encoder.pkl')
def recommend_crop(nitrogen, phosphorus, potassium, temperature, humidity, ph, rainfall)
X_sample = nitrogen, phosphorus, potassium, temperature, humidity, ph, rainfall
# Predict crop recommendations
y_pred_sample = model.predict(X_sample)
# Decode the predictions and ground truth back to crop names
crops_pred = le.inverse_transform(y_pred_sample)
return crops_pred
# Create the Gradio interface
interface = gr.Interface(
fn=classify_potato_plant,
inputs=[gr.Number(label="Nitrogen - Ratio of Nitrogen in the soil"), gr.Number(label="Phosphorus - Ratio of Phosphorus in the soil"), gr.Number(label="Potassium - Ratio of Potassium in the soil"), gr.Number(label="Temperature - In degrees Celsius"), gr.Number(label="Humidity - Relative humidity in %"), gr.Number(label="pH Value - pH value of the soil"), gr.Number(label="Rainfall - Rainfall in mm")],
outputs=[gr.Textbox(label="Predicted Output"), gr.Textbox(label="Confidence Score")],
title="Acres - PPDC",
description="Acres PPDC, is our Potato Plant Disease Classification vision model, capable of accurately classifying potato plant disease, based on a single image."
)