hmb HF Staff commited on
Commit
5a267a3
·
verified ·
1 Parent(s): e88aa7c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import gradio as gr
3
+
4
+ # Creating a sample dataframe
5
+ def run():
6
+ df = pd.DataFrame({
7
+ "A" : ["Apparel & Accessories", "Home & Garden", "Health & Beauty", "Cameras & Optics", "Apparel & Accessories"],
8
+ "B" : [6, 2, 54, 3, 2],
9
+ "C" : [3, 20, 7, 3, 8],
10
+ "D" : [2, 3, 6, 2, 6],
11
+ "E" : [-1, 45, 64, 32, 23]
12
+ })
13
+ df = df.style.applymap(color_num, subset=["E"])
14
+
15
+ return df
16
+
17
+
18
+ def color_num(value) -> str:
19
+ color = "red" if value >= 0 else "green"
20
+ color_style = f"color: {color}"
21
+
22
+ return color_style
23
+
24
+ def handle_change(df):
25
+ return df
26
+
27
+ demo = gr.Blocks()
28
+
29
+ with demo:
30
+ gr.Textbox(f"{gr.__version__}")
31
+ a = gr.DataFrame(show_search="filter")
32
+
33
+ b = gr.Button("run")
34
+ b.click(run,outputs=a)
35
+ a.change(lambda x: print(x), inputs=a)
36
+
37
+ c = gr.DataFrame(show_search="search")
38
+ a.change(handle_change, inputs=a, outputs=c)
39
+
40
+
41
+ if __name__ == "__main__":
42
+ demo.launch()