aliabd HF Staff commited on
Commit
940c54e
·
1 Parent(s): 0eaa209

Upload with huggingface_hub

Browse files
Files changed (5) hide show
  1. line_plot_demo.py +78 -0
  2. requirements.txt +1 -1
  3. run.ipynb +1 -1
  4. run.py +3 -0
  5. scatter_plot_demo.py +1 -1
line_plot_demo.py ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from vega_datasets import data
3
+
4
+ stocks = data.stocks()
5
+ gapminder = data.gapminder()
6
+ gapminder = gapminder.loc[
7
+ gapminder.country.isin(["Argentina", "Australia", "Afghanistan"])
8
+ ]
9
+ climate = data.climate()
10
+ seattle_weather = data.seattle_weather()
11
+
12
+
13
+ def line_plot_fn(dataset):
14
+ if dataset == "stocks":
15
+ return gr.LinePlot.update(
16
+ stocks,
17
+ x="date",
18
+ y="price",
19
+ color="symbol",
20
+ color_legend_position="bottom",
21
+ title="Stock Prices",
22
+ tooltip=['date', 'price', 'symbol'],
23
+ height=300,
24
+ width=500
25
+ )
26
+ elif dataset == "climate":
27
+ return gr.LinePlot.update(
28
+ climate,
29
+ x="DATE",
30
+ y="HLY-TEMP-NORMAL",
31
+ y_lim=[250, 500],
32
+ title="Climate",
33
+ tooltip=['DATE', 'HLY-TEMP-NORMAL'],
34
+ height=300,
35
+ width=500
36
+ )
37
+ elif dataset == "seattle_weather":
38
+ return gr.LinePlot.update(
39
+ seattle_weather,
40
+ x="date",
41
+ y="temp_min",
42
+ tooltip=["weather", "date"],
43
+ overlay_point=True,
44
+ title="Seattle Weather",
45
+ height=300,
46
+ width=500
47
+ )
48
+ elif dataset == "gapminder":
49
+ return gr.LinePlot.update(
50
+ gapminder,
51
+ x="year",
52
+ y="life_expect",
53
+ color="country",
54
+ title="Life expectancy for countries",
55
+ stroke_dash="cluster",
56
+ x_lim=[1950, 2010],
57
+ tooltip=['country', 'life_expect'],
58
+ stroke_dash_legend_title="Country Cluster",
59
+ height=300,
60
+ width=500
61
+ )
62
+
63
+
64
+ with gr.Blocks() as line_plot:
65
+ with gr.Row():
66
+ with gr.Column():
67
+ dataset = gr.Dropdown(
68
+ choices=["stocks", "climate", "seattle_weather", "gapminder"],
69
+ value="stocks",
70
+ )
71
+ with gr.Column():
72
+ plot = gr.LinePlot(show_label=False).style(container=False)
73
+ dataset.change(line_plot_fn, inputs=dataset, outputs=plot)
74
+ line_plot.load(fn=line_plot_fn, inputs=dataset, outputs=plot)
75
+
76
+
77
+ if __name__ == "__main__":
78
+ line_plot.launch()
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
  vega_datasets
2
- https://gradio-main-build.s3.amazonaws.com/3cb2bb061c8fa42ea1c13d73438dbff132f42983/gradio-3.14.0-py3-none-any.whl
 
1
  vega_datasets
2
+ https://gradio-main-build.s3.amazonaws.com/96297c0bad09ee82e65d56a53f96ee9814bb8360/gradio-3.14.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/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", "\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Tabs():\n", " with gr.TabItem(\"Scatter Plot\"):\n", " scatter_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/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}
run.py CHANGED
@@ -1,12 +1,15 @@
1
  import gradio as gr
2
 
3
  from scatter_plot_demo import scatter_plot
 
4
 
5
 
6
  with gr.Blocks() as demo:
7
  with gr.Tabs():
8
  with gr.TabItem("Scatter Plot"):
9
  scatter_plot.render()
 
 
10
 
11
  if __name__ == "__main__":
12
  demo.launch()
 
1
  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:
8
  with gr.Tabs():
9
  with gr.TabItem("Scatter Plot"):
10
  scatter_plot.render()
11
+ with gr.TabItem("Line Plot"):
12
+ line_plot.render()
13
 
14
  if __name__ == "__main__":
15
  demo.launch()
scatter_plot_demo.py CHANGED
@@ -30,7 +30,7 @@ def scatter_plot_fn(dataset):
30
  title="Car Data",
31
  y_title="Miles per Gallon",
32
  color_legend_title="Origin of Car",
33
- caption="MPG vs Horsepower of various cars"
34
  )
35
 
36
 
 
30
  title="Car Data",
31
  y_title="Miles per Gallon",
32
  color_legend_title="Origin of Car",
33
+ caption="MPG vs Horsepower of various cars",
34
  )
35
 
36