aliabd HF Staff commited on
Commit
340051c
·
1 Parent(s): 3e3f222

Upload with huggingface_hub

Browse files
Files changed (3) hide show
  1. requirements.txt +1 -1
  2. run.ipynb +1 -1
  3. run.py +15 -5
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
  plotly
2
- https://gradio-main-build.s3.amazonaws.com/943b4ed77a098bf69519515c027b0c12ca8b2573/gradio-3.14.0-py3-none-any.whl
 
1
  plotly
2
+ https://gradio-main-build.s3.amazonaws.com/51157d74109ab4a3ec13320cea02da2f315f5388/gradio-3.14.0-py3-none-any.whl
run.ipynb CHANGED
@@ -1 +1 @@
1
- {"cells": [{"cell_type": "markdown", "id": 302934307671667531413257853548643485645, "metadata": {}, "source": ["# Gradio Demo: live_dashboard\n", "### This demo shows how you can build a live interactive dashboard with gradio.\n", "The current time is refreshed every second and the plot every half second by using the 'every' keyword in the event handler.\n", "Changing the value of the slider will control the period of the sine curve (the distance between peaks). \n", " "]}, {"cell_type": "code", "execution_count": null, "id": 272996653310673477252411125948039410165, "metadata": {}, "outputs": [], "source": ["!pip install -q gradio plotly"]}, {"cell_type": "code", "execution_count": null, "id": 288918539441861185822528903084949547379, "metadata": {}, "outputs": [], "source": ["import math\n", "import gradio as gr\n", "import datetime\n", "import plotly.express as px\n", "import numpy as np\n", "import time\n", "\n", "\n", "def get_time():\n", " return datetime.datetime.now()\n", "\n", "\n", "plot_end = 2 * math.pi\n", "\n", "\n", "def get_plot(period=1):\n", " global plot_end\n", " x = np.arange(plot_end - 2 * math.pi, plot_end, 0.02)\n", " y = np.sin(2 * math.pi * period * x)\n", " fig = px.line(x=x, y=y)\n", " plot_end += 2 * math.pi\n", " return fig\n", "\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " with gr.Column():\n", " c_time2 = gr.Textbox(label=\"Current Time refreshed every second\")\n", " gr.Textbox(\n", " \"Change the value of the slider to automatically update the plot\",\n", " label=\"\",\n", " )\n", " period = gr.Slider(\n", " label=\"Period of plot\", value=1, minimum=0, maximum=10, step=1\n", " )\n", " plot = gr.Plot(label=\"Plot (updates every second)\")\n", " with gr.Column():\n", " name = gr.Textbox(label=\"Enter your name\")\n", " greeting = gr.Textbox(label=\"Greeting\")\n", " button = gr.Button(value=\"Greet\")\n", " button.click(lambda s: f\"Hello {s}\", name, greeting)\n", "\n", " demo.load(lambda: datetime.datetime.now(), None, c_time2, every=1)\n", " dep = demo.load(get_plot, None, plot, every=1)\n", " period.change(get_plot, period, plot, every=1, cancels=[dep])\n", "\n", "if __name__ == \"__main__\":\n", " demo.queue().launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
 
1
+ {"cells": [{"cell_type": "markdown", "id": 302934307671667531413257853548643485645, "metadata": {}, "source": ["# Gradio Demo: live_dashboard\n", "### This demo shows how you can build a live interactive dashboard with gradio.\n", "The current time is refreshed every second and the plot every half second by using the 'every' keyword in the event handler.\n", "Changing the value of the slider will control the period of the sine curve (the distance between peaks). \n", " "]}, {"cell_type": "code", "execution_count": null, "id": 272996653310673477252411125948039410165, "metadata": {}, "outputs": [], "source": ["!pip install -q gradio plotly"]}, {"cell_type": "code", "execution_count": null, "id": 288918539441861185822528903084949547379, "metadata": {}, "outputs": [], "source": ["import math\n", "\n", "import pandas as pd\n", "\n", "import gradio as gr\n", "import datetime\n", "import numpy as np\n", "\n", "\n", "def get_time():\n", " return datetime.datetime.now()\n", "\n", "\n", "plot_end = 2 * math.pi\n", "\n", "\n", "def get_plot(period=1):\n", " global plot_end\n", " x = np.arange(plot_end - 2 * math.pi, plot_end, 0.02)\n", " y = np.sin(2 * math.pi * period * x)\n", " update = gr.LinePlot.update(\n", " value=pd.DataFrame({\"x\": x, \"y\": y}),\n", " x=\"x\",\n", " y=\"y\",\n", " title=\"Plot (updates every second)\",\n", " width=600,\n", " height=350,\n", " )\n", " plot_end += 2 * math.pi\n", " if plot_end > 1000:\n", " plot_end = 2 * math.pi\n", " return update\n", "\n", "\n", "with gr.Blocks() as demo:\n", " with gr.Row():\n", " with gr.Column():\n", " c_time2 = gr.Textbox(label=\"Current Time refreshed every second\")\n", " gr.Textbox(\n", " \"Change the value of the slider to automatically update the plot\",\n", " label=\"\",\n", " )\n", " period = gr.Slider(\n", " label=\"Period of plot\", value=1, minimum=0, maximum=10, step=1\n", " )\n", " plot = gr.LinePlot(show_label=False)\n", " with gr.Column():\n", " name = gr.Textbox(label=\"Enter your name\")\n", " greeting = gr.Textbox(label=\"Greeting\")\n", " button = gr.Button(value=\"Greet\")\n", " button.click(lambda s: f\"Hello {s}\", name, greeting)\n", "\n", " demo.load(lambda: datetime.datetime.now(), None, c_time2, every=1)\n", " dep = demo.load(get_plot, None, plot, every=1)\n", " period.change(get_plot, period, plot, every=1, cancels=[dep])\n", "\n", "if __name__ == \"__main__\":\n", " demo.queue().launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py CHANGED
@@ -1,9 +1,10 @@
1
  import math
 
 
 
2
  import gradio as gr
3
  import datetime
4
- import plotly.express as px
5
  import numpy as np
6
- import time
7
 
8
 
9
  def get_time():
@@ -17,9 +18,18 @@ def get_plot(period=1):
17
  global plot_end
18
  x = np.arange(plot_end - 2 * math.pi, plot_end, 0.02)
19
  y = np.sin(2 * math.pi * period * x)
20
- fig = px.line(x=x, y=y)
 
 
 
 
 
 
 
21
  plot_end += 2 * math.pi
22
- return fig
 
 
23
 
24
 
25
  with gr.Blocks() as demo:
@@ -33,7 +43,7 @@ with gr.Blocks() as demo:
33
  period = gr.Slider(
34
  label="Period of plot", value=1, minimum=0, maximum=10, step=1
35
  )
36
- plot = gr.Plot(label="Plot (updates every second)")
37
  with gr.Column():
38
  name = gr.Textbox(label="Enter your name")
39
  greeting = gr.Textbox(label="Greeting")
 
1
  import math
2
+
3
+ import pandas as pd
4
+
5
  import gradio as gr
6
  import datetime
 
7
  import numpy as np
 
8
 
9
 
10
  def get_time():
 
18
  global plot_end
19
  x = np.arange(plot_end - 2 * math.pi, plot_end, 0.02)
20
  y = np.sin(2 * math.pi * period * x)
21
+ update = gr.LinePlot.update(
22
+ value=pd.DataFrame({"x": x, "y": y}),
23
+ x="x",
24
+ y="y",
25
+ title="Plot (updates every second)",
26
+ width=600,
27
+ height=350,
28
+ )
29
  plot_end += 2 * math.pi
30
+ if plot_end > 1000:
31
+ plot_end = 2 * math.pi
32
+ return update
33
 
34
 
35
  with gr.Blocks() as demo:
 
43
  period = gr.Slider(
44
  label="Period of plot", value=1, minimum=0, maximum=10, step=1
45
  )
46
+ plot = gr.LinePlot(show_label=False)
47
  with gr.Column():
48
  name = gr.Textbox(label="Enter your name")
49
  greeting = gr.Textbox(label="Greeting")