Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
import subprocess
|
| 4 |
+
import tempfile
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def runCAS(src_str):
|
| 8 |
+
with tempfile.NamedTemporaryFile(mode="w", suffix=".sage") as tmp:
|
| 9 |
+
tmp.write(src_str)
|
| 10 |
+
tmp.flush()
|
| 11 |
+
output, err = subprocess.Popen(["sage", tmp.name], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
|
| 12 |
+
return output.decode('utf-8') + err.decode('utf-8')
|
| 13 |
+
|
| 14 |
+
my_examples = [
|
| 15 |
+
["""x = var('x')
|
| 16 |
+
print(diff(ln(x^2 + 1), x))
|
| 17 |
+
"""],
|
| 18 |
+
["""x, y = var('x y')
|
| 19 |
+
print(solve([y == (x-2)/(x+2)], x))
|
| 20 |
+
"""],
|
| 21 |
+
["""x, y = var('x y')
|
| 22 |
+
f = (3*x + 7, log(x*y))
|
| 23 |
+
J = jacobian(f, [x,y])
|
| 24 |
+
print(J)
|
| 25 |
+
"""]
|
| 26 |
+
]
|
| 27 |
+
|
| 28 |
+
#def greet(name):
|
| 29 |
+
# return "Hello " + name + "!!"
|
| 30 |
+
|
| 31 |
+
demo = gr.Interface(fn=runCAS,
|
| 32 |
+
title="SageMath Online Tool (For LLM)",
|
| 33 |
+
inputs="textarea",
|
| 34 |
+
outputs="textarea",
|
| 35 |
+
examples=my_examples)
|
| 36 |
+
demo.queue().launch()
|