spa / app.py
fadiyahalanazi's picture
Update app.py
242163d verified
import os
# Install missing libraries
os.system("pip install transformers torch")
from transformers import pipeline
import gradio as gr
# Load the model
classifier = pipeline("image-classification", model="umutbozdag/plant-identity")
# Your existing Gradio app code goes here...
import gradio as gr
from transformers import pipeline
# Load the model from Hugging Face
classifier = pipeline("image-classification", model="umutbozdag/plant-identity")
# Link to the first project (PlantInfo1)
plant_info_url = "https://huggingface.co/spaces/NoufSaleh46/PlantInfo1"
# Dictionary containing basic plant information
plant_info = {
"Sunflower": "Sunflowers are tall plants known for their large, bright yellow flowers.",
"Rose": "Roses are flowering plants known for their beauty and fragrance.",
"Dandelion": "Dandelions are common wild plants with bright yellow flowers.",
"Tulip": "Tulips are brightly colored flowers that bloom in the spring.",
"Daisy": "Daisies are small, simple flowers with white petals and a yellow center."
}
# Function to classify the plant image and provide information
def classify_plant_with_info(image):
result = classifier(image)
plant_name = result[0]["label"]
info = plant_info.get(plant_name, "No detailed information available.")
link = f"[Learn More About {plant_name}]({plant_info_url})"
return plant_name, info, link
# Custom CSS for styling
css = """
body {background-color: #0a0f1c;}
h1 {color: #ffffff; text-align: center; font-size: 28px;}
p {color: #b0b3b8; text-align: center; font-size: 16px;}
.gr-button {background-color: #6366f1; color: white; border-radius: 10px; font-size: 18px; padding: 12px;}
.gr-box {border-radius: 10px; background-color: #161b2b; padding: 15px; color: white;}
.gr-textbox {color: white;}
.gr-row {justify-content: center;}
"""
# Gradio Interface
with gr.Blocks(css=css) as demo:
gr.Markdown("<h1>🌱 AI Plant Identification 🌿</h1>")
gr.Markdown("<p>Upload a plant image and let AI identify it! ✨</p>")
with gr.Row():
with gr.Column():
image_input = gr.Image(type="pil", label="πŸ“Έ Upload Plant Image")
with gr.Column():
output = gr.Textbox(label="πŸ” Plant Name", interactive=False)
info_output = gr.Textbox(label="πŸ“– Plant Information", interactive=False)
link_output = gr.Markdown()
classify_btn = gr.Button("πŸ”Ž Identify Plant")
classify_btn.click(classify_plant_with_info, inputs=image_input, outputs=[output, info_output, link_output])
# Launch the app
demo.launch()