JohanBeytell commited on
Commit
e4cf7c3
·
verified ·
1 Parent(s): ee7d1e1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from sklearn.preprocessing import LabelEncoder
4
+ from xgboost import XGBClassifier
5
+ import pickle
6
+
7
+ model = pickle.load('crop_recommendation_model.pkl')
8
+ le = pickle.load('label_encoder.pkl')
9
+
10
+ def recommend_crop(nitrogen, phosphorus, potassium, temperature, humidity, ph, rainfall)
11
+ X_sample = nitrogen, phosphorus, potassium, temperature, humidity, ph, rainfall
12
+
13
+ # Predict crop recommendations
14
+ y_pred_sample = model.predict(X_sample)
15
+
16
+ # Decode the predictions and ground truth back to crop names
17
+ crops_pred = le.inverse_transform(y_pred_sample)
18
+
19
+ return crops_pred
20
+
21
+ # Create the Gradio interface
22
+ interface = gr.Interface(
23
+ fn=classify_potato_plant,
24
+ 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")],
25
+ outputs=[gr.Textbox(label="Predicted Output"), gr.Textbox(label="Confidence Score")],
26
+ title="Acres - PPDC",
27
+ description="Acres PPDC, is our Potato Plant Disease Classification vision model, capable of accurately classifying potato plant disease, based on a single image."
28
+ )