santhosh97 commited on
Commit
71960d7
·
1 Parent(s): 28d8d3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -52
app.py CHANGED
@@ -38,43 +38,22 @@ _S3_PATH_OUTPUT = "s3://gretel-image-synthetics-use2/data/{identifier}/{image_ty
38
  # Eventually may want to move everything into functions and have a
39
  # if __name__ == "main" setup instead of everything inline.
40
 
41
- if "key" not in st.session_state:
42
- st.session_state["key"] = uuid.uuid4().hex
43
-
44
- if "captcha_bool" not in st.session_state:
45
- st.session_state["captcha_bool"] = False
46
-
47
- if "model_inputs" not in st.session_state:
48
- st.session_state["model_inputs"] = None
49
 
50
- if (
51
- "s3_face_file_path" not in st.session_state
52
- and "s3_theme_file_path" not in st.session_state
53
- ):
54
- st.session_state["s3_face_file_path"] = None
55
- st.session_state["s3_theme_file_path"] = None
56
 
57
- if "view" not in st.session_state:
58
- st.session_state["view"] = False
59
-
60
- if "train_view" not in st.session_state:
61
- st.session_state["train_view"] = False
62
-
63
- if "captcha_response" not in st.session_state:
64
- st.session_state["captcha_response"] = None
65
 
66
  if "captcha" not in st.session_state:
67
  st.session_state["captcha"] = {}
68
 
69
- if "login" not in st.session_state:
70
- st.session_state["login"] = None
71
-
72
- if "user_auth_sess" not in st.session_state:
73
- st.session_state["user_auth_sess"] = False
74
-
75
- if "user_email" not in st.session_state:
76
- st.session_state["email_provided"] = True
77
-
78
  def callback():
79
  st.session_state["button_clicked"] = True
80
 
@@ -232,26 +211,26 @@ def verify_captcha(captcha_id, captcha_response):
232
  return {"error": "Failed to verify captcha"}
233
 
234
  def train_model(model_inputs):
235
- # Use banana backend
236
  api_key = "03cdd72e-5c04-4207-bd6a-fd5712c1740e"
237
  model_key = "1a3b4ce5-164f-4efb-9f4a-c2ad3a930d0b"
238
- st.markdown(str(model_inputs))
239
  _ = banana.run(api_key, model_key, model_inputs)
240
 
241
- if st.session_state["email_provided"]:
 
242
  user_email_input = st.empty()
243
- with user_email_input.form(key='user_auth'):
244
  text_input = st.text_input(label='Please Enter Your Email')
245
  submit_button = st.form_submit_button(label='Submit')
246
  if submit_button:
247
  st.session_state["user_auth_sess"] = True
248
- st.session_state["email_provided"] = False
249
- send_email(text_input, str(st.session_state["key"]))
250
-
 
 
251
  if st.session_state["user_auth_sess"]:
252
  user_auth = st.empty()
253
- user_email_input.empty()
254
- with user_auth.form("one-code"):
255
  text_input = st.text_input(label='Please Input One Time Code')
256
  submit_button = st.form_submit_button(label='Submit')
257
  if submit_button:
@@ -260,12 +239,12 @@ if st.session_state["user_auth_sess"]:
260
  else:
261
  st.markdown("Please Enter Correct Code!")
262
 
 
263
  if st.session_state["login"]:
264
  identifier = st.session_state["key"]
265
  user_auth.empty()
266
- user_email_input.empty()
267
  face_images = st.empty()
268
- with face_images.form("my_form"):
269
  uploaded_files = st.file_uploader(
270
  "Choose image files", accept_multiple_files=True, type=["png", "jpg", "jpeg"]
271
  )
@@ -276,7 +255,11 @@ if st.session_state["login"]:
276
  identifier, uploaded_files, "face"
277
  )
278
  st.success(f'Uploading {len(uploaded_files)} files done!')
 
279
 
 
 
 
280
  preset_theme_images = st.empty()
281
  with preset_theme_images.form("choose-preset-theme"):
282
  img = image_select(
@@ -310,6 +293,7 @@ if st.session_state["login"]:
310
  "num_images": 50,
311
  }
312
  st.success("Success!")
 
313
  with col2:
314
  submitted_4 = st.form_submit_button(
315
  "If none of the themes interest you, click here!"
@@ -341,19 +325,18 @@ if st.session_state["login"]:
341
  "num_images": 50,
342
  }
343
  st.success('Done!')
 
344
 
 
 
 
 
 
345
  train = st.empty()
346
  with train.form("training"):
347
- col1, col3, col2 = st.columns(3)
348
- with col1:
349
- email = st.text_input("Enter Email")
350
- with col2:
351
- submitted = st.form_submit_button("Train Model!")
352
  if submitted:
353
- if not email:
354
- st.markdown('Please input an email!')
355
- else:
356
- st.session_state["captcha_bool"] = True
357
 
358
  if st.session_state["captcha_bool"]:
359
  captcha_form = st.empty()
@@ -380,7 +363,7 @@ if st.session_state["login"]:
380
  display_captcha = False
381
  with st.spinner("Model Fine Tuning..."):
382
  st.session_state["model_inputs"]["identifier"] = st.session_state["key"]
383
- st.session_state["model_inputs"]["email"] = email
384
  s3_output_path = _S3_PATH_OUTPUT.format(identifier=st.session_state["key"], image_type="generated")
385
  # The backend does not have s3 credentials, so generate
386
  # presigned urls for the backend to use to write and read
 
38
  # Eventually may want to move everything into functions and have a
39
  # if __name__ == "main" setup instead of everything inline.
40
 
41
+ bool_session_variables = ['captcha_bool', 'view', 'train_view', 'login', 'user_auth_sess', 'face_images_uploaded', 'theme_images_uploaded']
42
+ for var in bool_session_variables:
43
+ if var not in st.session_state:
44
+ st.session_state[var] = False
 
 
 
 
45
 
46
+ obj_session_variables = ['s3_face_file_path', 's3_theme_file_path', 'captcha_response', 'user_email']
47
+ for var in obj_session_variables:
48
+ if var not in st.session_state:
49
+ st.session_state[var] = None
 
 
50
 
51
+ if "key" not in st.session_state:
52
+ st.session_state["key"] = uuid.uuid4().hex
 
 
 
 
 
 
53
 
54
  if "captcha" not in st.session_state:
55
  st.session_state["captcha"] = {}
56
 
 
 
 
 
 
 
 
 
 
57
  def callback():
58
  st.session_state["button_clicked"] = True
59
 
 
211
  return {"error": "Failed to verify captcha"}
212
 
213
  def train_model(model_inputs):
 
214
  api_key = "03cdd72e-5c04-4207-bd6a-fd5712c1740e"
215
  model_key = "1a3b4ce5-164f-4efb-9f4a-c2ad3a930d0b"
 
216
  _ = banana.run(api_key, model_key, model_inputs)
217
 
218
+ #first page - user provides email
219
+ if st.session_state["user_email"] is None:
220
  user_email_input = st.empty()
221
+ with user_email_input.form(key='user_email_provided'):
222
  text_input = st.text_input(label='Please Enter Your Email')
223
  submit_button = st.form_submit_button(label='Submit')
224
  if submit_button:
225
  st.session_state["user_auth_sess"] = True
226
+ st.session_state["user_email"] = text_input
227
+ send_email(st.session_state["user_email"], str(st.session_state["key"]))
228
+ user_email_input.empty()
229
+
230
+ #second page - user inputs one time code
231
  if st.session_state["user_auth_sess"]:
232
  user_auth = st.empty()
233
+ with user_auth.form("one-time-code"):
 
234
  text_input = st.text_input(label='Please Input One Time Code')
235
  submit_button = st.form_submit_button(label='Submit')
236
  if submit_button:
 
239
  else:
240
  st.markdown("Please Enter Correct Code!")
241
 
242
+ #third page - user inputs face images
243
  if st.session_state["login"]:
244
  identifier = st.session_state["key"]
245
  user_auth.empty()
 
246
  face_images = st.empty()
247
+ with face_images.form("face_images_upload"):
248
  uploaded_files = st.file_uploader(
249
  "Choose image files", accept_multiple_files=True, type=["png", "jpg", "jpeg"]
250
  )
 
255
  identifier, uploaded_files, "face"
256
  )
257
  st.success(f'Uploading {len(uploaded_files)} files done!')
258
+ st.session_state["face_images_uploaded"] = True
259
 
260
+ #fourth page - user inputs theme images
261
+ if st.session_state["face_images_uploaded"]:
262
+ face_images.empty()
263
  preset_theme_images = st.empty()
264
  with preset_theme_images.form("choose-preset-theme"):
265
  img = image_select(
 
293
  "num_images": 50,
294
  }
295
  st.success("Success!")
296
+ st.session_state["theme_images_uploaded"] = True
297
  with col2:
298
  submitted_4 = st.form_submit_button(
299
  "If none of the themes interest you, click here!"
 
325
  "num_images": 50,
326
  }
327
  st.success('Done!')
328
+ st.session_state["theme_images_uploaded"] = True
329
 
330
+ #fifth page - user enters captcha and trains model
331
+ if st.session_state["theme_images_uploaded"]:
332
+ if st.session_state["view"]:
333
+ custom_theme_images.empty()
334
+ preset_theme_images.empty()
335
  train = st.empty()
336
  with train.form("training"):
337
+ submitted = st.form_submit_button("Train Model!")
 
 
 
 
338
  if submitted:
339
+ st.session_state["captcha_bool"] = True
 
 
 
340
 
341
  if st.session_state["captcha_bool"]:
342
  captcha_form = st.empty()
 
363
  display_captcha = False
364
  with st.spinner("Model Fine Tuning..."):
365
  st.session_state["model_inputs"]["identifier"] = st.session_state["key"]
366
+ st.session_state["model_inputs"]["email"] = st.session_state["user_email"]
367
  s3_output_path = _S3_PATH_OUTPUT.format(identifier=st.session_state["key"], image_type="generated")
368
  # The backend does not have s3 credentials, so generate
369
  # presigned urls for the backend to use to write and read