ui.py 1.8 KB

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