diff --git a/app.py b/app.py index fd133803d..3f48e0fec 100644 --- a/app.py +++ b/app.py @@ -1,29 +1,14 @@ -import os +# app.py import streamlit as st -import pandas as pd -import joblib from PIL import Image -import torch -from torchvision import models from llama_cpp import Llama -from diffusers import DiffusionPipeline, StableDiffusionPipeline, DPMSolverMultistepScheduler from image_generation import generate_image st.set_page_config(page_title="GreenThumber", layout="centered") st.title("🌱 GreenThumber") -@st.cache_resource -def load_imagenet_labels(): - import urllib - url = "https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt" - response = urllib.request.urlopen(url) - labels = [line.strip() for line in response.read().decode("utf-8").split("\n")] - return labels -labels = load_imagenet_labels() - -# Load Mistral LLM via llama-cpp-python with custom hash to avoid Streamlit caching issues @st.cache_resource(hash_funcs={Llama: lambda _: None}) def load_mistral_model(): llm = Llama( @@ -39,13 +24,14 @@ llm = load_mistral_model() # Generate a description using the Mistral model -def generate_growth_description(plant_type, 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): prompt = ( f" Instruction:\n" 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 additional conditions: {additional_info}\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" @@ -66,10 +52,11 @@ uploaded_image = None if plant_input_mode == "Type name": 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=30) + 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) @@ -79,43 +66,41 @@ elif plant_input_mode == "Upload image": col1, col2 = st.columns(2) with col1: - st.header("Environmental Parameters") + st.markdown("