| import os |
| import streamlit as st |
|
|
| from plant_identifier.identifier import identify_plant |
|
|
| st.set_page_config(page_title="Identification de plante Greenmorrow", page_icon="🌿") |
|
|
| st.title("🌱🌲 Agent d'identification de plante Greenmorrow") |
| st.write("Téléchargez une photo de plante et l'application tentera d'identifier son espèce.") |
|
|
| |
| |
| openai_key = os.getenv("OPENAI_KEY", os.getenv("OPENAI_KEY", "")) |
| plantnet_key = os.getenv("PLANTNET_API_KEY", os.getenv("PLANTNET_API_KEY", "")) |
|
|
| if not openai_key or not plantnet_key: |
| st.error( |
| "Missing API keys. Please define the following Space Secrets:" |
| "- OPENAI_KEY" |
| "- PLANTNET_API_KEY" |
| ) |
| st.stop() |
|
|
| st.subheader("📷 Télécharger des photos") |
| uploaded_files = st.file_uploader( |
| "Téléchargez une ou plusieurs images", |
| type=["png", "jpg", "jpeg", "webp"], |
| accept_multiple_files=True, |
| ) |
|
|
| if st.button("Identifier la plante", type="primary", disabled=not uploaded_files): |
| with st.spinner("Plante en cours d'identification..."): |
| try: |
| |
| result = identify_plant( |
| images=[f for f in uploaded_files], |
| openai_api_key=openai_key, |
| plantnet_api_key=plantnet_key, |
| ) |
| st.success("Terminé !") |
| st.markdown("### 🌿 Résultats d'identification") |
| st.write(result) |
|
|
| except Exception as e: |
| st.error(f"Error: {e}") |
|
|