freddyaboulton HF Staff commited on
Commit
ff87375
·
verified ·
1 Parent(s): e1ca35b

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. requirements.txt +2 -2
  2. run.ipynb +1 -1
  3. run.py +14 -16
requirements.txt CHANGED
@@ -1,5 +1,5 @@
1
- gradio-client @ git+https://github.com/gradio-app/gradio@a1d436f7e62ea7d973ef176b4801ca6eb1be65a4#subdirectory=client/python
2
- https://gradio-pypi-previews.s3.amazonaws.com/a1d436f7e62ea7d973ef176b4801ca6eb1be65a4/gradio-5.29.0-py3-none-any.whl
3
  numpy
4
  pandas
5
  plotly
 
1
+ gradio-client @ git+https://github.com/gradio-app/gradio@afaaeeccd0be7ee56ab91ee168ff5b63b566e814#subdirectory=client/python
2
+ https://gradio-pypi-previews.s3.amazonaws.com/afaaeeccd0be7ee56ab91ee168ff5b63b566e814/gradio-5.29.0-py3-none-any.whl
3
  numpy
4
  pandas
5
  plotly
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 numpy pandas 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", "def get_time():\n", " return datetime.datetime.now()\n", "\n", "plot_end = 2 * math.pi\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(\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", "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.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 numpy pandas 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", "def get_time():\n", " return datetime.datetime.now()\n", "\n", "plot_end = 2 * math.pi\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(\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 += 0.1\n", " return update\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", " period = gr.Slider(\n", " label=\"Period of plot\", value=1, minimum=0, maximum=10\n", " )\n", " plot = gr.LinePlot(show_label=False)\n", " with gr.Column():\n", " start_time = gr.Textbox(label=\"Start Time\")\n", " end_time = gr.Textbox(label=\"End Time\")\n", "\n", " timer = gr.Timer(1)\n", "\n", " timer.tick(lambda: datetime.datetime.now(), None, c_time2)\n", " timer.tick(get_plot, period, plot)\n", "\n", " def select(selection_range: gr.SelectData):\n", " return gr.LinePlot(x_lim=selection_range.index), selection_range.index[0], selection_range.index[1]\n", " plot.select(select, None, [plot, start_time, end_time])\n", " plot.double_click(lambda: gr.LinePlot(x_lim=None), None, plot)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py CHANGED
@@ -23,32 +23,30 @@ def get_plot(period=1):
23
  width=600,
24
  height=350,
25
  )
26
- plot_end += 2 * math.pi
27
- if plot_end > 1000:
28
- plot_end = 2 * math.pi
29
  return update
30
 
31
  with gr.Blocks() as demo:
32
  with gr.Row():
33
  with gr.Column():
34
  c_time2 = gr.Textbox(label="Current Time refreshed every second")
35
- gr.Textbox(
36
- "Change the value of the slider to automatically update the plot",
37
- label="",
38
- )
39
  period = gr.Slider(
40
- label="Period of plot", value=1, minimum=0, maximum=10, step=1
41
  )
42
  plot = gr.LinePlot(show_label=False)
43
  with gr.Column():
44
- name = gr.Textbox(label="Enter your name")
45
- greeting = gr.Textbox(label="Greeting")
46
- button = gr.Button(value="Greet")
47
- button.click(lambda s: f"Hello {s}", name, greeting)
48
-
49
- demo.load(lambda: datetime.datetime.now(), None, c_time2, every=1)
50
- dep = demo.load(get_plot, None, plot, every=1)
51
- period.change(get_plot, period, plot, every=1, cancels=[dep])
 
 
 
 
52
 
53
  if __name__ == "__main__":
54
  demo.launch()
 
23
  width=600,
24
  height=350,
25
  )
26
+ plot_end += 0.1
 
 
27
  return update
28
 
29
  with gr.Blocks() as demo:
30
  with gr.Row():
31
  with gr.Column():
32
  c_time2 = gr.Textbox(label="Current Time refreshed every second")
 
 
 
 
33
  period = gr.Slider(
34
+ label="Period of plot", value=1, minimum=0, maximum=10
35
  )
36
  plot = gr.LinePlot(show_label=False)
37
  with gr.Column():
38
+ start_time = gr.Textbox(label="Start Time")
39
+ end_time = gr.Textbox(label="End Time")
40
+
41
+ timer = gr.Timer(1)
42
+
43
+ timer.tick(lambda: datetime.datetime.now(), None, c_time2)
44
+ timer.tick(get_plot, period, plot)
45
+
46
+ def select(selection_range: gr.SelectData):
47
+ return gr.LinePlot(x_lim=selection_range.index), selection_range.index[0], selection_range.index[1]
48
+ plot.select(select, None, [plot, start_time, end_time])
49
+ plot.double_click(lambda: gr.LinePlot(x_lim=None), None, plot)
50
 
51
  if __name__ == "__main__":
52
  demo.launch()