rjiang12 commited on
Commit
01be1a4
·
1 Parent(s): a4cf573

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -1,8 +1,8 @@
1
  import gradio as gr
2
 
3
  def func(percent, numBlocks):
4
- filledSquares = "<div style='height:12px;width:12px;background-color:#555;display:inline-block'></div> "
5
- emptySquares = "<div style='height:12px;width:12px;background-color:#999;display:inline-block'></div> "
6
  numFilled = round((percent/100) * numBlocks)
7
  print(f"numFilled: {numFilled}")
8
  numEmpty = numBlocks - numFilled
@@ -10,9 +10,12 @@ def func(percent, numBlocks):
10
  HTMLstr = filledSquares * numFilled + emptySquares * numEmpty
11
  return HTMLstr
12
 
13
-
14
 
15
- with gr.Blocks() as demo:
 
 
 
 
16
  percent = gr.Slider(1, 100, value=50, step=1, label="percentage")
17
  numBlocks = gr.Slider(3, 20, value=4, step=1, label="number of blocks")
18
  button = gr.Button("button")
 
1
  import gradio as gr
2
 
3
  def func(percent, numBlocks):
4
+ filledSquares = "<div style='height:12px;width:12px;background-color:#555;display:inline-block' id='filled'><span class='tooltiptext'>Tooltip text</span></div> "
5
+ emptySquares = "<div style='height:12px;width:12px;background-color:#999;display:inline-block' id='empty'><span class='tooltiptext'>Tooltip text</span></div> "
6
  numFilled = round((percent/100) * numBlocks)
7
  print(f"numFilled: {numFilled}")
8
  numEmpty = numBlocks - numFilled
 
10
  HTMLstr = filledSquares * numFilled + emptySquares * numEmpty
11
  return HTMLstr
12
 
 
13
 
14
+ css_adds = ".tooltiptext {visibility: hidden;width: 120px;background-color: black;color: #fff;text-align: center;border-radius: 6px;padding: 5px 0;position: absolute;z-index: 1;} \
15
+ #filled:hover .tooltiptext {visibility: visible;} \
16
+ #empty:hover .tooltiptext {visibility: visible;}"
17
+
18
+ with gr.Blocks(css=css_adds) as demo:
19
  percent = gr.Slider(1, 100, value=50, step=1, label="percentage")
20
  numBlocks = gr.Slider(3, 20, value=4, step=1, label="number of blocks")
21
  button = gr.Button("button")