ui.py 873 B

123456789101112131415161718192021222324252627282930
  1. import gradio as gr
  2. refresh_symbol = '\U0001f504' # 🔄
  3. class ToolButton(gr.Button, gr.components.FormComponent):
  4. """Small button with single emoji as text, fits inside gradio forms"""
  5. def __init__(self, **kwargs):
  6. super().__init__(variant="tool", **kwargs)
  7. def get_block_name(self):
  8. return "button"
  9. def create_refresh_button(refresh_component, refresh_method, refreshed_args, elem_id):
  10. def refresh():
  11. refresh_method()
  12. args = refreshed_args() if callable(refreshed_args) else refreshed_args
  13. for k, v in args.items():
  14. setattr(refresh_component, k, v)
  15. return gr.update(**(args or {}))
  16. refresh_button = ToolButton(value=refresh_symbol, elem_id=elem_id)
  17. refresh_button.click(
  18. fn=refresh,
  19. inputs=[],
  20. outputs=[refresh_component]
  21. )
  22. return refresh_button