final changes to the ui
This commit is contained in:
commit
a0d4476350
1 changed files with 131 additions and 108 deletions
239
app.py
239
app.py
|
@ -1,108 +1,131 @@
|
||||||
# app.py
|
# app.py
|
||||||
import streamlit as st
|
import streamlit as st
|
||||||
from PIL import Image
|
from llama_cpp import Llama
|
||||||
from llama_cpp import Llama
|
from image_generation import generate_image
|
||||||
from image_generation import generate_image
|
|
||||||
|
st.set_page_config(page_title="GreenThumber", layout="centered")
|
||||||
st.set_page_config(page_title="GreenThumber", layout="centered")
|
st.title("🌱 GreenThumber")
|
||||||
st.title("🌱 GreenThumber")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@st.cache_resource(hash_funcs={Llama: lambda _: None})
|
@st.cache_resource(hash_funcs={Llama: lambda _: None})
|
||||||
def load_mistral_model():
|
def load_mistral_model():
|
||||||
llm = Llama(
|
llm = Llama(
|
||||||
model_path="./models/mistral-7b-instruct-v0.1.Q4_K_M.gguf",
|
model_path="./models/mistral-7b-instruct-v0.1.Q4_K_M.gguf",
|
||||||
n_ctx=2048,
|
n_ctx=2048,
|
||||||
n_threads=4,
|
n_threads=4,
|
||||||
n_batch=512,
|
n_batch=512,
|
||||||
verbose=False
|
verbose=False
|
||||||
)
|
)
|
||||||
return llm
|
return llm
|
||||||
|
|
||||||
llm = 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,
|
||||||
def generate_growth_description(plant_type, plant_age, soil_type, sunlight_hours, water_frequency,
|
fertilizer_type, temperature, humidity, days, additional_info):
|
||||||
fertilizer_type, temperature, humidity, days, additional_info):
|
prompt = (
|
||||||
prompt = (
|
f" Instruction:\n"
|
||||||
f" Instruction:\n"
|
f"You are a botanical expert. Describe how a {plant_type} plant will likely look in {days} days "
|
||||||
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"based on these conditions:\n"
|
f"Important environment conditions: {additional_info}\n"
|
||||||
f"Important environment conditions: {additional_info}\n"
|
f"- Plant age: {plant_age}\n"
|
||||||
f"- Plant age: {plant_age}\n"
|
f"Important environment conditions: {additional_info}\n"
|
||||||
f"- Soil Type: {soil_type}\n"
|
f"- Plant age: {plant_age}\n"
|
||||||
f"- Sunlight: {sunlight_hours} hours per day\n"
|
f"- Soil Type: {soil_type}\n"
|
||||||
f"- Water Frequency: {water_frequency} times per week\n"
|
f"- Sunlight: {sunlight_hours} hours per day\n"
|
||||||
f"- Fertilizer Type: {fertilizer_type}\n"
|
f"- Water Frequency: {water_frequency} times per week\n"
|
||||||
f"- Temperature: {temperature}°C\n"
|
f"- Fertilizer Type: {fertilizer_type}\n"
|
||||||
f"- Humidity: {humidity}%\n"
|
f"- Temperature: {temperature}°C\n"
|
||||||
f"### Response:\n"
|
f"- Humidity: {humidity}%\n"
|
||||||
)
|
f"### Response:\n"
|
||||||
output = llm(prompt, max_tokens=100, stop=["###"])
|
)
|
||||||
return output["choices"][0]["text"].strip()
|
output = llm(prompt, max_tokens=100, stop=["###"])
|
||||||
|
return output["choices"][0]["text"].strip()
|
||||||
|
|
||||||
st.header("Plant Info")
|
|
||||||
plant_input_mode = st.radio("How would you like to provide plant info?", ("Type name", "Upload image"))
|
st.header("Plant Info")
|
||||||
plant_type = None
|
plant_input_mode = st.radio("How would you like to provide plant info?", ("Type name", "Upload image"))
|
||||||
uploaded_image = None
|
plant_type = None
|
||||||
|
uploaded_image = None
|
||||||
if plant_input_mode == "Type name":
|
|
||||||
plant_type = st.selectbox("Select Plant Type", ["Basil", "Tomato", "Lettuce"])
|
if plant_input_mode == "Type name":
|
||||||
plant_age = st.number_input("Enter Plant Age (in days)", min_value=1, max_value=365, value=25)
|
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)
|
||||||
|
|
||||||
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)
|
elif plant_input_mode == "Upload image":
|
||||||
image_file = st.file_uploader("Upload an image of your plant", type=["jpg", "jpeg", "png"])
|
plant_type = st.selectbox("Select Plant Type", ["Basil", "Tomato", "Lettuce"])
|
||||||
if image_file:
|
plant_age = st.number_input("Enter Plant Age (in days)", min_value=1, max_value=365, value=25)
|
||||||
uploaded_image = Image.open(image_file)
|
plant_age = st.number_input("Enter Plant Age (in days)", min_value=1, max_value=365, value=25)
|
||||||
st.image(uploaded_image, caption="Uploaded Plant Image", use_container_width =True)
|
image_file = st.file_uploader("Upload an image of your plant", type=["jpg", "jpeg", "png"])
|
||||||
|
if image_file:
|
||||||
|
uploaded_image = Image.open(image_file)
|
||||||
col1, col2 = st.columns(2)
|
st.image(uploaded_image, caption="Uploaded Plant Image", use_container_width =True)
|
||||||
|
|
||||||
with col1:
|
|
||||||
st.markdown("<h3 style='text-align: center;'>Environmental Parameters</h3>", unsafe_allow_html=True)
|
col1, col2 = st.columns(2)
|
||||||
soil_options = ["Sandy", "Clay", "Loamy", "Peaty", "Chalky", "Silty"]
|
|
||||||
|
with col1:
|
||||||
soil_type = st.selectbox("Soil Type", soil_options)
|
st.markdown("<h3 style='text-align: center;'>Environmental Parameters</h3>", unsafe_allow_html=True)
|
||||||
sunlight_hours = st.slider("Sunlight Hours per day", 0, 24, 6)
|
st.markdown("<h3 style='text-align: center;'>Environmental Parameters</h3>", unsafe_allow_html=True)
|
||||||
water_frequency = st.slider("Water Frequency (times per week)", 0, 14, 3)
|
soil_options = ["Sandy", "Clay", "Loamy", "Peaty", "Chalky", "Silty"]
|
||||||
|
|
||||||
with col2:
|
soil_type = st.selectbox("Soil Type", soil_options)
|
||||||
st.markdown("---")
|
sunlight_hours = st.slider("Sunlight Hours per day", 0, 24, 6)
|
||||||
fertilizer_options = ["Organic", "Chemical", "None"]
|
water_frequency = st.slider("Water Frequency (times per week)", 0, 14, 3)
|
||||||
|
|
||||||
fertilizer_type = st.selectbox("Fertilizer Type", fertilizer_options)
|
with col2:
|
||||||
temperature = st.slider("Temperature (°C)", -10, 50, 22)
|
st.markdown("---")
|
||||||
humidity = st.slider("Humidity (%)", 0, 100, 60)
|
st.markdown("---")
|
||||||
|
fertilizer_options = ["Organic", "Chemical", "None"]
|
||||||
days = st.slider("Prediction Interval (in days)", min_value=1, max_value=30, value=7)
|
|
||||||
|
fertilizer_type = st.selectbox("Fertilizer Type", fertilizer_options)
|
||||||
additional_info = st.text_area("Feel free to include any additional detail", "- e.g. 'I'm adding compost to the soil.'", height=100)
|
temperature = st.slider("Temperature (°C)", -10, 50, 22)
|
||||||
|
humidity = st.slider("Humidity (%)", 0, 100, 60)
|
||||||
|
|
||||||
#if st.button("Start Prediction"):
|
days = st.slider("Prediction Interval (in days)", min_value=1, max_value=30, value=7)
|
||||||
if plant_type and plant_type.strip() != "":
|
|
||||||
with st.spinner("Analyzing data and generating description..."):
|
days = st.slider("Prediction Interval (in days)", min_value=1, max_value=30, value=7)
|
||||||
description = generate_growth_description(
|
|
||||||
plant_type, plant_age, soil_type, sunlight_hours, water_frequency,
|
additional_info = st.text_area("Feel free to include any additional detail", "- e.g. 'I'm adding compost to the soil.'", height=100)
|
||||||
fertilizer_type, temperature, humidity, days, additional_info
|
|
||||||
)
|
additional_info = st.text_area("Feel free to include any additional detail", "- e.g. 'I'm adding compost to the soil.'", height=100)
|
||||||
st.subheader(f"📝 Predicted Plant Condition in {days} Days:")
|
|
||||||
st.write(description)
|
|
||||||
|
#if st.button("Start Prediction"):
|
||||||
manipulated_img = generate_image(plant_type, description, plant_age)
|
if plant_type and plant_type.strip() != "":
|
||||||
st.image(manipulated_img, caption="Predicted Plant Condition Image")
|
with st.spinner("Analyzing data and generating description..."):
|
||||||
|
description = generate_growth_description(
|
||||||
# else:
|
plant_type, plant_age, soil_type, sunlight_hours, water_frequency,
|
||||||
# st.warning("Please select or enter a plant type.")
|
fertilizer_type, temperature, humidity, days, additional_info
|
||||||
|
)
|
||||||
|
st.subheader(f"📝 Predicted Plant Condition in {days} Days:")
|
||||||
|
st.write(description)
|
||||||
st.markdown("---")
|
#if st.button("Start Prediction"):
|
||||||
st.caption("Made with ❤️ by Sandwich Craftz.")
|
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")
|
||||||
|
|
||||||
|
# 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.")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
st.markdown("---")
|
||||||
|
st.caption("Made with ❤️ by Sandwich Craftz.")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue