g8a9 commited on
Commit
01c6c72
β€’
1 Parent(s): 9c2fe83

[text2image] suggestions without session_state

Browse files
Files changed (1) hide show
  1. text2image.py +21 -19
text2image.py CHANGED
@@ -111,39 +111,41 @@ def app():
111
 
112
  🀌 Italian mode on! 🀌
113
 
 
 
114
  """
115
  )
116
 
117
- if "suggestion" not in st.session_state:
118
- st.session_state.suggestion = ""
119
-
120
- def update_query(value=""):
121
- st.session_state.suggestion = value
 
 
122
 
123
- col1, col2, col3, col4 = st.beta_columns(4)
124
  with col1:
125
- st.button("Un gatto", on_click=update_query, kwargs=dict(value="Un gatto"))
 
126
  with col2:
127
- st.button("Due gatti", on_click=update_query, kwargs=dict(value="Due gatti"))
 
128
  with col3:
129
- st.button(
130
- "Un fiore giallo",
131
- on_click=update_query,
132
- kwargs=dict(value="Un fiore giallo"),
133
- )
134
  with col4:
135
- st.button(
136
- "Un gatto sopra una sedia", on_click=update_query, kwargs=dict(value="Un gatto sopra una sedia")
137
- )
138
 
139
  col1, col2 = st.beta_columns([3, 1])
140
  with col1:
141
- query = st.text_input(
142
- "Insert an italian query text here...", st.session_state.suggestion
143
- )
144
  with col2:
145
  dataset_name = st.selectbox("IR dataset", ["Unsplash", "CC"])
146
 
 
 
147
  if query:
148
  with st.spinner("Computing..."):
149
 
 
111
 
112
  🀌 Italian mode on! 🀌
113
 
114
+
115
+ You can choose one of our examples down below...
116
  """
117
  )
118
 
119
+ suggestions = [
120
+ "Un gatto",
121
+ "Due gatti",
122
+ "Un fiore giallo",
123
+ "Un gatto sopra una sedia",
124
+ ]
125
+ sugg_idx = -1
126
 
127
+ col1, col2, col3, col4 = st.beta_columns([1, 1, 1, 2])
128
  with col1:
129
+ if st.button(suggestions[0]):
130
+ sugg_idx = 0
131
  with col2:
132
+ if st.button(suggestions[1]):
133
+ sugg_idx = 1
134
  with col3:
135
+ if st.button(suggestions[2]):
136
+ sugg_idx = 2
 
 
 
137
  with col4:
138
+ if st.button(suggestions[3]):
139
+ sugg_idx = 3
 
140
 
141
  col1, col2 = st.beta_columns([3, 1])
142
  with col1:
143
+ query = st.text_input("... or insert an Italian query text")
 
 
144
  with col2:
145
  dataset_name = st.selectbox("IR dataset", ["Unsplash", "CC"])
146
 
147
+ query = query if query else suggestions[sugg_idx] if sugg_idx > -1 else ""
148
+
149
  if query:
150
  with st.spinner("Computing..."):
151