File size: 935 Bytes
5a267a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
41
42
43
import pandas as pd
import gradio as gr

# Creating a sample dataframe
def run():
  df = pd.DataFrame({
      "A" : ["Apparel & Accessories", "Home & Garden", "Health & Beauty", "Cameras & Optics", "Apparel & Accessories"],
      "B" : [6, 2, 54, 3, 2],
      "C" : [3, 20, 7, 3, 8],
      "D" : [2, 3, 6, 2, 6],
      "E" : [-1, 45, 64, 32, 23]
  })
  df = df.style.applymap(color_num, subset=["E"])

  return df


def color_num(value) -> str:
    color = "red" if value >= 0 else "green"
    color_style = f"color: {color}"

    return color_style

def handle_change(df):
    return df

demo = gr.Blocks()

with demo:
    gr.Textbox(f"{gr.__version__}")
    a = gr.DataFrame(show_search="filter")

    b = gr.Button("run")
    b.click(run,outputs=a)
    a.change(lambda x: print(x), inputs=a)

    c = gr.DataFrame(show_search="search")
    a.change(handle_change, inputs=a, outputs=c)


if __name__ == "__main__":
    demo.launch()