ui.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. page_js = f.read()
  10. class ToolButton(gr.Button, gr.components.FormComponent):
  11. """Small button with single emoji as text, fits inside gradio forms"""
  12. def __init__(self, **kwargs):
  13. super().__init__(variant="tool", **kwargs)
  14. def get_block_name(self):
  15. return "button"
  16. def create_refresh_button(refresh_component, refresh_method, refreshed_args, elem_id):
  17. def refresh():
  18. refresh_method()
  19. args = refreshed_args() if callable(refreshed_args) else refreshed_args
  20. for k, v in args.items():
  21. setattr(refresh_component, k, v)
  22. return gr.update(**(args or {}))
  23. refresh_button = ToolButton(value=refresh_symbol, elem_id=elem_id)
  24. refresh_button.click(
  25. fn=refresh,
  26. inputs=[],
  27. outputs=[refresh_component]
  28. )
  29. return refresh_button