diff --git a/__pycache__/image_generation.cpython-312.pyc b/__pycache__/image_generation.cpython-312.pyc index a5587a5b7..f7a968d67 100644 Binary files a/__pycache__/image_generation.cpython-312.pyc and b/__pycache__/image_generation.cpython-312.pyc differ diff --git a/app.py b/app.py index 032d59cae..b83947bc4 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,5 @@ # app.py +from PIL import Image import streamlit as st from llama_cpp import Llama from image_generation import generate_image @@ -6,9 +7,6 @@ from image_generation import generate_image st.set_page_config(page_title="GreenThumber", layout="centered") st.title("🌱 GreenThumber") - - - @st.cache_resource(hash_funcs={Llama: lambda _: None}) def load_mistral_model(): llm = Llama( @@ -30,9 +28,7 @@ def generate_growth_description(plant_type, plant_age, soil_type, sunlight_hours f"You are a botanical expert. Describe how a {plant_type} plant will likely look in {days} days " 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"- Plant age: {plant_age} days\n" f"- Soil Type: {soil_type}\n" f"- Sunlight: {sunlight_hours} hours per day\n" f"- Water Frequency: {water_frequency} times per week\n" @@ -59,7 +55,6 @@ if plant_input_mode == "Type name": 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) @@ -86,30 +81,21 @@ with col2: 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", 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..."): - 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"): # Comment out this line to enable automatic refresh on input change + 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) - manipulated_img = generate_image(plant_type, description, plant_age) - st.image(manipulated_img, caption="Predicted Plant Condition Image") + manipulated_img = generate_image(plant_type, description, plant_age) + st.image(manipulated_img, caption="Predicted Plant Condition Image") st.markdown("---") diff --git a/image_generation.py b/image_generation.py index b11ea68bb..02e9f4765 100644 --- a/image_generation.py +++ b/image_generation.py @@ -12,7 +12,7 @@ PLANTVILLAGE_DIR = ".\plant_growth_data\images" def determine_health_status(description: str) -> str: illness_keywords = [ - "disease", "wilt", "brown", "yellowing", "withered", "damage", "ill", "unhealthy" + "disease", "wilt", "wilted ", "brown", "yellowing", "withered", "damage", "ill", "unhealthy", "harmful", "fire", "coca cola" ] healthy_keywords = [ "healthy", "vibrant", "green", "lush", "strong", "thriving", "fresh", "good condition"