diff --git a/tools/flaskIfc/flaskIfc.py b/tools/flaskIfc/flaskIfc.py index bba12448a1177..7d2333b36e0ce 100644 --- a/tools/flaskIfc/flaskIfc.py +++ b/tools/flaskIfc/flaskIfc.py @@ -11,6 +11,56 @@ def index(): return render_template('index.html') +@app.route('/llama-cli', methods=['GET']) +def serial_command(): + # Currently the port is hard coded to /dev/ttyUSB3 but can be parameterized + port = '/dev/ttyUSB3' + #port = request.args.get('port') + + # Currently the baudrate is hard coded to 921600 but can be parameterized + #baudrate = request.args.get('baudrate') + baudrate = '921600' + #./run_platform_test.sh "my cat's name" "10" "tinyllama-vo-5m-para.gguf" "none" + model = request.args.get('model') + backend = request.args.get('backend') + tokens = request.args.get('tokens') + prompt = request.args.get('prompt') + + # Define the model path (update with actual paths) + model_paths = { + "tiny-llama": "tinyllama-vo-5m-para.gguf", + "Tiny-llama-F32": "Tiny-Llama-v0.3-FP32-1.1B-F32.gguf" + } + + model_path = model_paths.get(model, "") + if not model_path: + return f"

Error: Model path not found for '{model}'

" + + # Build llama-cli command + #command = [ + # "./llama-cli", + # "-p", prompt, + # "-m", model_path, + # "--device", backend, + # "--temp", "0", + # "--n-predict", tokens, + # "--repeat-penalty", "1", + # "--top-k", "0", + # "--top-p", "1" + #] + # URL to Test this end point is as follows + # http://10.50.30.167:5001/llama-cli?model=tiny-llama&backend=tSavorite&tokens=5&prompt=Hello+How+are+you + 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) + return result.stdout, 200 + except subprocess.CalledProcessError as e: + return f"Error executing script: {e.stderr}", 500 + + + @app.route('/submit', methods=['POST']) def submit(): global job_status diff --git a/tools/flaskIfc/serial_script.py b/tools/flaskIfc/serial_script.py index a91587341e557..38a53d103f0c8 100644 --- a/tools/flaskIfc/serial_script.py +++ b/tools/flaskIfc/serial_script.py @@ -6,15 +6,21 @@ def send_serial_command(port, baudrate, command): ser = serial.Serial(port, baudrate) ser.write((command + '\n').encode()) # Send command with newline - # Wait to read the serial port data = '\0' while True: try: - line = ser.readline() + # read byte by byte to find either a new line character or a prompt marker + # instead of new line using line = ser.readline() + line = b"" + while True: + byte = ser.read(1) # Read one byte at a time + if (byte == b"\n") or (byte == b"#"): # Stop when delimiter is found + break + line += byte if line: # Check if line is not empty read_next_line = line.decode('utf-8') - if ("run-platform-done" in read_next_line) or ("@agilex7_dk_si_agf014ea" in read_next_line): + if ("run-platform-done" in read_next_line.strip()) or ("@agilex7_dk_si_agf014ea" in read_next_line.strip()) or ("imx8mpevk" in read_next_line.strip()): break data += read_next_line # Keep the line as-is with newline else: