Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 43 additions & 8 deletions tools/flaskIfc/flaskIfc.py
Original file line number Diff line number Diff line change
@@ -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__)

Expand All @@ -9,6 +13,11 @@ def index():

@app.route('/submit', methods=['POST'])
def submit():
global job_status

if job_status["running"]:
return "<h2>A model is already running. Please wait or abort.</h2>"

#./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')
Expand All @@ -25,7 +34,6 @@ def submit():
if not model_path:
return f"<h2>Error: Model path not found for '{model}'</h2>"

# Below is for reference i will remove later
# Build llama-cli command
#command = [
# "./llama-cli",
Expand All @@ -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 "<h2>Job aborted.</h2><a href='/'>Home</a>"
return "<h2>No job running.</h2><a href='/'>Home</a>"

if __name__ == '__main__':
app.run(debug=True, port=5000)
22 changes: 22 additions & 0 deletions tools/flaskIfc/templates/processing.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<title>Processing</title>
<script>
function checkStatus() {
fetch('/status')
.then(response => response.text())
.then(status => {
if (status === 'done') {
window.location.href = '/result';
}
});
}
setInterval(checkStatus, 3000);
</script>
</head>
<body>
<h1>Model is running...</h1>
<button onclick="location.href='/abort'">Abort</button>
</body>
</html>