agentsvalley's picture
Update app.py
7f83875 verified
import streamlit as st
from transformers import pipeline
from PIL import Image
# Image classification for plant diseases
plant_disease_pipeline = pipeline(task="image-classification", model="microsoft/resnet-50")
# Load an LLM for remedy generation
llm_pipeline = pipeline("text-generation", model="deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B")
st.title("LLM-Powered Plant Disease Identifier 🌿")
# Upload the plant leaf image
file_name = st.file_uploader("Upload a plant leaf image")
if file_name is not None:
col1, col2 = st.columns(2)
# Display the uploaded image
image = Image.open(file_name)
col1.image(image, use_container_width=True, caption="Uploaded Image")
# Make predictions
predictions = plant_disease_pipeline(image)
# Display disease predictions and generate LLM-based remedies
col2.header("Disease Predictions 🌱")
for p in predictions[:3]:
disease = p['label'].lower()
confidence = round(p['score'] * 100, 1)
col2.subheader(f"**{disease.capitalize()}**: {confidence}%")
# Query LLM for remedy suggestion
prompt = f"Provide a remedy and care tips for a plant affected by {disease}."
llm_response = llm_pipeline(prompt, max_length=50, num_return_sequences=1)
remedy = llm_response[0]['generated_text'].strip()
col2.write(f"**Suggested Remedy:** {remedy}")