From f74f48d3f69bd8baac55766ee977551c5aa4022e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2?= Date: Sat, 2 Aug 2025 12:26:50 +0200 Subject: [PATCH] final changes to the ui --- __pycache__/image_generation.cpython-312.pyc | Bin 2969 -> 3004 bytes app.py | 42 +++++++------------ image_generation.py | 2 +- 3 files changed, 15 insertions(+), 29 deletions(-) diff --git a/__pycache__/image_generation.cpython-312.pyc b/__pycache__/image_generation.cpython-312.pyc index a5587a5b725f4cfd1b6117737cf1bf78fcbd72b7..f7a968d6749d7a7cd2a03b0c4ad1b63efd3a3f23 100644 GIT binary patch delta 356 zcmbO!zDJzzG%qg~0}yyU>&;-`*vNN~QIh8tdrD?;YGQHfEtc}koRTVb5Sf~yF!?^C ziPSCjjKrecw9=egENPiVsa2fG`N@e2$@w{nn}wMI7+C~?hE0xTa!@Ri1hR^xK!h}q zC}su{3JMKH@*oifATgPbS%+I3#8U(jN|XOHJMqf_nZ+zXLP0^np-6sm0E;Z6#^gMf zWsH)OMOlqxLAq~=rhyz(6rY)!n4Vf3pO#+~UzA^7q(3=@Rf$n^b35xhCUFgrLgw_; zl3QG1i8-aIu0=)pMMc_^dpK+v^(UX=@M6@REXwIB1~!l{JvA@2D6u3JVq}rW<^oPv zMn>()+qeRaZNMfKmlPF&%q-Fe5gs4{>^Dsi3uMSI4x8Nkl+v73yP}}UR@~7nAQ=G1 C$z5Oo delta 304 zcmdlZK2x0UG%qg~0}$|C=*_swzLD=BqX5S(_LR)x)WqV{TP)?7IVF={Fq&*OV+vqo z;Rh<5+`#0ZSR@W)6-j^yNgz?o3?vj38j55=B62`tvLUk$H&~H8NJwF_5{r|F43JsO z0wfd^6db^6Z;4NS%Ph`Rq&9gX%Q8ms$rh|ejIxunS*00uC%3aIF{*D~#rlp(Tn(t_ z7IS)P$t|w1#GKMp*P^2Qq9V=7>p5(J3g2>gF=|h?;B*xOS$~T!JvA@2D6u3pJ~KBl zJ+;Vf^JGp}Mn=uaH@O0ht-vM~mlPF&%q-Fc5pEy?>=$(q3uMSI4x8Nkl+v73yP|-} KvE0!tAQ=Fu97+TL 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"