idan shenfeld commited on
Commit
9bee81e
·
1 Parent(s): 83e1f30

another bugfix for cookies

Browse files
Files changed (1) hide show
  1. app/app.py +15 -7
app/app.py CHANGED
@@ -698,14 +698,21 @@ button.yellow-btn {
698
 
699
  def get_config(request: gr.Request):
700
  """Get configuration from cookies"""
701
- config = {"feel_consent": "false"} # Default value
702
- if request and 'feel_consent' in request.cookies:
703
- config["feel_consent"] = request.cookies['feel_consent']
704
- return config["feel_consent"] == "true" # Return boolean
 
 
 
 
 
 
705
 
706
  def initialize_consent_status(request: gr.Request):
707
- """Initialize consent status from cookies"""
708
- return get_config(request)
 
709
 
710
  js = '''function js(){
711
  window.set_cookie = function(key, value){
@@ -888,6 +895,7 @@ with gr.Blocks(css=css, js=js) as demo:
888
  demo.load(
889
  fn=initialize_consent_status,
890
  outputs=user_consented,
 
891
  ).then(
892
  fn=update_visibility,
893
  inputs=user_consented,
@@ -898,7 +906,7 @@ with gr.Blocks(css=css, js=js) as demo:
898
  consent_btn.click(
899
  fn=lambda: True,
900
  outputs=user_consented,
901
- js="(value) => set_cookie('feel_consent', 'true')"
902
  ).then(
903
  fn=update_visibility,
904
  inputs=user_consented,
 
698
 
699
  def get_config(request: gr.Request):
700
  """Get configuration from cookies"""
701
+ config = {
702
+ "feel_consent": "false",
703
+ }
704
+
705
+ if request and request.cookies:
706
+ for key in config.keys():
707
+ if key in request.cookies:
708
+ config[key] = request.cookies[key]
709
+
710
+ return config["feel_consent"] == "true"
711
 
712
  def initialize_consent_status(request: gr.Request):
713
+ """Initialize consent status and language preference from cookies"""
714
+ has_consent = get_config(request)
715
+ return has_consent
716
 
717
  js = '''function js(){
718
  window.set_cookie = function(key, value){
 
895
  demo.load(
896
  fn=initialize_consent_status,
897
  outputs=user_consented,
898
+ js=js
899
  ).then(
900
  fn=update_visibility,
901
  inputs=user_consented,
 
906
  consent_btn.click(
907
  fn=lambda: True,
908
  outputs=user_consented,
909
+ js="() => set_cookie('feel_consent', 'true')"
910
  ).then(
911
  fn=update_visibility,
912
  inputs=user_consented,