ui.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import gradio as gr
  2. refresh_symbol = '\U0001f504' # 🔄
  3. css = """
  4. .tabs.svelte-710i53 {
  5. margin-top: 0
  6. }
  7. .py-6 {
  8. padding-top: 2.5rem
  9. }
  10. .dark #refresh-button {
  11. background-color: #ffffff1f;
  12. }
  13. #refresh-button {
  14. flex: none;
  15. margin: 0;
  16. padding: 0;
  17. min-width: 50px;
  18. border: none;
  19. box-shadow: none;
  20. border-radius: 10px;
  21. background-color: #0000000d;
  22. }
  23. #download-label, #upload-label {
  24. min-height: 0
  25. }
  26. #accordion {
  27. }
  28. """
  29. chat_css = """
  30. .h-\[40vh\], .wrap.svelte-byatnx.svelte-byatnx.svelte-byatnx {
  31. height: 66.67vh
  32. }
  33. .gradio-container {
  34. max-width: 800px;
  35. margin-left: auto;
  36. margin-right: auto
  37. }
  38. .w-screen {
  39. width: unset
  40. }
  41. div.svelte-362y77>*, div.svelte-362y77>.form>* {
  42. flex-wrap: nowrap
  43. }
  44. """
  45. class ToolButton(gr.Button, gr.components.FormComponent):
  46. """Small button with single emoji as text, fits inside gradio forms"""
  47. def __init__(self, **kwargs):
  48. super().__init__(variant="tool", **kwargs)
  49. def get_block_name(self):
  50. return "button"
  51. def create_refresh_button(refresh_component, refresh_method, refreshed_args, elem_id):
  52. def refresh():
  53. refresh_method()
  54. args = refreshed_args() if callable(refreshed_args) else refreshed_args
  55. for k, v in args.items():
  56. setattr(refresh_component, k, v)
  57. return gr.update(**(args or {}))
  58. refresh_button = ToolButton(value=refresh_symbol, elem_id=elem_id)
  59. refresh_button.click(
  60. fn=refresh,
  61. inputs=[],
  62. outputs=[refresh_component]
  63. )
  64. return refresh_button