aliabd HF staff commited on
Commit
c4fc5dd
·
1 Parent(s): e7c0f6e

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +5 -6
  2. requirements.txt +2 -0
  3. run.ipynb +1 -0
  4. run.py +140 -0
README.md CHANGED
@@ -1,12 +1,11 @@
 
1
  ---
2
- title: Bar Plot Main
3
  emoji: 🔥
4
- colorFrom: blue
5
- colorTo: blue
6
  sdk: gradio
7
  sdk_version: 3.35.2
8
- app_file: app.py
9
  pinned: false
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+
2
  ---
3
+ title: bar_plot_main
4
  emoji: 🔥
5
+ colorFrom: indigo
6
+ colorTo: indigo
7
  sdk: gradio
8
  sdk_version: 3.35.2
9
+ app_file: run.py
10
  pinned: false
11
  ---
 
 
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ pandas
2
+ https://gradio-main-build.s3.amazonaws.com/44c766bd1a19e6c9195aed298ee6423c5e0116e3/gradio-3.35.2-py3-none-any.whl
run.ipynb ADDED
@@ -0,0 +1 @@
 
 
1
+ {"cells": [{"cell_type": "markdown", "id": 302934307671667531413257853548643485645, "metadata": {}, "source": ["# Gradio Demo: bar_plot"]}, {"cell_type": "code", "execution_count": null, "id": 272996653310673477252411125948039410165, "metadata": {}, "outputs": [], "source": ["!pip install -q gradio pandas"]}, {"cell_type": "code", "execution_count": null, "id": 288918539441861185822528903084949547379, "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import pandas as pd\n", "import random\n", "\n", "simple = pd.DataFrame(\n", " {\n", " \"a\": [\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", \"I\"],\n", " \"b\": [28, 55, 43, 91, 81, 53, 19, 87, 52],\n", " }\n", ")\n", "\n", "fake_barley = pd.DataFrame(\n", " {\n", " \"site\": [\n", " random.choice(\n", " [\n", " \"University Farm\",\n", " \"Waseca\",\n", " \"Morris\",\n", " \"Crookston\",\n", " \"Grand Rapids\",\n", " \"Duluth\",\n", " ]\n", " )\n", " for _ in range(120)\n", " ],\n", " \"yield\": [random.randint(25, 75) for _ in range(120)],\n", " \"variety\": [\n", " random.choice(\n", " [\n", " \"Manchuria\",\n", " \"Wisconsin No. 38\",\n", " \"Glabron\",\n", " \"No. 457\",\n", " \"No. 462\",\n", " \"No. 475\",\n", " ]\n", " )\n", " for _ in range(120)\n", " ],\n", " \"year\": [\n", " random.choice(\n", " [\n", " \"1931\",\n", " \"1932\",\n", " ]\n", " )\n", " for _ in range(120)\n", " ],\n", " }\n", ")\n", "\n", "\n", "def bar_plot_fn(display):\n", " if display == \"simple\":\n", " return gr.BarPlot.update(\n", " simple,\n", " x=\"a\",\n", " y=\"b\",\n", " title=\"Simple Bar Plot with made up data\",\n", " tooltip=[\"a\", \"b\"],\n", " y_lim=[20, 100],\n", " )\n", " elif display == \"stacked\":\n", " return gr.BarPlot.update(\n", " fake_barley,\n", " x=\"variety\",\n", " y=\"yield\",\n", " color=\"site\",\n", " title=\"Barley Yield Data\",\n", " tooltip=[\"variety\", \"site\"],\n", " )\n", " elif display == \"grouped\":\n", " return gr.BarPlot.update(\n", " fake_barley.astype({\"year\": str}),\n", " x=\"year\",\n", " y=\"yield\",\n", " color=\"year\",\n", " group=\"site\",\n", " title=\"Barley Yield by Year and Site\",\n", " group_title=\"\",\n", " tooltip=[\"yield\", \"site\", \"year\"],\n", " )\n", " elif display == \"simple-horizontal\":\n", " return gr.BarPlot.update(\n", " simple,\n", " x=\"a\",\n", " y=\"b\",\n", " x_title=\"Variable A\",\n", " y_title=\"Variable B\",\n", " title=\"Simple Bar Plot with made up data\",\n", " tooltip=[\"a\", \"b\"],\n", " vertical=False,\n", " y_lim=[20, 100],\n", " )\n", " elif display == \"stacked-horizontal\":\n", " return gr.BarPlot.update(\n", " fake_barley,\n", " x=\"variety\",\n", " y=\"yield\",\n", " color=\"site\",\n", " title=\"Barley Yield Data\",\n", " vertical=False,\n", " tooltip=[\"variety\", \"site\"],\n", " )\n", " elif display == \"grouped-horizontal\":\n", " return gr.BarPlot.update(\n", " fake_barley.astype({\"year\": str}),\n", " x=\"year\",\n", " y=\"yield\",\n", " color=\"year\",\n", " group=\"site\",\n", " title=\"Barley Yield by Year and Site\",\n", " group_title=\"\",\n", " tooltip=[\"yield\", \"site\", \"year\"],\n", " vertical=False,\n", " )\n", "\n", "\n", "with gr.Blocks() as bar_plot:\n", " with gr.Row():\n", " with gr.Column():\n", " display = gr.Dropdown(\n", " choices=[\n", " \"simple\",\n", " \"stacked\",\n", " \"grouped\",\n", " \"simple-horizontal\",\n", " \"stacked-horizontal\",\n", " \"grouped-horizontal\",\n", " ],\n", " value=\"simple\",\n", " label=\"Type of Bar Plot\",\n", " )\n", " with gr.Column():\n", " plot = gr.BarPlot()\n", " display.change(bar_plot_fn, inputs=display, outputs=plot)\n", " bar_plot.load(fn=bar_plot_fn, inputs=display, outputs=plot)\n", "\n", "bar_plot.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import random
4
+
5
+ simple = pd.DataFrame(
6
+ {
7
+ "a": ["A", "B", "C", "D", "E", "F", "G", "H", "I"],
8
+ "b": [28, 55, 43, 91, 81, 53, 19, 87, 52],
9
+ }
10
+ )
11
+
12
+ fake_barley = pd.DataFrame(
13
+ {
14
+ "site": [
15
+ random.choice(
16
+ [
17
+ "University Farm",
18
+ "Waseca",
19
+ "Morris",
20
+ "Crookston",
21
+ "Grand Rapids",
22
+ "Duluth",
23
+ ]
24
+ )
25
+ for _ in range(120)
26
+ ],
27
+ "yield": [random.randint(25, 75) for _ in range(120)],
28
+ "variety": [
29
+ random.choice(
30
+ [
31
+ "Manchuria",
32
+ "Wisconsin No. 38",
33
+ "Glabron",
34
+ "No. 457",
35
+ "No. 462",
36
+ "No. 475",
37
+ ]
38
+ )
39
+ for _ in range(120)
40
+ ],
41
+ "year": [
42
+ random.choice(
43
+ [
44
+ "1931",
45
+ "1932",
46
+ ]
47
+ )
48
+ for _ in range(120)
49
+ ],
50
+ }
51
+ )
52
+
53
+
54
+ def bar_plot_fn(display):
55
+ if display == "simple":
56
+ return gr.BarPlot.update(
57
+ simple,
58
+ x="a",
59
+ y="b",
60
+ title="Simple Bar Plot with made up data",
61
+ tooltip=["a", "b"],
62
+ y_lim=[20, 100],
63
+ )
64
+ elif display == "stacked":
65
+ return gr.BarPlot.update(
66
+ fake_barley,
67
+ x="variety",
68
+ y="yield",
69
+ color="site",
70
+ title="Barley Yield Data",
71
+ tooltip=["variety", "site"],
72
+ )
73
+ elif display == "grouped":
74
+ return gr.BarPlot.update(
75
+ fake_barley.astype({"year": str}),
76
+ x="year",
77
+ y="yield",
78
+ color="year",
79
+ group="site",
80
+ title="Barley Yield by Year and Site",
81
+ group_title="",
82
+ tooltip=["yield", "site", "year"],
83
+ )
84
+ elif display == "simple-horizontal":
85
+ return gr.BarPlot.update(
86
+ simple,
87
+ x="a",
88
+ y="b",
89
+ x_title="Variable A",
90
+ y_title="Variable B",
91
+ title="Simple Bar Plot with made up data",
92
+ tooltip=["a", "b"],
93
+ vertical=False,
94
+ y_lim=[20, 100],
95
+ )
96
+ elif display == "stacked-horizontal":
97
+ return gr.BarPlot.update(
98
+ fake_barley,
99
+ x="variety",
100
+ y="yield",
101
+ color="site",
102
+ title="Barley Yield Data",
103
+ vertical=False,
104
+ tooltip=["variety", "site"],
105
+ )
106
+ elif display == "grouped-horizontal":
107
+ return gr.BarPlot.update(
108
+ fake_barley.astype({"year": str}),
109
+ x="year",
110
+ y="yield",
111
+ color="year",
112
+ group="site",
113
+ title="Barley Yield by Year and Site",
114
+ group_title="",
115
+ tooltip=["yield", "site", "year"],
116
+ vertical=False,
117
+ )
118
+
119
+
120
+ with gr.Blocks() as bar_plot:
121
+ with gr.Row():
122
+ with gr.Column():
123
+ display = gr.Dropdown(
124
+ choices=[
125
+ "simple",
126
+ "stacked",
127
+ "grouped",
128
+ "simple-horizontal",
129
+ "stacked-horizontal",
130
+ "grouped-horizontal",
131
+ ],
132
+ value="simple",
133
+ label="Type of Bar Plot",
134
+ )
135
+ with gr.Column():
136
+ plot = gr.BarPlot()
137
+ display.change(bar_plot_fn, inputs=display, outputs=plot)
138
+ bar_plot.load(fn=bar_plot_fn, inputs=display, outputs=plot)
139
+
140
+ bar_plot.launch()