idan shenfeld commited on
Commit
e642d6d
·
1 Parent(s): 57b3790

fix bug in dropdown

Browse files
Files changed (1) hide show
  1. app/app.py +16 -3
app/app.py CHANGED
@@ -490,6 +490,8 @@ def close_add_language_modal():
490
 
491
  def save_new_language(lang_name, system_prompt):
492
  """Save the new language and system prompt to persistent storage if available, otherwise to local file."""
 
 
493
  # First determine where to save the file
494
  persistent_path = Path("/data/languages.json")
495
  local_path = Path(__file__).parent / "languages.json"
@@ -532,6 +534,9 @@ def save_new_language(lang_name, system_prompt):
532
  except Exception as e:
533
  print(f"Error updating local backup: {e}")
534
 
 
 
 
535
  # Update the dropdown choices
536
  new_choices = list(LANGUAGES.keys())
537
 
@@ -610,7 +615,7 @@ with gr.Blocks(css=css) as demo:
610
  """)
611
 
612
  with gr.Column():
613
- gr.Markdown("Select your language or add a new one:") # Label on its own line
614
  with gr.Row():
615
  language = gr.Dropdown(
616
  choices=list(load_languages().keys()),
@@ -745,12 +750,20 @@ with gr.Blocks(css=css) as demo:
745
  )
746
 
747
  def on_app_load():
748
- return str(uuid.uuid4())
 
 
 
 
 
 
 
 
749
 
750
  demo.load(
751
  fn=on_app_load,
752
  inputs=None,
753
- outputs=session_id
754
  )
755
 
756
  add_language_btn.click(
 
490
 
491
  def save_new_language(lang_name, system_prompt):
492
  """Save the new language and system prompt to persistent storage if available, otherwise to local file."""
493
+ global LANGUAGES # Access the global variable
494
+
495
  # First determine where to save the file
496
  persistent_path = Path("/data/languages.json")
497
  local_path = Path(__file__).parent / "languages.json"
 
534
  except Exception as e:
535
  print(f"Error updating local backup: {e}")
536
 
537
+ # Update the global LANGUAGES variable with the new data
538
+ LANGUAGES.update({lang_name: system_prompt})
539
+
540
  # Update the dropdown choices
541
  new_choices = list(LANGUAGES.keys())
542
 
 
615
  """)
616
 
617
  with gr.Column():
618
+ gr.Markdown("Select your language or add a new one:")
619
  with gr.Row():
620
  language = gr.Dropdown(
621
  choices=list(load_languages().keys()),
 
750
  )
751
 
752
  def on_app_load():
753
+ global LANGUAGES
754
+ # Force reload languages from file
755
+ LANGUAGES = load_languages()
756
+
757
+ # Get the list of languages
758
+ language_choices = list(LANGUAGES.keys())
759
+
760
+ # Return both the session ID and available language choices
761
+ return str(uuid.uuid4()), gr.Dropdown(choices=language_choices, value=language_choices[0])
762
 
763
  demo.load(
764
  fn=on_app_load,
765
  inputs=None,
766
+ outputs=[session_id, language]
767
  )
768
 
769
  add_language_btn.click(