File size: 4,260 Bytes
79402cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import gradio as gr
from src.main import get_fn, get_dev, get_tangent_line
from src.piecewise import get_piecewise_fn, get_piecewise_dev
from src.product_rule import get_pr_fn, get_pr_dev

# to run app: python -m gr_app or gradio gr_app.py

fn_fig, dev_fig = None, None
tl_plot = None

with gr.Blocks() as scatterplot:
    with gr.Column():
        with gr.Row():
            inp = gr.Textbox(value = "x**2", 
                            info = "eg 'np.sqrt(x)'", 
                            label = "Enter Your Expression here")
            inp_2 = gr.Textbox(value = "2", 
                       info = "e.g. 2", 
                       label = "Which point on x do you want to draw the tangent line?")
        btn = gr.Button("Run!")

    with gr.Row():
        fn_scatter = gr.Plot(fn_fig)
        dev_scatter = gr.Plot(dev_fig)

    tl_scatter = gr.Plot(tl_plot)

    gr.on(triggers = [inp.submit, btn.click], 
          fn=get_fn, 
          inputs = inp, 
          outputs = fn_scatter)
    gr.on(triggers = [inp.submit, btn.click], 
          fn=get_dev, 
          inputs = inp, 
          outputs = dev_scatter)
    gr.on(triggers = [inp.submit, inp_2.submit, btn.click], 
          fn=get_tangent_line, 
          inputs = [inp, inp_2], 
          outputs=tl_scatter)
    
# dev_obj = None
piecewise_fn_fig, piecewise_dev_fig = None, None
    
with gr.Blocks() as piecewise: 
    with gr.Column():
        with gr.Row():
            with gr.Column():
                inp_func_1 = gr.Textbox(value = "x**2", 
                                info = "eg 'np.sqrt(x)'", 
                                label = "Enter Your Expression here")
                
                inp_sign_1 = gr.Textbox(value = "<", 
                                info = "eg <", 
                                label = "Enter Your Sign Here")
                
            with gr.Column():

                inp_func_2 = gr.Textbox(value = "x**3", 
                        info = "e.g. x**3", 
                        label = "Enter Your Expression here")
                
                inp_sign_2 = gr.Textbox(value = ">=", 
                            info = "eg >=", 
                            label = "Enter Your Sign Here")
                
            inp_point = gr.Textbox(value = "2", 
                       info = "e.g. 2", 
                       label = "Enter where your point will be separating your piecewise function")
            
        btn_3 = gr.Button("Run!")

    with gr.Row():
        piecewise_fn_scatter = gr.Plot(piecewise_fn_fig)
        piecewise_dev_scatter = gr.Plot(piecewise_dev_fig)

    gr.on(triggers = [inp_func_1.submit, inp_func_2.submit, inp_point.submit, inp_sign_1.submit, inp_sign_2.submit, btn_3.click], 
        fn=get_piecewise_fn, 
        inputs = [inp_func_1, inp_func_2, inp_point, inp_sign_1, inp_sign_2],
        outputs = piecewise_fn_scatter)
    
    gr.on(triggers = [inp_func_1.submit, inp_func_2.submit, inp_point.submit, inp_sign_1.submit, inp_sign_2.submit, btn_3.click], 
        fn=get_piecewise_dev, 
        inputs = [inp_func_1, inp_func_2, inp_point, inp_sign_1, inp_sign_2],
        outputs = piecewise_dev_scatter)
    
pr_fn_fig, pr_dev_fig = None, None
    
with gr.Blocks() as product_rule:
    with gr.Column():
        with gr.Row():
            inp = gr.Textbox(value = "x**2", 
                            info = "eg 'np.sqrt(x)'", 
                            label = "Enter Your First Expression here")
            inp_2 = gr.Textbox(value = "x**3", 
                       info = "e.g. x**3", 
                       label = "Enter Your Second Expression Here")
        btn = gr.Button("Run!")

    with gr.Row():
        pr_fn_scatter = gr.Plot(pr_fn_fig)
        dev_scatter = gr.Plot(pr_dev_fig)

    gr.on(triggers = [inp.submit, inp_2.submit, btn.click], 
          fn=get_pr_fn, 
          inputs = [inp, inp_2], 
          outputs = pr_fn_scatter)
    
    gr.on(triggers = [inp.submit, inp_2.submit, btn.click], 
          fn=get_pr_dev, 
          inputs = [inp, inp_2], 
          outputs = dev_scatter)

demo = gr.TabbedInterface([scatterplot, piecewise, product_rule], ["Single Function", "Piecewise Function", "Product Rule"])

if __name__ == "__main__":

    demo.launch()