edit_metadata_ui.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from tts_webui.bark.npz_tools import load_npz, save_npz
  2. import gradio as gr
  3. import json
  4. def edit_metadata_ui(voice_file_name, metadata_display):
  5. with gr.Accordion(label="Edit Metadata", open=False):
  6. metadata_input = gr.Textbox(label="New Metadata", value="{}", lines=20)
  7. save_metadata_button = gr.Button(value="Save Metadata", variant="primary")
  8. def save_metadata(metadata_input, voice_file_name):
  9. metadata = json.loads(metadata_input)
  10. full_generation = load_npz(voice_file_name)
  11. save_npz(
  12. voice_file_name,
  13. {
  14. "coarse_prompt": full_generation["coarse_prompt"],
  15. "fine_prompt": full_generation["fine_prompt"],
  16. "semantic_prompt": full_generation["semantic_prompt"],
  17. },
  18. metadata=metadata,
  19. )
  20. return {
  21. metadata_display: gr.JSON(value=metadata),
  22. save_metadata_button: gr.Button(value="Saved"),
  23. }
  24. save_metadata_button.click(
  25. fn=save_metadata,
  26. inputs=[metadata_input, voice_file_name],
  27. outputs=[metadata_display, save_metadata_button],
  28. )
  29. metadata_input.change(
  30. fn=lambda: gr.Button(value="Save Metadata"), outputs=[save_metadata_button]
  31. )
  32. return metadata_input