final changes to the ui

This commit is contained in:
Nicolò 2025-08-02 12:26:50 +02:00
parent 3418324060
commit f74f48d3f6
3 changed files with 15 additions and 29 deletions

42
app.py
View file

@ -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("---")

View file

@ -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"