-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): add read only flask server
- added the following endpoints: /v1/backends (lists all backends and path) /v1/health (heartbeat) /v1/tasks (gets current task info, includes name, status, progress, and log file) /v1/models (gets name, model type, path, and shard status)
- Loading branch information
Showing
3 changed files
with
86 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -5,4 +5,5 @@ torch~=1.13.1 | |
sentencepiece~=0.2.0 | ||
PyYAML~=6.0.2 | ||
pynvml~=11.5.3 | ||
PySide6~=6.7.2 | ||
PySide6~=6.7.2 | ||
flask~=3.0.3 |
This file contains 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 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,9 +1,54 @@ | ||
import sys | ||
import threading | ||
|
||
from PySide6.QtCore import QTimer | ||
from PySide6.QtWidgets import QApplication | ||
from AutoGGUF import AutoGGUF | ||
from flask import Flask, jsonify | ||
|
||
server = Flask(__name__) | ||
|
||
|
||
@server.route("/v1/models", methods=["GET"]) | ||
def models(): | ||
if window: | ||
return jsonify({"models": window.get_models_data()}) | ||
return jsonify({"models": []}) | ||
|
||
|
||
@server.route("/v1/tasks", methods=["GET"]) | ||
def tasks(): | ||
if window: | ||
return jsonify({"tasks": window.get_tasks_data()}) | ||
return jsonify({"tasks": []}) | ||
|
||
|
||
@server.route("/v1/health", methods=["GET"]) | ||
def ping(): | ||
return jsonify({"status": "alive"}) | ||
|
||
|
||
@server.route("/v1/backends", methods=["GET"]) | ||
def get_backends(): | ||
backends = [] | ||
for i in range(window.backend_combo.count()): | ||
backends.append( | ||
{ | ||
"name": window.backend_combo.itemText(i), | ||
"path": window.backend_combo.itemData(i), | ||
} | ||
) | ||
return jsonify({"backends": backends}) | ||
|
||
|
||
def run_flask(): | ||
server.run(host="0.0.0.0", port=5000, debug=False, use_reloader=False) | ||
|
||
|
||
if __name__ == "__main__": | ||
app = QApplication(sys.argv) | ||
window = AutoGGUF() | ||
window.show() | ||
sys.exit(app.exec()) | ||
app = QApplication(sys.argv) | ||
window = AutoGGUF() | ||
window.show() | ||
# Start Flask in a separate thread after a short delay | ||
timer = QTimer() | ||
timer.singleShot(100, lambda: threading.Thread(target=run_flask, daemon=True).start()) | ||
sys.exit(app.exec()) |