aliabd HF Staff commited on
Commit
1f067b4
·
1 Parent(s): 905469f

Upload with huggingface_hub

Browse files
Files changed (4) hide show
  1. DESCRIPTION.md +3 -0
  2. README.md +1 -1
  3. requirements.txt +1 -1
  4. run.py +12 -6
DESCRIPTION.md ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ This demo shows how you can build a live interactive dashboard with gradio.
2
+ The current time is refreshed every second and the plot every half second by using the 'every' keyword in the event handler.
3
+ Changing the value of the slider will control the period of the sine curve (the distance between peaks).
README.md CHANGED
@@ -5,7 +5,7 @@ emoji: 🔥
5
  colorFrom: indigo
6
  colorTo: indigo
7
  sdk: gradio
8
- sdk_version: 3.8.1
9
  app_file: run.py
10
  pinned: false
11
  ---
 
5
  colorFrom: indigo
6
  colorTo: indigo
7
  sdk: gradio
8
+ sdk_version: 3.8.2
9
  app_file: run.py
10
  pinned: false
11
  ---
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
  plotly
2
- https://gradio-main-build.s3.amazonaws.com/e30af8813c3d76329cf4869fa87a902b2075c8cd/gradio-3.8.1-py3-none-any.whl
 
1
  plotly
2
+ https://gradio-main-build.s3.amazonaws.com/e30af8813c3d76329cf4869fa87a902b2075c8cd/gradio-3.8.2-py3-none-any.whl
run.py CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
3
  import datetime
4
  import plotly.express as px
5
  import numpy as np
 
6
 
7
 
8
  def get_time():
@@ -15,7 +16,7 @@ plot_end = 2 * math.pi
15
  def get_plot(period=1):
16
  global plot_end
17
  x = np.arange(plot_end - 2 * math.pi, plot_end, 0.02)
18
- y = np.sin(2*math.pi*period * x)
19
  fig = px.line(x=x, y=y)
20
  plot_end += 2 * math.pi
21
  return fig
@@ -25,9 +26,14 @@ with gr.Blocks() as demo:
25
  with gr.Row():
26
  with gr.Column():
27
  c_time2 = gr.Textbox(label="Current Time refreshed every second")
28
- gr.Markdown("Change the value of the slider to automatically update the plot")
29
- period = gr.Slider(label="Period of plot", value=1, minimum=0, maximum=10, step=1)
30
- plot = gr.Plot(label="Plot (updates every half second)")
 
 
 
 
 
31
  with gr.Column():
32
  name = gr.Textbox(label="Enter your name")
33
  greeting = gr.Textbox(label="Greeting")
@@ -35,8 +41,8 @@ with gr.Blocks() as demo:
35
  button.click(lambda s: f"Hello {s}", name, greeting)
36
 
37
  demo.load(lambda: datetime.datetime.now(), None, c_time2, every=1)
38
- dep = demo.load(get_plot, None, plot, every=0.5)
39
- period.change(get_plot, period, plot, every=0.5, cancels=[dep])
40
 
41
  if __name__ == "__main__":
42
  demo.queue().launch()
 
3
  import datetime
4
  import plotly.express as px
5
  import numpy as np
6
+ import time
7
 
8
 
9
  def get_time():
 
16
  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
 
26
  with gr.Row():
27
  with gr.Column():
28
  c_time2 = gr.Textbox(label="Current Time refreshed every second")
29
+ gr.Textbox(
30
+ "Change the value of the slider to automatically update the plot",
31
+ label="",
32
+ )
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")
 
41
  button.click(lambda s: f"Hello {s}", name, greeting)
42
 
43
  demo.load(lambda: datetime.datetime.now(), None, c_time2, every=1)
44
+ dep = demo.load(get_plot, None, plot, every=1)
45
+ period.change(get_plot, period, plot, every=1, cancels=[dep])
46
 
47
  if __name__ == "__main__":
48
  demo.queue().launch()