Skip to content

Commit

Permalink
fix: fixed bundling static assets + favicon, so that web ui works whe…
Browse files Browse the repository at this point in the history
…n installed from pypi
  • Loading branch information
ErikBjare committed Aug 8, 2024
1 parent 19fc560 commit 116f847
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
20 changes: 13 additions & 7 deletions gptme/server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
- https://matplotlib.org/stable/gallery/user_interfaces/web_application_server_sgskip.html
"""

import atexit
import io
from contextlib import redirect_stdout
from importlib import resources

import flask
from flask import current_app

from ..commands import execute_cmd
from ..dirs import get_logs_dir
Expand Down Expand Up @@ -123,22 +126,25 @@ def api_conversation_generate(logfile: str):
)


# serve the static assets in the static folder
@api.route("/static/<path:path>")
def static_proxy(path):
return flask.send_from_directory("static", path)
gptme_path_ctx = resources.as_file(resources.files("gptme"))
static_path = gptme_path_ctx.__enter__().parent / "static"
atexit.register(gptme_path_ctx.__exit__, None, None, None)


# serve index.html from the root
@api.route("/")
def root():
return flask.send_from_directory("../../static", "index.html")
return current_app.send_static_file("index.html")


@api.route("/favicon.png")
def favicon():
return flask.send_from_directory(static_path.parent / "media", "logo.png")


def create_app():
app = flask.Flask(__name__, static_folder="../static")
app = flask.Flask(__name__, static_folder=static_path)
app.register_blueprint(api)

return app


Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ packages = [
{ include = "gptme" },
]

include = ["static/**/*", "media/logo.png"]

[tool.poetry.scripts]
gptme = "gptme.cli:main"
gptme-server = "gptme.server.cli:main"
Expand Down
1 change: 1 addition & 0 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html>
<head>
<title>gptme</title>
<link rel="icon" type="image/png" href="/favicon.png">

<!-- Scripts -->
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
Expand Down

0 comments on commit 116f847

Please sign in to comment.