ui.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. from pathlib import Path
  2. import gradio as gr
  3. refresh_symbol = '\U0001f504' # 🔄
  4. with open(Path(__file__).resolve().parent / '../css/main.css', 'r') as f:
  5. css = f.read()
  6. with open(Path(__file__).resolve().parent / '../css/chat.css', 'r') as f:
  7. chat_css = f.read()
  8. with open(Path(__file__).resolve().parent / '../css/main.js', 'r') as f:
  9. main_js = f.read()
  10. with open(Path(__file__).resolve().parent / '../css/chat.js', 'r') as f:
  11. chat_js = f.read()
  12. class ToolButton(gr.Button, gr.components.FormComponent):
  13. """Small button with single emoji as text, fits inside gradio forms"""
  14. def __init__(self, **kwargs):
  15. super().__init__(variant="tool", **kwargs)
  16. def get_block_name(self):
  17. return "button"
  18. def create_refresh_button(refresh_component, refresh_method, refreshed_args, elem_id):
  19. def refresh():
  20. refresh_method()
  21. args = refreshed_args() if callable(refreshed_args) else refreshed_args
  22. for k, v in args.items():
  23. setattr(refresh_component, k, v)
  24. return gr.update(**(args or {}))
  25. refresh_button = ToolButton(value=refresh_symbol, elem_id=elem_id)
  26. refresh_button.click(
  27. fn=refresh,
  28. inputs=[],
  29. outputs=[refresh_component]
  30. )
  31. return refresh_button