Spaces:
Sleeping
Sleeping
Keldos
commited on
Commit
·
8131457
1
Parent(s):
9186425
feat&refactor: add_classes_to_gradio_component
Browse files- modules/overwrites.py +34 -0
modules/overwrites.py
CHANGED
|
@@ -70,3 +70,37 @@ def postprocess_chat_messages(
|
|
| 70 |
return chat_message
|
| 71 |
else:
|
| 72 |
raise ValueError(f"Invalid message for Chatbot component: {chat_message}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
return chat_message
|
| 71 |
else:
|
| 72 |
raise ValueError(f"Invalid message for Chatbot component: {chat_message}")
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def add_classes_to_gradio_component(comp):
|
| 77 |
+
"""
|
| 78 |
+
this adds gradio-* to the component for css styling (ie gradio-button to gr.Button), as well as some others
|
| 79 |
+
code from stable-diffusion-webui <AUTOMATIC1111/stable-diffusion-webui>
|
| 80 |
+
"""
|
| 81 |
+
|
| 82 |
+
comp.elem_classes = [f"gradio-{comp.get_block_name()}", *(comp.elem_classes or [])]
|
| 83 |
+
|
| 84 |
+
if getattr(comp, 'multiselect', False):
|
| 85 |
+
comp.elem_classes.append('multiselect')
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def IOComponent_init(self, *args, **kwargs):
|
| 89 |
+
res = original_IOComponent_init(self, *args, **kwargs)
|
| 90 |
+
add_classes_to_gradio_component(self)
|
| 91 |
+
|
| 92 |
+
return res
|
| 93 |
+
|
| 94 |
+
original_IOComponent_init = gr.components.IOComponent.__init__
|
| 95 |
+
gr.components.IOComponent.__init__ = IOComponent_init
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def BlockContext_init(self, *args, **kwargs):
|
| 99 |
+
res = original_BlockContext_init(self, *args, **kwargs)
|
| 100 |
+
add_classes_to_gradio_component(self)
|
| 101 |
+
|
| 102 |
+
return res
|
| 103 |
+
|
| 104 |
+
original_BlockContext_init = gr.blocks.BlockContext.__init__
|
| 105 |
+
gr.blocks.BlockContext.__init__ = BlockContext_init
|
| 106 |
+
|