jacobbarkow commited on
Commit
415374b
·
1 Parent(s): 3aa3cdc

improved design and background image

Browse files
Files changed (3) hide show
  1. app.py +23 -22
  2. assets/background.png +0 -0
  3. predictor.py +1 -1
app.py CHANGED
@@ -25,26 +25,26 @@ def add_bg_from_local(image_file):
25
  unsafe_allow_html=True
26
  )
27
 
28
- def header_white_bg(text, fontsize = 40, bold = True):
29
  st.markdown(
30
  f"""
31
- <span style="background:rgba(255, 255, 255, 0.8); font-size:{fontsize}px; font-weight:{"bold" if bold else "normal"}; line-height: 2em">{text}</span>
32
  """,
33
  unsafe_allow_html=True
34
  )
35
 
36
- def header_red_bg(text, fontsize = 40, bold = True):
37
  st.markdown(
38
  f"""
39
- <span style="background:rgba(184, 35, 35, 0.5); font-size:{fontsize}px; font-weight:{"bold" if bold else "normal"}; line-height: 1.25">{text}</span>
40
  """,
41
  unsafe_allow_html=True
42
  )
43
 
44
- def header_green_bg(text, fontsize = 40, bold = True):
45
  st.markdown(
46
  f"""
47
- <span style="background:rgba(26, 153, 58, 0.5); font-size:{fontsize}px; font-weight:{"bold" if bold else "normal"}; line-height: 1.25">{text}</span>
48
  """,
49
  unsafe_allow_html=True
50
  )
@@ -115,14 +115,15 @@ def diagnose_health(file):
115
  def app():
116
 
117
  add_bg_from_local('assets/background.png')
118
- header_white_bg(f'<span style="color:green">Plant</span><span style="color:orange">Dx</span><span style="color:green">: Diagnosis in a Snap!</span> ')
119
 
120
  # Upload image of plant
121
- header_white_bg("Upload an image of your plant:", fontsize=32)
 
122
  uploaded_file = st.file_uploader("", type=["jpg", "jpeg", "png"])
123
 
124
  if uploaded_file:
125
- header_white_bg("Preview of the selected image:", fontsize=28, bold=False)
126
  st.image(uploaded_file)
127
 
128
  # Get diagnosis button
@@ -132,34 +133,34 @@ def app():
132
  results = diagnose_health(uploaded_file)
133
 
134
  if results[0][1] == 'healthy':
135
- header_green_bg(f"We believe this is a healthy {results[0][0]} plant with {results[0][2]} confidence. Keep up the good work with proper watering, sunlight, and nutrients.", fontsize=32, bold=False)
136
  else:
137
- header_red_bg(f"We believe this is an unhealthy {results[0][0]} plant with {results[0][1]}, with {results[0][2]} confidence. {results[0][3] if results [0][3] else ''}", fontsize=32, bold=False)
138
 
139
  if len(results) > 1:
140
- header_white_bg("Other potential diagnoses: ", fontsize=24)
141
 
142
  for p in range(1, len(results)):
143
  if results[p][1] == 'healthy':
144
- header_white_bg(
145
  f"A healthy {results[p][0]} plant, {results[p][2]} confidence.",
146
  fontsize=20, bold=False)
147
  else:
148
- header_white_bg(
149
  f"An unhealthy {results[p][0]} plant with {results[p][1]}, {results[p][2]} confidence. {results[p][3] if results [p][3] else ''}",
150
  fontsize=20, bold=False)
151
 
152
  else:
153
  st.warning("Please upload an image of your plant first")
154
 
155
- # Create user profile button
156
- if st.button("Create User Profile"):
157
- st.subheader("User Profile")
158
- # Prompt user to add their name and the plant they own
159
- user_name = st.text_input("Enter your name:")
160
- plant_name = st.text_input("Enter the plant you own:")
161
- if user_name and plant_name:
162
- st.success(f"User profile created for {user_name} with plant {plant_name}")
163
 
164
 
165
  # Run Streamlit app
 
25
  unsafe_allow_html=True
26
  )
27
 
28
+ def header_white(text, fontsize = 40, bold = True):
29
  st.markdown(
30
  f"""
31
+ <span style="display:inline-block; background:rgba(255, 255, 255, 1); outline: 1px solid; border-radius: 50px; padding: 10px; font-size:{fontsize}px; font-weight:{"bold" if bold else "normal"}; line-height: 2em">{text}</span>
32
  """,
33
  unsafe_allow_html=True
34
  )
35
 
36
+ def header_red(text, fontsize = 40, bold = True):
37
  st.markdown(
38
  f"""
39
+ <span style="display:inline-block; background:rgba(255, 255, 255, 1); color:red; outline: 1px solid; border-radius: 30px; padding: 10px; font-size:{fontsize}px; font-weight:{"bold" if bold else "normal"}">{text}</span>
40
  """,
41
  unsafe_allow_html=True
42
  )
43
 
44
+ def header_green(text, fontsize = 40, bold = True):
45
  st.markdown(
46
  f"""
47
+ <span style="display:inline-block; background:rgba(255, 255, 255, 1); color:green; outline: 1px solid; border-radius: 30px; padding: 10px; font-size:{fontsize}px; font-weight:{"bold" if bold else "normal"}; line-height: 1.25">{text}</span>
48
  """,
49
  unsafe_allow_html=True
50
  )
 
115
  def app():
116
 
117
  add_bg_from_local('assets/background.png')
118
+ header_white(f'<span style="color:green">Plant</span><span style="color:orange">Dx</span><span style="color:green">: Diagnosis in a Snap!</span> ')
119
 
120
  # Upload image of plant
121
+ header_white("Upload an image of your plant below:", fontsize=32)
122
+ header_white("For best results, remove the leaf from the plant and take the image against a dark background.", fontsize=16, bold=False)
123
  uploaded_file = st.file_uploader("", type=["jpg", "jpeg", "png"])
124
 
125
  if uploaded_file:
126
+ header_white("Preview of the selected image:", fontsize=28, bold=False)
127
  st.image(uploaded_file)
128
 
129
  # Get diagnosis button
 
133
  results = diagnose_health(uploaded_file)
134
 
135
  if results[0][1] == 'healthy':
136
+ header_green(f"We believe this is a healthy {results[0][0]} plant with {results[0][2]} confidence. Keep up the good work with proper watering, sunlight, and nutrients.", fontsize=32, bold=False)
137
  else:
138
+ header_red(f"We believe this is an unhealthy {results[0][0]} plant with {results[0][1]}, with {results[0][2]} confidence. {results[0][3] if results [0][3] else ''}", fontsize=32, bold=False)
139
 
140
  if len(results) > 1:
141
+ header_white("Other potential diagnoses: ", fontsize=24)
142
 
143
  for p in range(1, len(results)):
144
  if results[p][1] == 'healthy':
145
+ header_white(
146
  f"A healthy {results[p][0]} plant, {results[p][2]} confidence.",
147
  fontsize=20, bold=False)
148
  else:
149
+ header_white(
150
  f"An unhealthy {results[p][0]} plant with {results[p][1]}, {results[p][2]} confidence. {results[p][3] if results [p][3] else ''}",
151
  fontsize=20, bold=False)
152
 
153
  else:
154
  st.warning("Please upload an image of your plant first")
155
 
156
+ # # Create user profile button
157
+ # if st.button("Create User Profile"):
158
+ # st.subheader("User Profile")
159
+ # # Prompt user to add their name and the plant they own
160
+ # user_name = st.text_input("Enter your name:")
161
+ # plant_name = st.text_input("Enter the plant you own:")
162
+ # if user_name and plant_name:
163
+ # st.success(f"User profile created for {user_name} with plant {plant_name}")
164
 
165
 
166
  # Run Streamlit app
assets/background.png CHANGED
predictor.py CHANGED
@@ -77,7 +77,7 @@ def predict(image_file):
77
  for j in range(topk):
78
  tmp_dct = {}
79
  label_indx = indices[0][j]
80
- # print(label_indx)
81
  class_name = class_names[label_indx]
82
  tmp_dct["predicted"] = class_name
83
  tmp_dct["probability"] = probs[0][j]
 
77
  for j in range(topk):
78
  tmp_dct = {}
79
  label_indx = indices[0][j]
80
+ print("index:", label_indx)
81
  class_name = class_names[label_indx]
82
  tmp_dct["predicted"] = class_name
83
  tmp_dct["probability"] = probs[0][j]