Skip to content

Commit

Permalink
Fix the components error
Browse files Browse the repository at this point in the history
  • Loading branch information
snekkenull authored Jul 8, 2024
1 parent 6ac4099 commit 2f5e510
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,15 @@ def update_menu(visible):


def export_txt(strings):
os.makedirs("outputs", exist_ok=True)
base_count = len(glob(os.path.join("outputs", "*.txt")))
file_path = os.path.join("outputs", f"{base_count:06d}.txt")
with open(file_path, "w", encoding="utf-8") as f:
f.write(strings)
return gr.update(value=file_path, visible=True)

if strings:
os.makedirs("outputs", exist_ok=True)
base_count = len(glob(os.path.join("outputs", "*.txt")))
file_path = os.path.join("outputs", f"{base_count:06d}.txt")
with open(file_path, "w", encoding="utf-8") as f:
f.write(strings)
return gr.update(value=file_path, visible=True)
else:
return gr.update(visible=False)

def switch(source_lang, source_text, target_lang, output_final):
if output_final:
Expand All @@ -151,9 +153,11 @@ def close_btn_show():
return gr.update(visible=False), gr.update(visible=True)


def close_btn_hide(output_final):
if output_final:
def close_btn_hide(output_diff):
if output_diff:
return gr.update(visible=True), gr.update(visible=False)
else:
return gr.update(visible=False), gr.update(visible=True)


TITLE = """
Expand Down Expand Up @@ -377,11 +381,11 @@ def close_btn_hide(output_final):
outputs=[output_init, output_reflect, output_final, output_diff],
)
upload.upload(fn=read_doc, inputs=upload, outputs=source_text)
output_final.change(fn=export_txt, inputs=output_final, outputs=[export])
output_diff.change(fn=export_txt, inputs=output_final, outputs=[export])

submit.click(fn=close_btn_show, outputs=[clear, close])
output_final.change(
fn=close_btn_hide, inputs=output_final, outputs=[clear, close]
output_diff.change(
fn=close_btn_hide, inputs=output_diff, outputs=[clear, close]
)
close.click(fn=None, cancels=start_ta)

Expand Down

0 comments on commit 2f5e510

Please sign in to comment.