hc1608 commited on
Commit
74a1cef
·
1 Parent(s): 6b83288

requirements.txt

Browse files
Files changed (1) hide show
  1. app.py +167 -0
app.py ADDED
@@ -0,0 +1,167 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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():
11
+ return datetime.datetime.now()
12
+
13
+
14
+ plot_end_1 = 2 * math.pi
15
+ plot_end_2 = 2 * math.pi
16
+ plot_end_3 = 2 * math.pi
17
+
18
+
19
+ def get_plot_v1(period_v1=1,xscale_v1 = 1,yscale_v1 = 1):
20
+ global plot_end_1
21
+ x = np.arange(plot_end_1 - 2 * math.pi, plot_end_1, 0.02)
22
+ #y = np.sin(2 * math.pi * period_v1 * x)
23
+ y = 2.02
24
+ vMean = 2.02
25
+ vPp = 0
26
+ #y = np.float64(0.5)
27
+ update = gr.LinePlot.update(
28
+ value=pd.DataFrame({"x": x, "y": y}),
29
+ x="x",
30
+ y="y",
31
+ title= f"V mean = {vMean},Vpp = {vPp}" ,
32
+ width=500,
33
+ height=350,
34
+ y_lim= [ -4,4],
35
+ y_title = 'V'
36
+ )
37
+ plot_end_1 += 2 * math.pi
38
+ if plot_end_1 > 1000:
39
+ plot_end_1 = 2 * math.pi
40
+ return update
41
+
42
+ def get_plot_i1(period_i1=1,xscale_i1 = 1,yscale_i1 = 1):
43
+ global plot_end_2
44
+ x = np.arange(plot_end_2 - 2 * math.pi, plot_end_2, 0.02)
45
+ #y = np.sin(2 * math.pi * period_i1 * x)
46
+ #y = 0
47
+ iMean = 0
48
+ iPp = 0
49
+ y = np.float64(0)
50
+ update = gr.LinePlot.update(
51
+ value=pd.DataFrame({"x": x, "y": y}),
52
+ x="x",
53
+ y="y",
54
+ title= f"I mean = {iMean},Ipp = {iPp}" ,
55
+ width=500,
56
+ height=350,
57
+ y_lim= [ -100,100],
58
+ y_title = 'mA'
59
+ )
60
+ plot_end_2 += 2 * math.pi
61
+ if plot_end_2 > 1000:
62
+ plot_end_2 = 2 * math.pi
63
+ return update
64
+
65
+ def get_plot_3(period_3=1,xscale_3 = 1,yscale_3 = 1):
66
+ global plot_end_3
67
+ x = np.arange(plot_end_3 - 2 * math.pi, plot_end_3, 0.02)
68
+ y = 0
69
+ #y = np.sin(2 * math.pi * period_3 * x)
70
+ xMean = 0
71
+ xPp = 0
72
+ #y = np.float64(0.5)
73
+ update = gr.LinePlot.update(
74
+ value=pd.DataFrame({"x": x, "y": y}),
75
+ x="x",
76
+ y="y",
77
+ title= f" Mean Value = {xMean}, PP value = {xPp}" ,
78
+ width=600,
79
+ height=350,
80
+ y_lim= [ -4,4],
81
+ y_title = 'V'
82
+ )
83
+ plot_end_3 += 2 * math.pi
84
+ if plot_end_3 > 1000:
85
+ plot_end_3 = 2 * math.pi
86
+ return update
87
+
88
+
89
+ with gr.Blocks() as demo:
90
+ with gr.Row():
91
+ with gr.Column():
92
+ gr.Textbox(
93
+ "Voltage Channel 1",
94
+ label="",
95
+ )
96
+ period_v1 = gr.Slider(
97
+ label="Period of plot", value=1, minimum=0, maximum=10, step=1
98
+ )
99
+ xscale_v1 = gr.Slider(
100
+ label="xscale", value=1, minimum=0, maximum=10, step=1
101
+ )
102
+ yscale_v1 = gr.Slider(
103
+ label="yscale", value=1, minimum=0, maximum=10, step=1
104
+ )
105
+
106
+ plot_v1 = gr.LinePlot(show_label= False )
107
+
108
+ with gr.Column():
109
+ gr.Textbox(
110
+ "Current Channel 1",
111
+ label="",
112
+ )
113
+ period_i1 = gr.Slider(
114
+ label="Period of plot", value=1, minimum=0, maximum=10, step=1
115
+ )
116
+ xscale_i1 = gr.Slider(
117
+ label="xscale", value=1, minimum=0, maximum=10, step=1
118
+ )
119
+ yscale_i1 = gr.Slider(
120
+ label="yscale", value=1, minimum=0, maximum=10, step=1
121
+ )
122
+
123
+ plot_i1 = gr.LinePlot(show_label= False )
124
+
125
+ with gr.Row():
126
+ with gr.Column():
127
+ #gr.inputs.Toggle(default=False, label="Select option A or B")
128
+ gr.Dropdown(
129
+ ["Voltage Channel 2","Current channel 2"], type = "index", multiselect= False, label="Select I or V")
130
+ # gr.Textbox(
131
+ # "I/V Channel 2",
132
+ # label="",
133
+ # )
134
+ period_3 = gr.Slider(
135
+ label="Period of plot", value=1, minimum=0, maximum=10, step=1
136
+ )
137
+ xscale_3 = gr.Slider(
138
+ label="xscale", value=1, minimum=0, maximum=10, step=1
139
+ )
140
+ yscale_3 = gr.Slider(
141
+ label="yscale", value=1, minimum=0, maximum=10, step=1
142
+ )
143
+
144
+ plot_3 = gr.LinePlot(show_label= False )
145
+
146
+
147
+ demo.load(lambda: datetime.datetime.now(), None, every=1)
148
+ dep1 = demo.load(get_plot_i1, None, plot_i1, every=1)
149
+ period_i1.change(get_plot_i1, period_i1, plot_i1, every=1, cancels=[dep1])
150
+ xscale_i1.change(get_plot_i1, xscale_i1, plot_i1, every=1, cancels=[dep1])
151
+ yscale_i1.change(get_plot_i1, yscale_i1, plot_i1, every=1, cancels=[dep1])
152
+
153
+
154
+ demo.load(lambda: datetime.datetime.now(), None, every=1)
155
+ dep = demo.load(get_plot_v1, None, plot_v1, every=1)
156
+ period_v1.change(get_plot_v1, period_v1, plot_v1, every=1, cancels=[dep])
157
+ xscale_v1.change(get_plot_v1, xscale_v1, plot_v1, every=1, cancels=[dep])
158
+ yscale_v1.change(get_plot_v1, yscale_v1, plot_v1, every=1, cancels=[dep])
159
+
160
+ demo.load(lambda: datetime.datetime.now(), None, every=1)
161
+ dep2 = demo.load(get_plot_3, None, plot_3, every=1)
162
+ period_3.change(get_plot_3, period_3, plot_3, every=1, cancels=[dep2])
163
+ xscale_3.change(get_plot_3, xscale_3, plot_3, every=1, cancels=[dep2])
164
+ yscale_3.change(get_plot_3, yscale_3, plot_3, every=1, cancels=[dep2])
165
+
166
+ if __name__ == "__main__":
167
+ demo.queue().launch(debug = True)