diff --git a/tools/flaskIfc/flaskIfc.py b/tools/flaskIfc/flaskIfc.py
index 4d65c9a7ffa0e..bba12448a1177 100644
--- a/tools/flaskIfc/flaskIfc.py
+++ b/tools/flaskIfc/flaskIfc.py
@@ -1,5 +1,9 @@
from flask import Flask, render_template, request
import subprocess
+import threading
+import time
+
+job_status = {"running": False, "result": "", "thread": None}
app = Flask(__name__)
@@ -9,6 +13,11 @@ def index():
@app.route('/submit', methods=['POST'])
def submit():
+ global job_status
+
+ if job_status["running"]:
+ return "
A model is already running. Please wait or abort.
"
+
#./run_platform_test.sh "my cat's name" "10" "tinyllama-vo-5m-para.gguf" "none"
model = request.form.get('model')
backend = request.form.get('backend')
@@ -25,7 +34,6 @@ def submit():
if not model_path:
return f"Error: Model path not found for '{model}'
"
- # Below is for reference i will remove later
# Build llama-cli command
#command = [
# "./llama-cli",
@@ -43,18 +51,45 @@ def submit():
# Currently the baudrate is hard coded to 921600 but can be parameterized
baudrate = '921600'
-
script_path = "/usr/bin/tsi/v0.1.1.tsv31_06_06_2025/bin/run_platform_test.sh"
command = f"{script_path} \"{prompt}\" {tokens} {model_path} {backend}"
- try:
- result = subprocess.run(['python3', 'serial_script.py', port, baudrate, command], capture_output=True, text=True, check=True)
- output = result.stdout # This should have \n
- except subprocess.CalledProcessError as e:
- output = f"Error running model: {e.stderr}"
+ def run_script():
+ try:
+ result = subprocess.run(['python3', 'serial_script.py', port, baudrate, command], capture_output=True, text=True, check=True)
+ job_status["result"] = result.stdout
+ except subprocess.CalledProcessError as e:
+ job_status["result"] = f"Error: {e.stderr}"
+ finally:
+ job_status["running"] = False
+
+ thread = threading.Thread(target=run_script)
+ job_status = {"running": True, "result": "", "thread": thread}
+ thread.start()
+
+ return render_template("processing.html")
+
+@app.route('/status')
+def status():
+ if job_status["running"]:
+ return "running"
+ else:
+ return "done"
+
+@app.route('/result')
+def result():
+ return render_template("result.html", output=job_status["result"])
- return render_template('result.html', output=output)
+@app.route('/abort')
+def abort():
+ global job_status
+ if job_status["running"] and job_status["thread"].is_alive():
+ # Use subprocess.Popen + pid handling instead for real process termination
+ job_status["running"] = False
+ job_status["result"] = "Aborted by user."
+ return "Job aborted.
Home"
+ return "No job running.
Home"
if __name__ == '__main__':
app.run(debug=True, port=5000)
diff --git a/tools/flaskIfc/templates/processing.html b/tools/flaskIfc/templates/processing.html
new file mode 100644
index 0000000000000..15f609bee1712
--- /dev/null
+++ b/tools/flaskIfc/templates/processing.html
@@ -0,0 +1,22 @@
+
+
+
+ Processing
+
+
+
+ Model is running...
+
+
+