Mia2024 commited on
Commit
2a5d41a
·
verified ·
1 Parent(s): 7c39d11
Files changed (1) hide show
  1. app.py +278 -34
app.py CHANGED
@@ -2,57 +2,301 @@ import streamlit as st
2
  import time
3
 
4
  # def submit_callback():
5
- # st.write(st.session_state.product)
6
- # st.write(st.session_state.gender)
7
- # st.write(st.session_state.profession)
8
- # st.write(st.session_state.hobby)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
- def delete_callback():
 
 
 
11
  del st.session_state.product
12
  del st.session_state.gender
13
  del st.session_state.profession
14
  del st.session_state.hobby
15
- st.experimental_rerun()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
 
 
 
 
 
 
 
 
 
 
 
17
  # # Create two columns
18
  # col1, col2 = st.columns(2)
19
 
20
  # # Place a form in each column
21
  # with col1:
22
- with st.form("my_input"):
23
- st.write("Input")
24
- # product
25
- product=st.text_input("product", key="product")
26
- # gender
27
- gender=st.radio("gender", ["male", "female"], key="gender")
28
- # profession
29
- profession=st.text_input("profession", key="profession")
30
- # hobby
31
- hobby=st.text_input("hobby", key="hobby")
32
- # Every form must have a submit button.
33
- btn1, btn2=st.columns(2)
34
- with btn1:
35
- # submitted = st.form_submit_button(label='Submit', on_click=submit_callback)
36
- submitted = st.form_submit_button(label='Submit')
37
- with btn2:
38
- clear = st.form_submit_button(label='Clear', on_click=delete_callback)
39
 
40
- # with col2:
41
- _LOREM_IPSUM = "product" + st.session_state.product + "\n"
42
- + "gender" + st.session_state.gender + "\n"
43
- + "profession" + st.session_state.profession + "\n"
44
- + "hobby" + st.session_state.hobby +"\n"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
- def stream_data():
47
- for word in _LOREM_IPSUM.split(" "):
48
- yield word + " "
49
- time.sleep(0.02)
 
 
50
 
51
- if st.button("Stream data"):
52
- st.write_stream(stream_data)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
 
58
 
 
2
  import time
3
 
4
  # def submit_callback():
5
+ # st.session_state.clicked = False
6
+ # handle the user_input here
7
+ # st.write("Product: " + st.session_state.product)
8
+ # st.write("Gender: " + st.session_state.gender)
9
+ # st.write("Profession: " + st.session_state.profession)
10
+ # st.write("Hobby: "+ st.session_state.hobby)
11
+
12
+
13
+ col1, col2=st.columns(2)
14
+ with col1:
15
+ with st.container(height=500):
16
+ with st.form("my_input", clear_on_submit=True, border=False):
17
+ st.write("Input")
18
+ # product
19
+ product=st.text_input("product", key="product")
20
+ # gender
21
+ gender=st.radio("gender", ["male", "female"], key="gender")
22
+ # profession
23
+ profession=st.text_input("profession", key="profession")
24
+ # hobby
25
+ hobby=st.text_input("hobby", key="hobby")
26
+ # Every form must have a submit button.
27
+ # submitted = st.form_submit_button(label='Submit', on_click=submit_callback)
28
+ submitted = st.form_submit_button(label='Submit')
29
+ with col2:
30
+ if submitted:
31
+ with st.spinner('Wait for it...'):
32
+ time.sleep(5)
33
+ with st.container(height=500):
34
+ placeholder = st.empty()
35
+ # Replace the chart with several elements:
36
+ with placeholder.container():
37
+ st.write("Product: " + st.session_state.product)
38
+ st.write("Gender: " + st.session_state.gender)
39
+ st.write("Profession: " + st.session_state.profession)
40
+ st.write("Hobby: "+ st.session_state.hobby)
41
+
42
+ if 'clicked' not in st.session_state:
43
+ st.session_state.clicked = False
44
+
45
+ def click_button():
46
+ st.session_state.clicked = True
47
 
48
+ st.button('Clear', on_click=click_button)
49
+
50
+ if st.session_state.clicked:
51
+ # The message and nested widget will remain on the page
52
  del st.session_state.product
53
  del st.session_state.gender
54
  del st.session_state.profession
55
  del st.session_state.hobby
56
+ del st.session_state.clicked
57
+ if submitted:
58
+ placeholder.empty()
59
+
60
+
61
+
62
+ # Clear all those elements:
63
+ # placeholder.empty()
64
+
65
+ # if clear:
66
+ # del st.session_state.product
67
+ # del st.session_state.gender
68
+ # del st.session_state.profession
69
+ # del st.session_state.hobby
70
+ # placeholder.empty()
71
+
72
+ # container1 = st.container(border=True)
73
 
74
+ # col1, col2 = st.columns(2)
75
+ # with col1:
76
+ # container1 = col1.container(height=3000, )
77
+
78
+ # with col2:
79
+ # container2 = col2.container(height=300)
80
+
81
+ # placeholder = st.empty()
82
+
83
+
84
+ # placeholder = st.empty()
85
  # # Create two columns
86
  # col1, col2 = st.columns(2)
87
 
88
  # # Place a form in each column
89
  # with col1:
90
+ # def submit_callback():
91
+ # st.write("Product: " + st.session_state.product)
92
+ # st.write("Gender: " + st.session_state.gender)
93
+ # st.write("Profession: " + st.session_state.profession)
94
+ # st.write("Hobby: "+ st.session_state.hobby)
 
 
 
 
 
 
 
 
 
 
 
 
95
 
96
+ # def delete_callback():
97
+ # del st.session_state.product
98
+ # del st.session_state.gender
99
+ # del st.session_state.profession
100
+ # del st.session_state.hobby
101
+ # placeholder.empty()
102
+
103
+ # import streamlit as st
104
+ # import time
105
+
106
+ # class SessionState:
107
+ # def __init__(self):
108
+ # self.product = ""
109
+ # self.gender = ""
110
+ # self.profession = ""
111
+ # self.hobby = ""
112
+
113
+ # state = SessionState()
114
+
115
+ # def submit_callback():
116
+ # with output_placeholder.container():
117
+ # st.write("Product: " + state.product)
118
+ # st.write("Gender: " + state.gender)
119
+ # st.write("Profession: " + state.profession)
120
+ # st.write("Hobby: "+ state.hobby)
121
+
122
+ # def delete_callback():
123
+ # state.product = ""
124
+ # state.gender = ""
125
+ # state.profession = ""
126
+ # state.hobby = ""
127
+ # output_placeholder.empty()
128
+
129
+ # form_placeholder = st.empty()
130
+ # output_placeholder = st.empty()
131
+
132
+ # submitted = False
133
+ # clear = False
134
+
135
+ # with form_placeholder.form("my_form", clear_on_submit=True):
136
+ # st.write("Input")
137
+ # # product
138
+ # state.product = st.text_input("product", value=state.product, key="product")
139
+ # # gender
140
+ # state.gender = st.radio("gender", ["male", "female"], value=state.gender, key="gender")
141
+ # # profession
142
+ # state.profession = st.text_input("profession", value=state.profession, key="profession")
143
+ # # hobby
144
+ # state.hobby = st.text_input("hobby", value=state.hobby, key="hobby")
145
+ # # Every form must have a submit button.
146
+ # btn1, btn2=st.columns(2)
147
+ # with btn1:
148
+ # submitted = st.form_submit_button(label='Submit')
149
+ # with btn2:
150
+ # clear = st.form_submit_button(label='Clear')
151
+
152
+ # if clear:
153
+ # delete_callback()
154
+ # if submitted:
155
+ # submit_callback()
156
+
157
+
158
+ # def submit_callback():
159
+ # with output_placeholder.container():
160
+ # st.write("Product: " + st.session_state.product)
161
+ # st.write("Gender: " + st.session_state.gender)
162
+ # st.write("Profession: " + st.session_state.profession)
163
+ # st.write("Hobby: "+ st.session_state.hobby)
164
 
165
+ # def delete_callback():
166
+ # del st.session_state.product
167
+ # del st.session_state.gender
168
+ # del st.session_state.profession
169
+ # del st.session_state.hobby
170
+ # output_placeholder.empty()
171
 
172
+ # form_placeholder = st.empty()
173
+ # output_placeholder = st.empty()
174
+
175
+ # with form_placeholder.form("my_input", clear_on_submit=True):
176
+ # st.write("Input")
177
+ # # product
178
+ # product=st.text_input("product", key="product")
179
+ # # gender
180
+ # gender=st.radio("gender", ["male", "female"], key="gender")
181
+ # # profession
182
+ # profession=st.text_input("profession", key="profession")
183
+ # # hobby
184
+ # hobby=st.text_input("hobby", key="hobby")
185
+ # # Every form must have a submit button.
186
+ # btn1, btn2=st.columns(2)
187
+ # with btn1:
188
+ # submitted = st.form_submit_button(label='Submit', on_click=submit_callback)
189
+ # # submitted = st.form_submit_button(label='Submit')
190
+ # with btn2:
191
+ # clear = st.form_submit_button(label='Clear', on_click=delete_callback)
192
+ # if submitted:
193
+ # # handle the user_input here
194
+ # st.write("Product: " + st.session_state.product)
195
+ # st.write("Gender: " + st.session_state.gender)
196
+ # st.write("Profession: " + st.session_state.profession)
197
+ # st.write("Hobby: "+ st.session_state.hobby)
198
+
199
+ # if clear:
200
+ # del st.session_state.product
201
+ # del st.session_state.gender
202
+ # del st.session_state.profession
203
+ # del st.session_state.hobby
204
+ # placeholder.empty()
205
+
206
+
207
+
208
+
209
+ # # with col2:
210
+ # _LOREM_IPSUM = (
211
+ # "product" + str(st.session_state.product) + "\n"
212
+ # + "gender" + str(st.session_state.gender) + "\n"
213
+ # + "profession" + str(st.session_state.profession) + "\n"
214
+ # + "hobby" + str(st.session_state.hobby) +"\n"
215
+ # )
216
+
217
+
218
+ # def stream_data():
219
+ # for word in _LOREM_IPSUM.split(" "):
220
+ # yield word + " "
221
+ # time.sleep(0.02)
222
+
223
+ # if st.button("Stream data"):
224
+ # st.write_stream(stream_data)
225
+ # placeholder = st.empty()
226
+
227
+ # with placeholder.container():
228
+ # st.write("Hello")
229
 
230
 
231
+ # import streamlit as st
232
+
233
+ # class SessionState:
234
+ # def __init__(self):
235
+ # self.input_text = ""
236
+
237
+ # state = SessionState()
238
+
239
+ # with st.form("my_form"):
240
+ # state.input_text = st.text_input("Enter something:", value=state.input_text)
241
+ # clear_button = st.form_submit_button("Clear")
242
+ # submit_button = st.form_submit_button("Submit")
243
+
244
+ # if clear_button:
245
+ # state.input_text = ""
246
+ # if submit_button:
247
+ # # handle the user_input here
248
+ # st.write(f"You submitted: {state.input_text}")
249
+
250
+ # import streamlit as st
251
+ # import time
252
+
253
+ # class SessionState:
254
+ # def __init__(self):
255
+ # self.product = ""
256
+ # self.gender = ""
257
+ # self.profession = ""
258
+ # self.hobby = ""
259
+
260
+ # state = SessionState()
261
+
262
+ # def submit_callback():
263
+ # output_placeholder.write("Product: " + state.product)
264
+ # output_placeholder.write("Gender: " + state.gender)
265
+ # output_placeholder.write("Profession: " + state.profession)
266
+ # output_placeholder.write("Hobby: "+ state.hobby)
267
 
268
+ # def delete_callback():
269
+ # state.product = ""
270
+ # state.gender = ""
271
+ # state.profession = ""
272
+ # state.hobby = ""
273
+ # output_placeholder.empty()
274
+
275
+ # form_placeholder = st.empty()
276
+ # output_placeholder = st.empty()
277
+
278
+ # with form_placeholder.form("my_form"):
279
+ # st.write("Input")
280
+ # # product
281
+ # state.product = st.text_input("product", value=state.product, key="product")
282
+ # # gender
283
+ # state.gender = st.radio("gender", ["male", "female"], value=state.gender, key="gender")
284
+ # # profession
285
+ # state.profession = st.text_input("profession", value=state.profession, key="profession")
286
+ # # hobby
287
+ # state.hobby = st.text_input("hobby", value=state.hobby, key="hobby")
288
+ # # Every form must have a submit button.
289
+ # btn1, btn2=st.columns(2)
290
+ # with btn1:
291
+ # submitted = st.form_submit_button(label='Submit')
292
+ # with btn2:
293
+ # clear = st.form_submit_button(label='Clear')
294
+
295
+ # if clear:
296
+ # delete_callback()
297
+ # if submitted:
298
+ # # handle the user_input here
299
+ # submit_callback()
300
 
301
 
302