Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,20 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
import subprocess
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
result = subprocess.run(
|
| 10 |
-
["node", "sample.js", a],
|
| 11 |
-
capture_output=True, text=True
|
| 12 |
-
)
|
| 13 |
|
| 14 |
-
|
| 15 |
-
print("Final Output from JS:", final_output)
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
|
|
|
| 1 |
+
from flask import Flask, jsonify
|
|
|
|
| 2 |
import subprocess
|
| 3 |
|
| 4 |
+
app = Flask(__name__)
|
| 5 |
+
|
| 6 |
+
@app.route("/")
|
| 7 |
+
def index():
|
| 8 |
+
# Python variable
|
| 9 |
+
a = "Hello World"
|
| 10 |
+
|
| 11 |
+
# Run JS script with subprocess
|
| 12 |
+
result = subprocess.run(["node", "sample.js", a], capture_output=True, text=True)
|
| 13 |
|
| 14 |
+
# Get JS output
|
| 15 |
+
output = result.stdout.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
return jsonify({"response": output})
|
|
|
|
| 18 |
|
| 19 |
+
if __name__ == "__main__":
|
| 20 |
+
app.run(host="0.0.0.0", port=7860)
|