forked from ggml-org/llama.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Llama.cpp: Webserver & HTML pages support #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,60 @@ | ||
| from flask import Flask, request | ||
| from flask import Flask, render_template, request | ||
| import subprocess | ||
|
|
||
| app = Flask(__name__) | ||
|
|
||
| @app.route('/serial', methods=['GET']) | ||
| def serial_command(): | ||
| @app.route('/') | ||
| def index(): | ||
| return render_template('index.html') | ||
|
|
||
| @app.route('/submit', methods=['POST']) | ||
| def submit(): | ||
| #./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') | ||
| tokens = request.form.get('tokens') | ||
| prompt = request.form.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"<h2>Error: Model path not found for '{model}'</h2>" | ||
|
|
||
| # Below is for reference i will remove later | ||
| # 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" | ||
| #] | ||
| # 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' | ||
|
|
||
| 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}" | ||
|
|
||
| # Parse the command and send it to serial.py | ||
| command = request.args.get('command') | ||
|
|
||
| #if not all([port, baudrate, command]): | ||
| if not all([command]): | ||
| return "Missing parameters", 400 | ||
|
|
||
| try: | ||
| result = subprocess.run(['python3', 'serial_script.py', port, baudrate, command], capture_output=True, text=True, check=True) | ||
| return result.stdout.strip(), 200 | ||
| output = result.stdout # This should have \n | ||
| except subprocess.CalledProcessError as e: | ||
| return f"Error executing script: {e.stderr}", 500 | ||
| output = f"Error running model: {e.stderr}" | ||
|
|
||
| return render_template('result.html', output=output) | ||
|
|
||
| if __name__ == '__main__': | ||
| app.run(debug=True, port=5000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>TSAVORITE Web UI For Model Inference</title> | ||
| </head> | ||
| <body> | ||
| <h1>Model Inference Configuration</h1> | ||
| <form action="/submit" method="post"> | ||
| <!-- Model Selection --> | ||
| <label for="model">Choose a model:</label> | ||
| <select name="model" id="model"> | ||
| <option value="tiny-llama">Tiny LLaMA</option> | ||
| <option value="Tiny-llama-F32">LLaMA 2 1B</option> | ||
| </select> | ||
| <br><br> | ||
|
|
||
| <!-- Backend Selection --> | ||
| <label for="backend">Select backend:</label> | ||
| <select name="backend" id="backend"> | ||
| <option value="tSavorite">TSAVORITE</option> | ||
| <option value="none">CPU</option> | ||
| </select> | ||
| <br><br> | ||
|
|
||
| <!-- Number of Tokens --> | ||
| <label for="tokens">Number of predicted tokens:</label> | ||
| <input type="number" name="tokens" id="tokens" min="1" max="1000" value="50"> | ||
| <br><br> | ||
|
|
||
| <!-- Prompt Input --> | ||
| <label for="prompt">Prompt:</label><br> | ||
| <textarea name="prompt" id="prompt" rows="4" cols="50" placeholder="Enter your prompt here..."></textarea> | ||
| <br><br> | ||
|
|
||
| <button type="submit">Submit</button> | ||
| </form> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>Model Output</title> | ||
| </head> | ||
| <body> | ||
| <h1>Model Response</h1> | ||
| <pre>{{ output }}</pre> | ||
| <br> | ||
| <a href="/">⟵ Back to Form</a> | ||
| </body> | ||
| </html> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.