Spaces:
Build error
Build error
Download app.py from Swapnilbpatil/Crop_Recommendation_System: direct link, hf CLI and curl.
- Browser
- Download file 923 Bytes
-
https://huggingface.co/spaces/Swapnilbpatil/Crop_Recommendation_System/resolve/main/app.py
- Command line
-
hf download hf://spaces/Swapnilbpatil/Crop_Recommendation_System/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Swapnilbpatil/Crop_Recommendation_System/resolve/main/app.py
923 Bytes
| import streamlit as st | |
| import numpy as np | |
| import pickle | |
| # Load the model | |
| with open('crop_recommendation.pkl', 'rb') as file: | |
| model = pickle.load(file) | |
| # Define function for prediction | |
| def predict_crop(Nitrogen, Phosphorus, Potassium, pH, Rainfall, Temperature): | |
| input_data = np.array([[Nitrogen, Phosphorus, Potassium, pH, Rainfall, Temperature]]) | |
| prediction = model.predict(input_data) | |
| return prediction[0] | |
| # Streamlit app | |
| st.title('Crop Recommendation System') | |
| # Input fields | |
| Nitrogen = st.number_input('Nitrogen') | |
| Phosphorus = st.number_input('Phosphorus') | |
| Potassium = st.number_input('Potassium') | |
| pH = st.number_input('pH') | |
| Rainfall = st.number_input('Rainfall (mm)') | |
| Temperature = st.number_input('Temperature (°C)') | |
| # Predict button | |
| if st.button('Predict Crop'): | |
| result = predict_crop(Nitrogen, Phosphorus, Potassium, pH, Rainfall, Temperature) | |
| st.success(f'Recommended Crop: {result}') | |