File size: 1,673 Bytes
70455bb
 
 
bfa5203
 
4349de9
6dd7921
70455bb
6dd7921
70455bb
0ae8261
 
 
 
70455bb
 
d7a1de5
01be1a4
 
 
 
12bc024
fc19874
70455bb
c5943a3
 
 
 
 
0ae8261
84dae4a
70455bb
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
import gradio as gr

def func(percent, numBlocks):
    filledSquares = "<div style='height:20px;width:20px;background-color:#555;display:inline-block;position:relative' id='filled'><span class='tooltiptext' style='color:#FFF'>Here is a sentence that goes on for a really really really really really really really long time</span></div> "
    emptySquares = "<div style='height:20px;width:20px;background-color:#999;display:inline-block;position:relative' id='empty'><span class='tooltiptext' style='color:#FFF'>Here is a sentence that goes on for a really really really really really really really long time</span></div> "
    numFilled = round((percent/100) * numBlocks)
    print(f"numFilled: {numFilled}")
    numEmpty = numBlocks - numFilled
    print(f"numEmpty: {numEmpty}")
    HTMLstr = filledSquares * numFilled + emptySquares * numEmpty
    return (
        gr.update(value=HTMLstr),
        gr.update(value=HTMLstr)
    )
    

css_adds = ".tooltiptext {visibility: hidden;width:50ch;top: 100%;left: 105%;background-color: #222;text-align: center;border-radius: 6px;padding: 5px 0;position: absolute;z-index: 1;} \
#filled:hover .tooltiptext {visibility: visible;} \
#empty:hover .tooltiptext {visibility: visible;}"

with gr.Blocks(css=css_adds) as demo:
    percent = gr.Slider(1, 100, value=50, step=1, label="percentage")
    numBlocks = gr.Slider(3, 100, value=4, step=1, label="number of blocks")
    button = gr.Button("button")
    with gr.Row():
        with gr.Column():
            html1 = gr.HTML()
        with gr.Column():
            html2 = gr.HTML()
    button.click(func, inputs=[percent, numBlocks], outputs=[html1, html2])
# hi
demo.launch()