Skip to content

Commit

Permalink
Improve CLI & OpenAPI metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
hv0905 committed Jul 5, 2024
1 parent 6356bd5 commit 2f0b3c5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
6 changes: 6 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
__title__ = 'NekoImageGallery'
__description__ = 'An AI-powered natural language & reverse Image Search Engine powered by CLIP & qdrant.'
__version__ = '1.2.0'
__author__ = 'EdgeNeko; pk5ls20'
__author_email__ = '[email protected]'
__url__ = 'https://github.com/hv0905/NekoImageGallery'
4 changes: 3 additions & 1 deletion app/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from fastapi.params import Depends
from fastapi.staticfiles import StaticFiles

import app
import app.Controllers.admin as admin_controller
import app.Controllers.search as search_controller
from app.Services.authentication import permissive_access_token_verify, permissive_admin_token_verify
Expand All @@ -30,9 +31,10 @@ async def lifespan(_: FastAPI):
await provider.onexit()


app = FastAPI(lifespan=lifespan)
app = FastAPI(lifespan=lifespan, title=app.__title__, description=app.__description__, version=app.__version__)
init_logging()

# noinspection PyTypeChecker
app.add_middleware(
CORSMiddleware,
allow_origins=config.cors_origins,
Expand Down
22 changes: 15 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@
import typer
import uvicorn

__version__ = '1.2.0'
import app

parser = typer.Typer(name='NekoImageGallery Server',
help='Ciallo~ Welcome to NekoImageGallery Server.\n\nBy default, running without command will '
'start the server. You can perform other actions by using the commands below.',
parser = typer.Typer(name=app.__title__,
epilog="Build with ♥ By EdgeNeko. Github: "
"https://github.com/hv0905/NekoImageGallery"
"https://github.com/hv0905/NekoImageGallery",
rich_markup_mode='markdown'
)


def version_callback(value: bool):
if value:
print(f"NekoImageGallery v{__version__}")
print(f"{app.__title__} v{app.__version__}")
raise typer.Exit()


Expand All @@ -35,7 +34,16 @@ def server(ctx: typer.Context,
] = None
):
"""
Start the server with the specified host, port and root path.
Ciallo~ Welcome to NekoImageGallery Server.
- Website: https://image-insight.edgneko.com
- Repository & Issue tracker: https://github.com/hv0905/NekoImageGallery
By default, running without command will start the server.
You can perform other actions by using the commands below.
"""
if ctx.invoked_subcommand is not None:
return
Expand Down
15 changes: 11 additions & 4 deletions scripts/local_indexing.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import sys
from datetime import datetime
from pathlib import Path

import PIL
from loguru import logger
from rich.progress import Progress

from app.Models.api_models.admin_query_params import UploadImageThumbnailMode
from app.Models.errors import PointDuplicateError
Expand Down Expand Up @@ -36,9 +38,14 @@ async def main(root_directory: Path, categories: list[str], starred: bool):
services = ServiceProvider()
await services.onload()
root = Path(root_directory)

for idx, item in enumerate(glob_local_files(root, '**/*')):
logger.info("[{}] Indexing {}", idx, str(item))
await index_task(item, categories, starred)
files = list(glob_local_files(root, '**/*'))
with Progress() as progress:
# A workaround for the loguru logger to work with rich progressbar
logger.remove()
logger.add(sys.stderr, colorize=True)
for idx, item in enumerate(progress.track(files, description="Indexing...")):
logger.info("[{} / {}] Indexing {}", idx + 1, len(files), str(item))

await index_task(item, categories, starred)

logger.success("Indexing completed!")

0 comments on commit 2f0b3c5

Please sign in to comment.