ui.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. .dark svg {
  29. fill: white;
  30. }
  31. """
  32. chat_css = """
  33. .h-\[40vh\], .wrap.svelte-byatnx.svelte-byatnx.svelte-byatnx {
  34. height: 66.67vh
  35. }
  36. .gradio-container {
  37. max-width: 800px;
  38. margin-left: auto;
  39. margin-right: auto
  40. }
  41. .w-screen {
  42. width: unset
  43. }
  44. div.svelte-362y77>*, div.svelte-362y77>.form>* {
  45. flex-wrap: nowrap
  46. }
  47. /* fixes the API documentation in chat mode */
  48. .api-docs.svelte-1iguv9h.svelte-1iguv9h.svelte-1iguv9h {
  49. display: grid;
  50. }
  51. """
  52. class ToolButton(gr.Button, gr.components.FormComponent):
  53. """Small button with single emoji as text, fits inside gradio forms"""
  54. def __init__(self, **kwargs):
  55. super().__init__(variant="tool", **kwargs)
  56. def get_block_name(self):
  57. return "button"
  58. def create_refresh_button(refresh_component, refresh_method, refreshed_args, elem_id):
  59. def refresh():
  60. refresh_method()
  61. args = refreshed_args() if callable(refreshed_args) else refreshed_args
  62. for k, v in args.items():
  63. setattr(refresh_component, k, v)
  64. return gr.update(**(args or {}))
  65. refresh_button = ToolButton(value=refresh_symbol, elem_id=elem_id)
  66. refresh_button.click(
  67. fn=refresh,
  68. inputs=[],
  69. outputs=[refresh_component]
  70. )
  71. return refresh_button