Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,69 +1,24 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
return {
|
| 19 |
-
"name": plant_info.get("name", plant_name),
|
| 20 |
-
"description": plant_info.get("description", "No description available."),
|
| 21 |
-
"image_url": plant_info.get("main_image_path", None),
|
| 22 |
-
"sun_requirements": plant_info.get("sun_requirements", "No information available."),
|
| 23 |
-
"watering": plant_info.get("watering", None),
|
| 24 |
-
}
|
| 25 |
-
return None
|
| 26 |
-
except requests.exceptions.RequestException as e:
|
| 27 |
-
st.error(f"Error fetching data: {e}")
|
| 28 |
-
return None
|
| 29 |
-
|
| 30 |
-
# Function to generate watering instructions using AI
|
| 31 |
-
def refine_watering_instructions(plant_name, basic_instructions=None):
|
| 32 |
-
prompt = (
|
| 33 |
-
f"Refine these watering instructions for the plant '{plant_name}': '{basic_instructions}'. "
|
| 34 |
-
"If no specific instructions are available, provide a detailed guideline for watering this plant type."
|
| 35 |
-
)
|
| 36 |
-
result = text_generation_pipeline(prompt, max_length=150, num_return_sequences=1)
|
| 37 |
-
return result[0]["generated_text"]
|
| 38 |
-
|
| 39 |
-
# Streamlit app
|
| 40 |
-
def main():
|
| 41 |
-
st.title("🌱 AI-Powered Plant Care Guide")
|
| 42 |
-
|
| 43 |
-
# Section 1: Search for plant care information
|
| 44 |
-
st.header("Search for Plant Care Information")
|
| 45 |
-
user_input = st.text_input("Enter the name of a plant", "")
|
| 46 |
-
|
| 47 |
-
if st.button("Search"):
|
| 48 |
-
if user_input.strip():
|
| 49 |
-
with st.spinner("Fetching plant data..."):
|
| 50 |
-
plant_info = fetch_plant_data(user_input)
|
| 51 |
-
|
| 52 |
-
if plant_info:
|
| 53 |
-
with st.spinner("Generating watering instructions..."):
|
| 54 |
-
basic_watering = plant_info["watering"] or "No specific instructions available."
|
| 55 |
-
plant_info["watering"] = refine_watering_instructions(user_input, basic_instructions=basic_watering)
|
| 56 |
-
|
| 57 |
-
st.subheader(f"Care Instructions for {plant_info['name']}")
|
| 58 |
-
st.write(f"**Description:** {plant_info['description']}")
|
| 59 |
-
st.write(f"**Sun Requirements:** {plant_info['sun_requirements']}")
|
| 60 |
-
st.write(f"**Watering Instructions:** {plant_info['watering']}")
|
| 61 |
-
|
| 62 |
-
# Display the image if available, otherwise show "Picture not available"
|
| 63 |
-
if plant_info["image_url"]:
|
| 64 |
st.image(plant_info["image_url"], caption=plant_info["name"], width=300)
|
| 65 |
-
|
| 66 |
-
st.
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
|
|
| 1 |
+
if st.button("Search"):
|
| 2 |
+
if user_input.strip():
|
| 3 |
+
with st.spinner("Fetching plant data..."):
|
| 4 |
+
plant_info = fetch_plant_data(user_input)
|
| 5 |
+
|
| 6 |
+
if plant_info:
|
| 7 |
+
with st.spinner("Generating watering instructions..."):
|
| 8 |
+
basic_watering = plant_info["watering"] or "No specific instructions available."
|
| 9 |
+
plant_info["watering"] = refine_watering_instructions(user_input, basic_instructions=basic_watering)
|
| 10 |
+
|
| 11 |
+
st.subheader(f"Care Instructions for {plant_info['name']}")
|
| 12 |
+
st.write(f"**Description:** {plant_info['description']}")
|
| 13 |
+
st.write(f"**Sun Requirements:** {plant_info['sun_requirements']}")
|
| 14 |
+
st.write(f"**Watering Instructions:** {plant_info['watering']}")
|
| 15 |
+
|
| 16 |
+
if plant_info["image_url"]:
|
| 17 |
+
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
st.image(plant_info["image_url"], caption=plant_info["name"], width=300)
|
| 19 |
+
except Exception:
|
| 20 |
+
st.warning("Could not load the plant image.")
|
| 21 |
+
else:
|
| 22 |
+
st.error("No plant information found.")
|
| 23 |
+
else:
|
| 24 |
+
st.warning("Please enter a plant name.")
|