Spaces:
Paused
Paused
File size: 1,250 Bytes
3f9c56c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import gradio as gr
from typing import List
class ModalInterface(gr.Interface):
modal_id_counter = 0
def __init__(
self,
html_content: str,
open_button_text: str,
open_button_classes: List[str] = [],
open_button_extra_attrs: str = ''
):
self.html_content = html_content
self.open_button_text = open_button_text
self.open_button_classes = open_button_classes
self.open_button_extra_attrs = open_button_extra_attrs
self.modal_id = ModalInterface.modal_id_counter
ModalInterface.modal_id_counter += 1
def __call__(self):
return self.create_modal()
def create_modal(self, visible=True):
html_code = f"""
<div id="cnet-modal-{self.modal_id}" class="cnet-modal">
<span class="cnet-modal-close">×</span>
<div class="cnet-modal-content">
{self.html_content}
</div>
</div>
<div id="cnet-modal-open-{self.modal_id}"
class="cnet-modal-open {' '.join(self.open_button_classes)}"
{self.open_button_extra_attrs}
>{self.open_button_text}</div>
"""
return gr.HTML(value=html_code, visible=visible)
|