aliabd HF Staff commited on
Commit
224c276
·
1 Parent(s): 6dcd174

Upload with huggingface_hub

Browse files
Files changed (4) hide show
  1. bar_plot_demo.py +89 -0
  2. requirements.txt +1 -1
  3. run.ipynb +1 -1
  4. run.py +3 -0
bar_plot_demo.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+
4
+ from vega_datasets import data
5
+
6
+ barley = data.barley()
7
+ simple = pd.DataFrame({
8
+ 'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'],
9
+ 'b': [28, 55, 43, 91, 81, 53, 19, 87, 52]
10
+ })
11
+
12
+ def bar_plot_fn(display):
13
+ if display == "simple":
14
+ return gr.BarPlot.update(
15
+ simple,
16
+ x="a",
17
+ y="b",
18
+ title="Simple Bar Plot with made up data",
19
+ tooltip=['a', 'b'],
20
+ y_lim=[20, 100]
21
+ )
22
+ elif display == "stacked":
23
+ return gr.BarPlot.update(
24
+ barley,
25
+ x="variety",
26
+ y="yield",
27
+ color="site",
28
+ title="Barley Yield Data",
29
+ tooltip=['variety', 'site']
30
+ )
31
+ elif display == "grouped":
32
+ return gr.BarPlot.update(
33
+ barley.astype({"year": str}),
34
+ x="year",
35
+ y="yield",
36
+ color="year",
37
+ group="site",
38
+ title="Barley Yield by Year and Site",
39
+ group_title="",
40
+ tooltip=["yield", "site", "year"]
41
+ )
42
+ elif display == "simple-horizontal":
43
+ return gr.BarPlot.update(
44
+ simple,
45
+ x="a",
46
+ y="b",
47
+ x_title="Variable A",
48
+ y_title="Variable B",
49
+ title="Simple Bar Plot with made up data",
50
+ tooltip=['a', 'b'],
51
+ vertical=False,
52
+ y_lim=[20, 100]
53
+ )
54
+ elif display == "stacked-horizontal":
55
+ return gr.BarPlot.update(
56
+ barley,
57
+ x="variety",
58
+ y="yield",
59
+ color="site",
60
+ title="Barley Yield Data",
61
+ vertical=False,
62
+ tooltip=['variety', 'site']
63
+ )
64
+ elif display == "grouped-horizontal":
65
+ return gr.BarPlot.update(
66
+ barley.astype({"year": str}),
67
+ x="year",
68
+ y="yield",
69
+ color="year",
70
+ group="site",
71
+ title="Barley Yield by Year and Site",
72
+ group_title="",
73
+ tooltip=["yield", "site", "year"],
74
+ vertical=False
75
+ )
76
+
77
+
78
+ with gr.Blocks() as bar_plot:
79
+ with gr.Row():
80
+ with gr.Column():
81
+ display = gr.Dropdown(
82
+ choices=["simple", "stacked", "grouped", "simple-horizontal", "stacked-horizontal", "grouped-horizontal"],
83
+ value="simple",
84
+ label="Type of Bar Plot"
85
+ )
86
+ with gr.Column():
87
+ plot = gr.BarPlot(show_label=False).style(container=True)
88
+ display.change(bar_plot_fn, inputs=display, outputs=plot)
89
+ bar_plot.load(fn=bar_plot_fn, inputs=display, outputs=plot)
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
  vega_datasets
2
- https://gradio-main-build.s3.amazonaws.com/f92109621a4f6ab8712eee6586cc3db20681ce47/gradio-3.18.0-py3-none-any.whl
 
1
  vega_datasets
2
+ https://gradio-main-build.s3.amazonaws.com/c06b4eab16f4898b08dfcd8e762d53e579102875/gradio-3.18.0-py3-none-any.whl
run.ipynb CHANGED
@@ -1 +1 @@
1
- {"cells": [{"cell_type": "markdown", "id": 302934307671667531413257853548643485645, "metadata": {}, "source": ["# Gradio Demo: native_plots"]}, {"cell_type": "code", "execution_count": null, "id": 272996653310673477252411125948039410165, "metadata": {}, "outputs": [], "source": ["!pip install -q gradio vega_datasets"]}, {"cell_type": "code", "execution_count": null, "id": 288918539441861185822528903084949547379, "metadata": {}, "outputs": [], "source": ["# Downloading files from the demo repo\n", "import os\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/native_plots/line_plot_demo.py\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/native_plots/scatter_plot_demo.py"]}, {"cell_type": "code", "execution_count": null, "id": 44380577570523278879349135829904343037, "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "\n", "from scatter_plot_demo import scatter_plot\n", "from line_plot_demo import line_plot\n", "\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Tabs():\n", " with gr.TabItem(\"Scatter Plot\"):\n", " scatter_plot.render()\n", " with gr.TabItem(\"Line Plot\"):\n", " line_plot.render()\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
 
1
+ {"cells": [{"cell_type": "markdown", "id": 302934307671667531413257853548643485645, "metadata": {}, "source": ["# Gradio Demo: native_plots"]}, {"cell_type": "code", "execution_count": null, "id": 272996653310673477252411125948039410165, "metadata": {}, "outputs": [], "source": ["!pip install -q gradio vega_datasets"]}, {"cell_type": "code", "execution_count": null, "id": 288918539441861185822528903084949547379, "metadata": {}, "outputs": [], "source": ["# Downloading files from the demo repo\n", "import os\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/native_plots/bar_plot_demo.py\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/native_plots/line_plot_demo.py\n", "!wget -q https://github.com/gradio-app/gradio/raw/main/demo/native_plots/scatter_plot_demo.py"]}, {"cell_type": "code", "execution_count": null, "id": 44380577570523278879349135829904343037, "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "\n", "from scatter_plot_demo import scatter_plot\n", "from line_plot_demo import line_plot\n", "from bar_plot_demo import bar_plot\n", "\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Tabs():\n", " with gr.TabItem(\"Scatter Plot\"):\n", " scatter_plot.render()\n", " with gr.TabItem(\"Line Plot\"):\n", " line_plot.render()\n", " with gr.TabItem(\"Bar Plot\"):\n", " bar_plot.render()\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
2
 
3
  from scatter_plot_demo import scatter_plot
4
  from line_plot_demo import line_plot
 
5
 
6
 
7
  with gr.Blocks() as demo:
@@ -10,6 +11,8 @@ with gr.Blocks() as demo:
10
  scatter_plot.render()
11
  with gr.TabItem("Line Plot"):
12
  line_plot.render()
 
 
13
 
14
  if __name__ == "__main__":
15
  demo.launch()
 
2
 
3
  from scatter_plot_demo import scatter_plot
4
  from line_plot_demo import line_plot
5
+ from bar_plot_demo import bar_plot
6
 
7
 
8
  with gr.Blocks() as demo:
 
11
  scatter_plot.render()
12
  with gr.TabItem("Line Plot"):
13
  line_plot.render()
14
+ with gr.TabItem("Bar Plot"):
15
+ bar_plot.render()
16
 
17
  if __name__ == "__main__":
18
  demo.launch()