ui.py 1.9 KB

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