Javi commited on
Commit
a930e55
Β·
1 Parent(s): ff733c7

Small fixes

Browse files
Files changed (1) hide show
  1. streamlit_app.py +14 -4
streamlit_app.py CHANGED
@@ -49,6 +49,16 @@ def limit_number_prompts(state: SessionState):
49
  state.prompts = [state.prompts[0]]
50
 
51
 
 
 
 
 
 
 
 
 
 
 
52
  class Sections:
53
  @staticmethod
54
  def header():
@@ -198,7 +208,7 @@ class Sections:
198
  @staticmethod
199
  def classification_output(state: SessionState):
200
  # Possible way of customize this https://discuss.streamlit.io/t/st-button-in-a-custom-layout/2187/2
201
- if st.button("Predict"): # PREDICT πŸš€
202
  with st.spinner("Predicting..."):
203
  if isinstance(state.images[0], str):
204
  clip_response = booste.clip(BOOSTE_API_KEY,
@@ -246,7 +256,7 @@ col1, col2 = st.beta_columns([1, 2])
246
  col1.markdown(" "); col1.markdown(" ")
247
  col1.markdown("#### Task selection")
248
  task_name: str = col2.selectbox("", options=["Prompt ranking", "Image ranking", "Image classification"])
249
- st.markdown(" "); st.markdown(" ")
250
 
251
  session_state = get_state()
252
  if task_name == "Image classification":
@@ -282,6 +292,6 @@ elif task_name == "Image ranking":
282
  Sections.multiple_images_input_preview(session_state)
283
  Sections.classification_output(session_state)
284
 
285
- st.markdown("Created by [@JavierFnts](https://twitter.com/JavierFnts) |"
286
- " [How was CLIP playground created?](https://twitter.com/JavierFnts)")
287
  session_state.sync()
 
49
  state.prompts = [state.prompts[0]]
50
 
51
 
52
+ def is_valid_prediction_state(state: SessionState) -> bool:
53
+ if state.images is None or len(state.images) < 1:
54
+ st.error("Choose at least one image before predicting")
55
+ return False
56
+ if state.prompts is None or len(state.prompts) < 1:
57
+ st.error("Write at least one prompt before predicting")
58
+ return False
59
+ return True
60
+
61
+
62
  class Sections:
63
  @staticmethod
64
  def header():
 
208
  @staticmethod
209
  def classification_output(state: SessionState):
210
  # Possible way of customize this https://discuss.streamlit.io/t/st-button-in-a-custom-layout/2187/2
211
+ if st.button("Predict") and is_valid_prediction_state(state): # PREDICT πŸš€
212
  with st.spinner("Predicting..."):
213
  if isinstance(state.images[0], str):
214
  clip_response = booste.clip(BOOSTE_API_KEY,
 
256
  col1.markdown(" "); col1.markdown(" ")
257
  col1.markdown("#### Task selection")
258
  task_name: str = col2.selectbox("", options=["Prompt ranking", "Image ranking", "Image classification"])
259
+ st.markdown("<br>", unsafe_allow_html=True)
260
 
261
  session_state = get_state()
262
  if task_name == "Image classification":
 
292
  Sections.multiple_images_input_preview(session_state)
293
  Sections.classification_output(session_state)
294
 
295
+ st.markdown("<br><br><br><br>Made by [@JavierFnts](https://twitter.com/JavierFnts) " # "| [How was CLIP Playground made?](https://twitter.com/JavierFnts)"
296
+ "", unsafe_allow_html=True)
297
  session_state.sync()