tappyness1's picture
Initial Commit
79402cb
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()