LordXido commited on
Commit
6bd284d
·
verified ·
1 Parent(s): 6a61d7c

Create api/server.py

Browse files
Files changed (1) hide show
  1. api/server.py +22 -0
api/server.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ import subprocess
3
+ import tempfile
4
+
5
+ app = FastAPI()
6
+
7
+ @app.post("/run")
8
+ def run_program(program_hex: str):
9
+ with tempfile.NamedTemporaryFile(delete=False) as f:
10
+ f.write(bytes.fromhex(program_hex))
11
+ f.flush()
12
+
13
+ result = subprocess.run(
14
+ ["/app/bcn-vm", f.name],
15
+ capture_output=True,
16
+ text=True
17
+ )
18
+
19
+ return {
20
+ "stdout": result.stdout,
21
+ "stderr": result.stderr
22
+ }