final changes to the ui
This commit is contained in:
commit
a0d4476350
1 changed files with 131 additions and 108 deletions
27
app.py
27
app.py
|
@ -1,6 +1,5 @@
|
|||
# app.py
|
||||
import streamlit as st
|
||||
from PIL import Image
|
||||
from llama_cpp import Llama
|
||||
from image_generation import generate_image
|
||||
|
||||
|
@ -9,6 +8,7 @@ st.title("🌱 GreenThumber")
|
|||
|
||||
|
||||
|
||||
|
||||
@st.cache_resource(hash_funcs={Llama: lambda _: None})
|
||||
def load_mistral_model():
|
||||
llm = Llama(
|
||||
|
@ -23,7 +23,6 @@ def load_mistral_model():
|
|||
llm = load_mistral_model()
|
||||
|
||||
|
||||
# Generate a description using the Mistral model
|
||||
def generate_growth_description(plant_type, plant_age, soil_type, sunlight_hours, water_frequency,
|
||||
fertilizer_type, temperature, humidity, days, additional_info):
|
||||
prompt = (
|
||||
|
@ -32,6 +31,8 @@ def generate_growth_description(plant_type, plant_age, soil_type, sunlight_hours
|
|||
f"based on these conditions:\n"
|
||||
f"Important environment conditions: {additional_info}\n"
|
||||
f"- Plant age: {plant_age}\n"
|
||||
f"Important environment conditions: {additional_info}\n"
|
||||
f"- Plant age: {plant_age}\n"
|
||||
f"- Soil Type: {soil_type}\n"
|
||||
f"- Sunlight: {sunlight_hours} hours per day\n"
|
||||
f"- Water Frequency: {water_frequency} times per week\n"
|
||||
|
@ -54,9 +55,11 @@ if plant_input_mode == "Type name":
|
|||
plant_age = st.number_input("Enter Plant Age (in days)", min_value=1, max_value=365, value=25)
|
||||
|
||||
|
||||
|
||||
elif plant_input_mode == "Upload image":
|
||||
plant_type = st.selectbox("Select Plant Type", ["Basil", "Tomato", "Lettuce"])
|
||||
plant_age = st.number_input("Enter Plant Age (in days)", min_value=1, max_value=365, value=25)
|
||||
plant_age = st.number_input("Enter Plant Age (in days)", min_value=1, max_value=365, value=25)
|
||||
image_file = st.file_uploader("Upload an image of your plant", type=["jpg", "jpeg", "png"])
|
||||
if image_file:
|
||||
uploaded_image = Image.open(image_file)
|
||||
|
@ -66,6 +69,7 @@ elif plant_input_mode == "Upload image":
|
|||
col1, col2 = st.columns(2)
|
||||
|
||||
with col1:
|
||||
st.markdown("<h3 style='text-align: center;'>Environmental Parameters</h3>", unsafe_allow_html=True)
|
||||
st.markdown("<h3 style='text-align: center;'>Environmental Parameters</h3>", unsafe_allow_html=True)
|
||||
soil_options = ["Sandy", "Clay", "Loamy", "Peaty", "Chalky", "Silty"]
|
||||
|
||||
|
@ -74,6 +78,7 @@ with col1:
|
|||
water_frequency = st.slider("Water Frequency (times per week)", 0, 14, 3)
|
||||
|
||||
with col2:
|
||||
st.markdown("---")
|
||||
st.markdown("---")
|
||||
fertilizer_options = ["Organic", "Chemical", "None"]
|
||||
|
||||
|
@ -83,9 +88,22 @@ with col2:
|
|||
|
||||
days = st.slider("Prediction Interval (in days)", min_value=1, max_value=30, value=7)
|
||||
|
||||
days = st.slider("Prediction Interval (in days)", min_value=1, max_value=30, value=7)
|
||||
|
||||
additional_info = st.text_area("Feel free to include any additional detail", "- e.g. 'I'm adding compost to the soil.'", height=100)
|
||||
|
||||
additional_info = st.text_area("Feel free to include any additional detail", "- e.g. 'I'm adding compost to the soil.'", height=100)
|
||||
|
||||
|
||||
#if st.button("Start Prediction"):
|
||||
if plant_type and plant_type.strip() != "":
|
||||
with st.spinner("Analyzing data and generating description..."):
|
||||
description = generate_growth_description(
|
||||
plant_type, plant_age, soil_type, sunlight_hours, water_frequency,
|
||||
fertilizer_type, temperature, humidity, days, additional_info
|
||||
)
|
||||
st.subheader(f"📝 Predicted Plant Condition in {days} Days:")
|
||||
st.write(description)
|
||||
#if st.button("Start Prediction"):
|
||||
if plant_type and plant_type.strip() != "":
|
||||
with st.spinner("Analyzing data and generating description..."):
|
||||
|
@ -99,6 +117,11 @@ if plant_type and plant_type.strip() != "":
|
|||
manipulated_img = generate_image(plant_type, description, plant_age)
|
||||
st.image(manipulated_img, caption="Predicted Plant Condition Image")
|
||||
|
||||
# else:
|
||||
# st.warning("Please select or enter a plant type.")
|
||||
manipulated_img = generate_image(plant_type, description, plant_age)
|
||||
st.image(manipulated_img, caption="Predicted Plant Condition Image")
|
||||
|
||||
# else:
|
||||
# st.warning("Please select or enter a plant type.")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue