File size: 931 Bytes
ae7ce37
 
 
 
 
5472480
ae7ce37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5472480
 
 
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
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()