Spaces:
Runtime error
Runtime error
Upload with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 3.18.
|
| 8 |
-
app_file:
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
+
|
| 2 |
---
|
| 3 |
+
title: bokeh_plot_main
|
| 4 |
+
emoji: 🔥
|
| 5 |
+
colorFrom: indigo
|
| 6 |
+
colorTo: indigo
|
| 7 |
sdk: gradio
|
| 8 |
+
sdk_version: 3.18.1b7
|
| 9 |
+
app_file: run.py
|
| 10 |
pinned: false
|
| 11 |
---
|
|
|
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
bokeh>=3.0
|
| 2 |
+
xyzservices
|
| 3 |
+
https://gradio-main-build.s3.amazonaws.com/9b2119f2979026163fc09a0212cdc6426644c0f6/gradio-3.18.1b7-py3-none-any.whl
|
run.ipynb
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"cells": [{"cell_type": "markdown", "id": 302934307671667531413257853548643485645, "metadata": {}, "source": ["# Gradio Demo: bokeh_plot"]}, {"cell_type": "code", "execution_count": null, "id": 272996653310673477252411125948039410165, "metadata": {}, "outputs": [], "source": ["!pip install -q gradio bokeh>=3.0 xyzservices"]}, {"cell_type": "code", "execution_count": null, "id": 288918539441861185822528903084949547379, "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "import xyzservices.providers as xyz\n", "from bokeh.plotting import figure\n", "from bokeh.tile_providers import get_provider\n", "from bokeh.models import ColumnDataSource, Whisker\n", "from bokeh.plotting import figure\n", "from bokeh.sampledata.autompg2 import autompg2 as df\n", "from bokeh.sampledata.penguins import data\n", "from bokeh.transform import factor_cmap, jitter, factor_mark\n", "\n", "\n", "def get_plot(plot_type):\n", " if plot_type == \"map\":\n", " tile_provider = get_provider(xyz.OpenStreetMap.Mapnik)\n", " plot = figure(\n", " x_range=(-2000000, 6000000),\n", " y_range=(-1000000, 7000000),\n", " x_axis_type=\"mercator\",\n", " y_axis_type=\"mercator\",\n", " )\n", " plot.add_tile(tile_provider)\n", " return plot\n", " elif plot_type == \"whisker\":\n", " classes = list(sorted(df[\"class\"].unique()))\n", "\n", " p = figure(\n", " height=400,\n", " x_range=classes,\n", " background_fill_color=\"#efefef\",\n", " title=\"Car class vs HWY mpg with quintile ranges\",\n", " )\n", " p.xgrid.grid_line_color = None\n", "\n", " g = df.groupby(\"class\")\n", " upper = g.hwy.quantile(0.80)\n", " lower = g.hwy.quantile(0.20)\n", " source = ColumnDataSource(data=dict(base=classes, upper=upper, lower=lower))\n", "\n", " error = Whisker(\n", " base=\"base\",\n", " upper=\"upper\",\n", " lower=\"lower\",\n", " source=source,\n", " level=\"annotation\",\n", " line_width=2,\n", " )\n", " error.upper_head.size = 20\n", " error.lower_head.size = 20\n", " p.add_layout(error)\n", "\n", " p.circle(\n", " jitter(\"class\", 0.3, range=p.x_range),\n", " \"hwy\",\n", " source=df,\n", " alpha=0.5,\n", " size=13,\n", " line_color=\"white\",\n", " color=factor_cmap(\"class\", \"Light6\", classes),\n", " )\n", " return p\n", " elif plot_type == \"scatter\":\n", "\n", " SPECIES = sorted(data.species.unique())\n", " MARKERS = [\"hex\", \"circle_x\", \"triangle\"]\n", "\n", " p = figure(title=\"Penguin size\", background_fill_color=\"#fafafa\")\n", " p.xaxis.axis_label = \"Flipper Length (mm)\"\n", " p.yaxis.axis_label = \"Body Mass (g)\"\n", "\n", " p.scatter(\n", " \"flipper_length_mm\",\n", " \"body_mass_g\",\n", " source=data,\n", " legend_group=\"species\",\n", " fill_alpha=0.4,\n", " size=12,\n", " marker=factor_mark(\"species\", MARKERS, SPECIES),\n", " color=factor_cmap(\"species\", \"Category10_3\", SPECIES),\n", " )\n", "\n", " p.legend.location = \"top_left\"\n", " p.legend.title = \"Species\"\n", " return p\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " plot_type = gr.Radio(value=\"scatter\", choices=[\"scatter\", \"whisker\", \"map\"])\n", " plot = gr.Plot()\n", " plot_type.change(get_plot, inputs=[plot_type], outputs=[plot])\n", " demo.load(get_plot, inputs=[plot_type], outputs=[plot])\n", "\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
|
run.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import xyzservices.providers as xyz
|
| 3 |
+
from bokeh.plotting import figure
|
| 4 |
+
from bokeh.tile_providers import get_provider
|
| 5 |
+
from bokeh.models import ColumnDataSource, Whisker
|
| 6 |
+
from bokeh.plotting import figure
|
| 7 |
+
from bokeh.sampledata.autompg2 import autompg2 as df
|
| 8 |
+
from bokeh.sampledata.penguins import data
|
| 9 |
+
from bokeh.transform import factor_cmap, jitter, factor_mark
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def get_plot(plot_type):
|
| 13 |
+
if plot_type == "map":
|
| 14 |
+
tile_provider = get_provider(xyz.OpenStreetMap.Mapnik)
|
| 15 |
+
plot = figure(
|
| 16 |
+
x_range=(-2000000, 6000000),
|
| 17 |
+
y_range=(-1000000, 7000000),
|
| 18 |
+
x_axis_type="mercator",
|
| 19 |
+
y_axis_type="mercator",
|
| 20 |
+
)
|
| 21 |
+
plot.add_tile(tile_provider)
|
| 22 |
+
return plot
|
| 23 |
+
elif plot_type == "whisker":
|
| 24 |
+
classes = list(sorted(df["class"].unique()))
|
| 25 |
+
|
| 26 |
+
p = figure(
|
| 27 |
+
height=400,
|
| 28 |
+
x_range=classes,
|
| 29 |
+
background_fill_color="#efefef",
|
| 30 |
+
title="Car class vs HWY mpg with quintile ranges",
|
| 31 |
+
)
|
| 32 |
+
p.xgrid.grid_line_color = None
|
| 33 |
+
|
| 34 |
+
g = df.groupby("class")
|
| 35 |
+
upper = g.hwy.quantile(0.80)
|
| 36 |
+
lower = g.hwy.quantile(0.20)
|
| 37 |
+
source = ColumnDataSource(data=dict(base=classes, upper=upper, lower=lower))
|
| 38 |
+
|
| 39 |
+
error = Whisker(
|
| 40 |
+
base="base",
|
| 41 |
+
upper="upper",
|
| 42 |
+
lower="lower",
|
| 43 |
+
source=source,
|
| 44 |
+
level="annotation",
|
| 45 |
+
line_width=2,
|
| 46 |
+
)
|
| 47 |
+
error.upper_head.size = 20
|
| 48 |
+
error.lower_head.size = 20
|
| 49 |
+
p.add_layout(error)
|
| 50 |
+
|
| 51 |
+
p.circle(
|
| 52 |
+
jitter("class", 0.3, range=p.x_range),
|
| 53 |
+
"hwy",
|
| 54 |
+
source=df,
|
| 55 |
+
alpha=0.5,
|
| 56 |
+
size=13,
|
| 57 |
+
line_color="white",
|
| 58 |
+
color=factor_cmap("class", "Light6", classes),
|
| 59 |
+
)
|
| 60 |
+
return p
|
| 61 |
+
elif plot_type == "scatter":
|
| 62 |
+
|
| 63 |
+
SPECIES = sorted(data.species.unique())
|
| 64 |
+
MARKERS = ["hex", "circle_x", "triangle"]
|
| 65 |
+
|
| 66 |
+
p = figure(title="Penguin size", background_fill_color="#fafafa")
|
| 67 |
+
p.xaxis.axis_label = "Flipper Length (mm)"
|
| 68 |
+
p.yaxis.axis_label = "Body Mass (g)"
|
| 69 |
+
|
| 70 |
+
p.scatter(
|
| 71 |
+
"flipper_length_mm",
|
| 72 |
+
"body_mass_g",
|
| 73 |
+
source=data,
|
| 74 |
+
legend_group="species",
|
| 75 |
+
fill_alpha=0.4,
|
| 76 |
+
size=12,
|
| 77 |
+
marker=factor_mark("species", MARKERS, SPECIES),
|
| 78 |
+
color=factor_cmap("species", "Category10_3", SPECIES),
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
p.legend.location = "top_left"
|
| 82 |
+
p.legend.title = "Species"
|
| 83 |
+
return p
|
| 84 |
+
|
| 85 |
+
with gr.Blocks() as demo:
|
| 86 |
+
with gr.Row():
|
| 87 |
+
plot_type = gr.Radio(value="scatter", choices=["scatter", "whisker", "map"])
|
| 88 |
+
plot = gr.Plot()
|
| 89 |
+
plot_type.change(get_plot, inputs=[plot_type], outputs=[plot])
|
| 90 |
+
demo.load(get_plot, inputs=[plot_type], outputs=[plot])
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
if __name__ == "__main__":
|
| 94 |
+
demo.launch()
|