sreepathi-ravikumar commited on
Commit
7531ae8
·
verified ·
1 Parent(s): 047dc16

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -1,18 +1,20 @@
1
- # app.py
2
-
3
  import subprocess
4
 
5
- a = "Hello World" # Static value to send to JS
 
 
 
 
 
 
 
 
6
 
7
- try:
8
- # Call sample.js and pass variable `a` as argument
9
- result = subprocess.run(
10
- ["node", "sample.js", a],
11
- capture_output=True, text=True
12
- )
13
 
14
- final_output = result.stdout.strip()
15
- print("Final Output from JS:", final_output)
16
 
17
- except Exception as e:
18
- print("Error:", str(e))
 
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)