Shashank1406 commited on
Commit
22616a7
1 Parent(s): 874e0c2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -51
app.py CHANGED
@@ -419,56 +419,56 @@ def main():
419
  st.warning(
420
  'Plesase Process RFP Details to access this feature', icon="⚠️")
421
 
422
- if __name__ == "__main__":
423
- main()
424
-
425
  # if __name__ == "__main__":
426
- # print(localStorage.getItem('email'))
427
- # if localStorage.getItem('email'):
428
- # main()
429
- # else:
430
- # st.title("SIGN UP TO ACCESS THE APP!")
431
- # AUTHORIZE_ENDPOINT = "https://accounts.google.com/o/oauth2/v2/auth"
432
- # TOKEN_ENDPOINT = "https://oauth2.googleapis.com/token"
433
- # REVOKE_ENDPOINT = "https://oauth2.googleapis.com/revoke"
434
-
435
- # # create a button to start the OAuth2 flow
436
- # oauth2 = OAuth2Component(
437
- # CLIENT_ID,
438
- # CLIENT_SECRET,
439
- # AUTHORIZE_ENDPOINT,
440
- # TOKEN_ENDPOINT,
441
- # TOKEN_ENDPOINT,
442
- # REVOKE_ENDPOINT,
443
- # )
444
- # result = oauth2.authorize_button(
445
- # name="Continue with Google",
446
- # icon="https://www.google.com.tw/favicon.ico",
447
- # redirect_uri="https://huggingface.co/spaces/coffeebeans-ai/rfp_to_story",
448
- # scope="openid email profile",
449
- # key="google",
450
- # height=600,
451
- # width=500,
452
- # extras_params={"prompt": "consent", "access_type": "offline"},
453
- # use_container_width=False,
454
- # pkce="S256",
455
- # )
456
-
457
- # if result:
458
- # # decode the id_token jwt and get the user's email address
459
- # id_token = result["token"]["id_token"]
460
- # # verify the signature is an optional step for security
461
- # payload = id_token.split(".")[1]
462
- # # add padding to the payload if needed
463
- # payload += "=" * (-len(payload) % 4)
464
- # payload = json.loads(base64.b64decode(payload))
465
- # email = payload["email"]
466
- # st.session_state["auth"] = email
467
- # st.session_state["token"] = result["token"]
468
- # is_valid = validate_email(email)
469
- # if is_valid:
470
- # localStorage.setItem("email",email)
471
- # st.rerun()
472
- # else:
473
- # st.warning("Unauthorized. you are not authorized to access this app.")
 
 
 
474
 
 
419
  st.warning(
420
  'Plesase Process RFP Details to access this feature', icon="⚠️")
421
 
 
 
 
422
  # if __name__ == "__main__":
423
+ # main()
424
+
425
+ if __name__ == "__main__":
426
+ print(localStorage.getItem('email'))
427
+ if localStorage.getItem('email'):
428
+ main()
429
+ else:
430
+ st.title("SIGN UP TO ACCESS THE APP!")
431
+ AUTHORIZE_ENDPOINT = "https://accounts.google.com/o/oauth2/v2/auth"
432
+ TOKEN_ENDPOINT = "https://oauth2.googleapis.com/token"
433
+ REVOKE_ENDPOINT = "https://oauth2.googleapis.com/revoke"
434
+
435
+ # create a button to start the OAuth2 flow
436
+ oauth2 = OAuth2Component(
437
+ CLIENT_ID,
438
+ CLIENT_SECRET,
439
+ AUTHORIZE_ENDPOINT,
440
+ TOKEN_ENDPOINT,
441
+ TOKEN_ENDPOINT,
442
+ REVOKE_ENDPOINT,
443
+ )
444
+ result = oauth2.authorize_button(
445
+ name="Continue with Google",
446
+ icon="https://www.google.com.tw/favicon.ico",
447
+ redirect_uri="https://huggingface.co/spaces/coffeebeans-ai/rfp_to_story",
448
+ scope="openid email profile",
449
+ key="google",
450
+ height=600,
451
+ width=500,
452
+ extras_params={"prompt": "consent", "access_type": "offline"},
453
+ use_container_width=False,
454
+ pkce="S256",
455
+ )
456
+
457
+ if result:
458
+ # decode the id_token jwt and get the user's email address
459
+ id_token = result["token"]["id_token"]
460
+ # verify the signature is an optional step for security
461
+ payload = id_token.split(".")[1]
462
+ # add padding to the payload if needed
463
+ payload += "=" * (-len(payload) % 4)
464
+ payload = json.loads(base64.b64decode(payload))
465
+ email = payload["email"]
466
+ st.session_state["auth"] = email
467
+ st.session_state["token"] = result["token"]
468
+ is_valid = validate_email(email)
469
+ if is_valid:
470
+ localStorage.setItem("email",email)
471
+ st.rerun()
472
+ else:
473
+ st.warning("Unauthorized. you are not authorized to access this app.")
474