Spaces:
Sleeping
Sleeping
idan shenfeld
commited on
Commit
Β·
7ca0870
1
Parent(s):
d2680fa
fix bug in dropdown
Browse files- app/app.py +48 -20
app/app.py
CHANGED
@@ -508,6 +508,8 @@ def close_add_language_modal():
|
|
508 |
|
509 |
def save_new_language(lang_name, system_prompt):
|
510 |
"""Save the new language and system prompt to persistent storage if available, otherwise to local file."""
|
|
|
|
|
511 |
# First determine where to save the file
|
512 |
persistent_path = Path("/data/languages.json")
|
513 |
local_path = Path(__file__).parent / "languages.json"
|
@@ -550,6 +552,9 @@ def save_new_language(lang_name, system_prompt):
|
|
550 |
except Exception as e:
|
551 |
print(f"Error updating local backup: {e}")
|
552 |
|
|
|
|
|
|
|
553 |
# Update the dropdown choices
|
554 |
new_choices = list(LANGUAGES.keys())
|
555 |
|
@@ -625,24 +630,39 @@ with gr.Blocks(css=css) as demo:
|
|
625 |
- π/π Like or dislike a message
|
626 |
- π Regenerate a message
|
627 |
|
628 |
-
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
646 |
|
647 |
session_id = gr.Textbox(
|
648 |
interactive=False,
|
@@ -748,12 +768,20 @@ with gr.Blocks(css=css) as demo:
|
|
748 |
)
|
749 |
|
750 |
def on_app_load():
|
751 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
752 |
|
753 |
demo.load(
|
754 |
fn=on_app_load,
|
755 |
inputs=None,
|
756 |
-
outputs=session_id
|
757 |
)
|
758 |
|
759 |
add_language_btn.click(
|
|
|
508 |
|
509 |
def save_new_language(lang_name, system_prompt):
|
510 |
"""Save the new language and system prompt to persistent storage if available, otherwise to local file."""
|
511 |
+
global LANGUAGES # Access the global variable
|
512 |
+
|
513 |
# First determine where to save the file
|
514 |
persistent_path = Path("/data/languages.json")
|
515 |
local_path = Path(__file__).parent / "languages.json"
|
|
|
552 |
except Exception as e:
|
553 |
print(f"Error updating local backup: {e}")
|
554 |
|
555 |
+
# Update the global LANGUAGES variable with the new data
|
556 |
+
LANGUAGES.update({lang_name: system_prompt})
|
557 |
+
|
558 |
# Update the dropdown choices
|
559 |
new_choices = list(LANGUAGES.keys())
|
560 |
|
|
|
630 |
- π/π Like or dislike a message
|
631 |
- π Regenerate a message
|
632 |
|
633 |
+
""")
|
634 |
+
|
635 |
+
with gr.Column():
|
636 |
+
gr.Markdown("Select your language or add a new one:")
|
637 |
+
with gr.Row():
|
638 |
+
language = gr.Dropdown(
|
639 |
+
choices=list(load_languages().keys()),
|
640 |
+
container=False,
|
641 |
+
show_label=False,
|
642 |
+
scale=8
|
643 |
+
)
|
644 |
+
add_language_btn = gr.Button(
|
645 |
+
"+",
|
646 |
+
elem_id="add-language-btn",
|
647 |
+
size="sm"
|
648 |
+
)
|
649 |
+
|
650 |
+
|
651 |
+
# Create a hidden group instead of a modal
|
652 |
+
with gr.Group(visible=False) as add_language_modal:
|
653 |
+
gr.Markdown(" Add New Language")
|
654 |
+
new_lang_name = gr.Textbox(label="Language Name", lines=1)
|
655 |
+
new_system_prompt = gr.Textbox(label="System Prompt", lines=4)
|
656 |
+
with gr.Row():
|
657 |
+
with gr.Column(scale=1):
|
658 |
+
save_language_btn = gr.Button("Save")
|
659 |
+
# with gr.Column(scale=0.2):
|
660 |
+
# pass # Empty column as spacer
|
661 |
+
with gr.Column(scale=1):
|
662 |
+
cancel_language_btn = gr.Button("Cancel")
|
663 |
+
|
664 |
+
# Add a hidden HTML component for page refresh
|
665 |
+
refresh_html = gr.HTML(visible=False)
|
666 |
|
667 |
session_id = gr.Textbox(
|
668 |
interactive=False,
|
|
|
768 |
)
|
769 |
|
770 |
def on_app_load():
|
771 |
+
global LANGUAGES
|
772 |
+
# Force reload languages from file
|
773 |
+
LANGUAGES = load_languages()
|
774 |
+
|
775 |
+
# Get the list of languages
|
776 |
+
language_choices = list(LANGUAGES.keys())
|
777 |
+
|
778 |
+
# Return both the session ID and available language choices
|
779 |
+
return str(uuid.uuid4()), gr.Dropdown(choices=language_choices, value=language_choices[0])
|
780 |
|
781 |
demo.load(
|
782 |
fn=on_app_load,
|
783 |
inputs=None,
|
784 |
+
outputs=[session_id, language]
|
785 |
)
|
786 |
|
787 |
add_language_btn.click(
|