drmurataltun commited on
Commit
4368524
·
verified ·
1 Parent(s): 0f26b72

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import math
2
+ import gradio as gr
3
+ import plotly.express as px
4
+ import numpy as np
5
+
6
+
7
+ plot_end = 2 * math.pi
8
+
9
+
10
+ def get_plot(period=1):
11
+ global plot_end
12
+ x = np.arange(plot_end - 2 * math.pi, plot_end, 0.02)
13
+ y = np.sin(2*math.pi*period * x)
14
+ fig = px.line(x=x, y=y)
15
+ plot_end += 2 * math.pi
16
+ if plot_end > 1000:
17
+ plot_end = 2 * math.pi
18
+ return fig
19
+
20
+
21
+ with gr.Blocks() as demo:
22
+ with gr.Row():
23
+ with gr.Column():
24
+ gr.Markdown("Change the value of the slider to automatically update the plot")
25
+ period = gr.Slider(label="Period of plot", value=1, minimum=0, maximum=10, step=1)
26
+ plot = gr.Plot(label="Plot (updates every half second)")
27
+
28
+ dep = demo.load(get_plot, None, plot, every=1)
29
+ period.change(get_plot, period, plot, every=1, cancels=[dep])
30
+
31
+
32
+ if __name__ == "__main__":
33
+ demo.queue().launch()