dr-wann commited on
Commit
be3cc0b
Β·
1 Parent(s): 798827b
Files changed (2) hide show
  1. Dockerfile +1 -1
  2. 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.write("XSRF:", st.get_option("server.enableXsrfProtection"))
7
-
8
- # st.set_page_config(page_title="Greenmorrow Plant Identification", page_icon="🌿")
9
-
10
- # st.title("🌱🌲 Greenmorrow Plant Identification Agent")
11
- # st.write("Upload a plant photograph and the app will attempt to identify the species.")
12
-
13
- # # Hugging Face Spaces best practice: store keys in Space Secrets.
14
- # # They are available via st.secrets and/or environment variables.
15
- # openai_key = os.getenv("OPENAI_KEY", os.getenv("OPENAI_KEY", ""))
16
- # plantnet_key = os.getenv("PLANTNET_API_KEY", os.getenv("PLANTNET_API_KEY", ""))
17
-
18
- # if not openai_key or not plantnet_key:
19
- # st.error(
20
- # "Missing API keys. Please define the following Space Secrets:"
21
- # "- OPENAI_KEY"
22
- # "- PLANTNET_API_KEY"
23
- # )
24
- # st.stop()
25
-
26
- # st.subheader("πŸ“· Upload plant photo(s)")
27
- # uploaded_files = st.file_uploader(
28
- # "Upload one or more images",
29
- # type=["png", "jpg", "jpeg", "webp"],
30
- # accept_multiple_files=True,
31
- # )
32
-
33
- # if st.button("Identify plant", type="primary", disabled=not uploaded_files):
34
- # with st.spinner("Identifying plant..."):
35
- # try:
36
- # # Streamlit UploadedFile behaves like a file-like object
37
- # result = identify_plant(
38
- # images=[f for f in uploaded_files],
39
- # openai_api_key=openai_key,
40
- # plantnet_api_key=plantnet_key,
41
- # )
42
- # st.success("Done!")
43
- # st.markdown("### 🌿 Identification result")
44
- # st.write(result)
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}")