Spaces:
Runtime error
Runtime error
Fix
Browse files- Dockerfile +1 -1
- src/streamlit_app.py +40 -42
Dockerfile
CHANGED
|
@@ -17,6 +17,6 @@ EXPOSE 8501
|
|
| 17 |
|
| 18 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
| 19 |
|
| 20 |
-
ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|
| 21 |
|
| 22 |
# If secrets need to be mounted: https://huggingface.co/docs/hub/spaces-sdks-docker#secrets-and-variables-management
|
|
|
|
| 17 |
|
| 18 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
| 19 |
|
| 20 |
+
ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]
|
| 21 |
|
| 22 |
# If secrets need to be mounted: https://huggingface.co/docs/hub/spaces-sdks-docker#secrets-and-variables-management
|
src/streamlit_app.py
CHANGED
|
@@ -3,45 +3,43 @@ import streamlit as st
|
|
| 3 |
|
| 4 |
from plant_identifier.identifier import identify_plant
|
| 5 |
|
| 6 |
-
st.
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
#
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
#
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
# except Exception as e:
|
| 47 |
-
# st.error(f"Error: {e}")
|
|
|
|
| 3 |
|
| 4 |
from plant_identifier.identifier import identify_plant
|
| 5 |
|
| 6 |
+
st.set_page_config(page_title="Greenmorrow Plant Identification", page_icon="πΏ")
|
| 7 |
+
|
| 8 |
+
st.title("π±π² Greenmorrow Plant Identification Agent")
|
| 9 |
+
st.write("Upload a plant photograph and the app will attempt to identify the species.")
|
| 10 |
+
|
| 11 |
+
# Hugging Face Spaces best practice: store keys in Space Secrets.
|
| 12 |
+
# They are available via st.secrets and/or environment variables.
|
| 13 |
+
openai_key = os.getenv("OPENAI_KEY", os.getenv("OPENAI_KEY", ""))
|
| 14 |
+
plantnet_key = os.getenv("PLANTNET_API_KEY", os.getenv("PLANTNET_API_KEY", ""))
|
| 15 |
+
|
| 16 |
+
if not openai_key or not plantnet_key:
|
| 17 |
+
st.error(
|
| 18 |
+
"Missing API keys. Please define the following Space Secrets:"
|
| 19 |
+
"- OPENAI_KEY"
|
| 20 |
+
"- PLANTNET_API_KEY"
|
| 21 |
+
)
|
| 22 |
+
st.stop()
|
| 23 |
+
|
| 24 |
+
st.subheader("π· Upload plant photo(s)")
|
| 25 |
+
uploaded_files = st.file_uploader(
|
| 26 |
+
"Upload one or more images",
|
| 27 |
+
type=["png", "jpg", "jpeg", "webp"],
|
| 28 |
+
accept_multiple_files=True,
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
if st.button("Identify plant", type="primary", disabled=not uploaded_files):
|
| 32 |
+
with st.spinner("Identifying plant..."):
|
| 33 |
+
try:
|
| 34 |
+
# Streamlit UploadedFile behaves like a file-like object
|
| 35 |
+
result = identify_plant(
|
| 36 |
+
images=[f for f in uploaded_files],
|
| 37 |
+
openai_api_key=openai_key,
|
| 38 |
+
plantnet_api_key=plantnet_key,
|
| 39 |
+
)
|
| 40 |
+
st.success("Done!")
|
| 41 |
+
st.markdown("### πΏ Identification result")
|
| 42 |
+
st.write(result)
|
| 43 |
+
|
| 44 |
+
except Exception as e:
|
| 45 |
+
st.error(f"Error: {e}")
|
|
|
|
|
|