Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from huggingface_hub import hf_hub_download
|
| 3 |
+
from terratorch.cli_tools import LightningInferenceModel
|
| 4 |
+
|
| 5 |
+
# Download the model checkpoint and configuration file
|
| 6 |
+
ckpt_path = hf_hub_download(repo_id="ibm-granite/granite-geospatial-biomass", filename="biomass_model.ckpt")
|
| 7 |
+
config_path = hf_hub_download(repo_id="ibm-granite/granite-geospatial-biomass", filename="config.yaml")
|
| 8 |
+
|
| 9 |
+
# Load the model
|
| 10 |
+
model = LightningInferenceModel.from_config(config_path, ckpt_path)
|
| 11 |
+
|
| 12 |
+
# Create a Streamlit app
|
| 13 |
+
st.title("Agricultural Yield Prediction App")
|
| 14 |
+
|
| 15 |
+
# Input field for directory containing input files
|
| 16 |
+
input_directory = st.text_input("Enter input directory:")
|
| 17 |
+
|
| 18 |
+
# Enter Farm Data sidebar
|
| 19 |
+
st.sidebar.subheader("Enter Farm Data:")
|
| 20 |
+
farm_data = {
|
| 21 |
+
"Soil Type": st.sidebar.selectbox("Soil Type", ["Clay", "Silt", "Sand"]),
|
| 22 |
+
"Weather Conditions": st.sidebar.selectbox("Weather Conditions", ["Sunny", "Rainy", "Cloudy"]),
|
| 23 |
+
"Crop Type": st.sidebar.selectbox("Crop Type", ["Wheat", "Corn", "Soybean"]),
|
| 24 |
+
"Crop Variety": st.sidebar.text_input("Crop Variety"),
|
| 25 |
+
"Soil pH": st.sidebar.number_input("Soil pH", min_value=0.0, max_value=14.0),
|
| 26 |
+
"Fertilizer Application": st.sidebar.text_input("Fertilizer Application"),
|
| 27 |
+
"Irrigation": st.sidebar.selectbox("Irrigation", ["Yes", "No"]),
|
| 28 |
+
"Pest/Disease Management": st.sidebar.text_input("Pest/Disease Management"),
|
| 29 |
+
"Weather Data": {
|
| 30 |
+
"Temperature": st.sidebar.number_input("Temperature (°C)", min_value=-20.0, max_value=40.0),
|
| 31 |
+
"Precipitation": st.sidebar.number_input("Precipitation (mm)", min_value=0.0, max_value=1000.0),
|
| 32 |
+
"Sunshine Hours": st.sidebar.number_input("Sunshine Hours", min_value=0.0, max_value=24.0)
|
| 33 |
+
},
|
| 34 |
+
"Topography": {
|
| 35 |
+
"Slope": st.sidebar.number_input("Slope (%)", min_value=0.0, max_value=100.0),
|
| 36 |
+
"Aspect": st.sidebar.selectbox("Aspect", ["North", "South", "East", "West"])
|
| 37 |
+
},
|
| 38 |
+
"Previous Crop": st.sidebar.selectbox("Previous Crop", ["Wheat", "Corn", "Soybean", "None"])
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
# Button to trigger prediction
|
| 42 |
+
if st.button("Predict Yield"):
|
| 43 |
+
if input_directory:
|
| 44 |
+
# Run inference on the input directory
|
| 45 |
+
inference_results, input_file_names = model.inference_on_dir(input_directory)
|
| 46 |
+
|
| 47 |
+
# Display predicted yields
|
| 48 |
+
st.subheader("Predicted Yields:")
|
| 49 |
+
for file_name, result in zip(input_file_names, inference_results):
|
| 50 |
+
st.write(f"{file_name}: {result}")
|
| 51 |
+
else:
|
| 52 |
+
st.error("Please enter a valid input directory.")
|