Skip to content

Commit

Permalink
2 choice Boxes are greyed out if one is used
Browse files Browse the repository at this point in the history
  • Loading branch information
Bikatr7 committed Sep 15, 2024
1 parent 35c7175 commit 40cb362
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions webgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import typing
import base64
import asyncio
import time
import os
import json

Expand Down Expand Up @@ -89,6 +90,9 @@ class KudasaiGUI:
"deepl_formality": lines[81-1].strip(),
}

last_text_change = 0
debounce_delay = 2 ## 2 seconds

##-------------------start-of-build_gui()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

def build_gui(self) -> None:
Expand Down Expand Up @@ -2088,6 +2092,58 @@ def switch_translator_api_key_type(translation_method:str) -> str:
self.send_to_translator_button.click(fn=send_to_translator_button,
inputs=[self.preprocessing_output_field],
outputs=[self.input_text_translator])

##-------------------start-of-toggle_inputs()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

def toggle_knowledge_base_inputs(file_input, dir_input):
return gr.update(interactive=not bool(file_input)), gr.update(interactive=not bool(dir_input))

self.input_knowledge_base_file.change(
toggle_knowledge_base_inputs,
inputs=[self.input_knowledge_base_file, self.input_knowledge_base_directory],
outputs=[self.input_knowledge_base_directory, self.input_knowledge_base_file]
)

self.input_knowledge_base_directory.change(
toggle_knowledge_base_inputs,
inputs=[self.input_knowledge_base_file, self.input_knowledge_base_directory],
outputs=[self.input_knowledge_base_directory, self.input_knowledge_base_file]
)

def toggle_text_inputs(file_input, text_input):
current_time = time.time()
if current_time - KudasaiGUI.last_text_change < KudasaiGUI.debounce_delay:
# If it's a text change and we're within the debounce period, don't update
return gr.update(), gr.update()
self.last_text_change = current_time
return gr.update(interactive=not bool(file_input)), gr.update(interactive=not bool(text_input))


## For preprocessor
self.input_txt_file_preprocessing.change(
toggle_text_inputs,
inputs=[self.input_txt_file_preprocessing, self.input_text_kairyou],
outputs=[self.input_text_kairyou, self.input_txt_file_preprocessing]
)

self.input_text_kairyou.change(
toggle_text_inputs,
inputs=[self.input_txt_file_preprocessing, self.input_text_kairyou],
outputs=[self.input_text_kairyou, self.input_txt_file_preprocessing]
)

## For translator
self.input_txt_file_translator.change(
toggle_text_inputs,
inputs=[self.input_txt_file_translator, self.input_text_translator],
outputs=[self.input_text_translator, self.input_txt_file_translator]
)

self.input_text_translator.change(
toggle_text_inputs,
inputs=[self.input_txt_file_translator, self.input_text_translator],
outputs=[self.input_text_translator, self.input_txt_file_translator]
)

##-------------------start-of-launch()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Expand Down

0 comments on commit 40cb362

Please sign in to comment.