sagemathtool / app.py
lemonteaa's picture
Update app.py
5472480 verified
raw
history blame contribute delete
931 Bytes
import gradio as gr
import subprocess
import tempfile
print("Begin app")
def runCAS(src_str):
with tempfile.NamedTemporaryFile(mode="w", suffix=".sage") as tmp:
tmp.write(src_str)
tmp.flush()
output, err = subprocess.Popen(["sage", tmp.name], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
return output.decode('utf-8') + err.decode('utf-8')
my_examples = [
["""x = var('x')
print(diff(ln(x^2 + 1), x))
"""],
["""x, y = var('x y')
print(solve([y == (x-2)/(x+2)], x))
"""],
["""x, y = var('x y')
f = (3*x + 7, log(x*y))
J = jacobian(f, [x,y])
print(J)
"""]
]
#def greet(name):
# return "Hello " + name + "!!"
demo = gr.Interface(fn=runCAS,
title="SageMath Online Tool (For LLM)",
inputs="textarea",
outputs="textarea",
examples=my_examples)
demo.queue(max_size=20)
demo.launch()