diff --git a/Makefile b/Makefile index 23fc26d..687648e 100644 --- a/Makefile +++ b/Makefile @@ -9,9 +9,6 @@ help: @echo " " @echo " build-push build image and upload to ghcr.io" @echo " " - @echo " deploy deploy example to registered 'docker_dev' for Nextcloud Last" - @echo " deploy27 deploy example to registered 'docker_dev' for Nextcloud 27" - @echo " " @echo " run install AIImageGeneratorBot for Nextcloud Last" @echo " run27 install AIImageGeneratorBot for Nextcloud 27" @echo " " @@ -26,18 +23,6 @@ build-push: docker login ghcr.io docker buildx build --push --platform linux/arm64/v8,linux/amd64 --tag ghcr.io/cloud-py-api/ai_image_generator_bot:2.0.0 --tag ghcr.io/cloud-py-api/ai_image_generator_bot:latest . -.PHONY: deploy -deploy: - docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:unregister ai_image_generator_bot --silent --force || true - docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:deploy ai_image_generator_bot \ - --info-xml https://raw.githubusercontent.com/cloud-py-api/ai_image_generator_bot/main/appinfo/info.xml - -.PHONY: deploy27 -deploy27: - docker exec master-stable27-1 sudo -u www-data php occ app_api:app:unregister ai_image_generator_bot --silent --force || true - docker exec master-stable27-1 sudo -u www-data php occ app_api:app:deploy ai_image_generator_bot \ - --info-xml https://raw.githubusercontent.com/cloud-py-api/ai_image_generator_bot/main/appinfo/info.xml - .PHONY: run run: docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:unregister ai_image_generator_bot --silent --force || true @@ -54,12 +39,12 @@ run27: register: docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:unregister ai_image_generator_bot --silent --force || true docker exec master-nextcloud-1 sudo -u www-data php occ app_api:app:register ai_image_generator_bot manual_install --json-info \ - "{\"appid\":\"ai_image_generator_bot\",\"name\":\"AIImageGeneratorBot\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9080,\"scopes\":[\"TALK\", \"TALK_BOT\", \"FILES\", \"FILES_SHARING\"],\"system_app\":1}" \ + "{\"id\":\"ai_image_generator_bot\",\"name\":\"AIImageGeneratorBot\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9080,\"scopes\":[\"TALK\", \"TALK_BOT\", \"FILES\", \"FILES_SHARING\"],\"system\":1}" \ --force-scopes --wait-finish .PHONY: register27 register27: docker exec master-stable27-1 sudo -u www-data php occ app_api:app:unregister ai_image_generator_bot --silent --force || true docker exec master-stable27-1 sudo -u www-data php occ app_api:app:register ai_image_generator_bot manual_install --json-info \ - "{\"appid\":\"ai_image_generator_bot\",\"name\":\"AIImageGeneratorBot\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9080,\"scopes\":[\"TALK\", \"TALK_BOT\", \"FILES\", \"FILES_SHARING\"],\"system_app\":1}" \ + "{\"id\":\"ai_image_generator_bot\",\"name\":\"AIImageGeneratorBot\",\"daemon_config_name\":\"manual_install\",\"version\":\"1.0.0\",\"secret\":\"12345\",\"port\":9080,\"scopes\":[\"TALK\", \"TALK_BOT\", \"FILES\", \"FILES_SHARING\"],\"system\":1}" \ --force-scopes --wait-finish diff --git a/lib/main.py b/lib/main.py index ebb5b6b..8aa2302 100644 --- a/lib/main.py +++ b/lib/main.py @@ -15,8 +15,8 @@ from huggingface_hub import snapshot_download from nc_py_api import AsyncNextcloudApp, NextcloudApp from nc_py_api.ex_app import ( + AppAPIAuthMiddleware, LogLvl, - anc_app, atalk_bot_msg, persistent_storage, run_app, @@ -32,7 +32,7 @@ @asynccontextmanager -async def lifespan(_app: FastAPI): +async def lifespan(app: FastAPI): if torch.cuda.is_available() or torch.backends.mps.is_available(): allow_patterns = ["*.fp16.safetensors", "*.json", "*.txt"] ignore_patterns = None @@ -42,7 +42,7 @@ async def lifespan(_app: FastAPI): allow_patterns = None ignore_patterns = ["*onnx*", "*fp16*", "sd_xl_turbo_1*"] set_handlers( - APP, + app, enabled_handler, models_to_fetch={ MODEL_NAME: { @@ -57,6 +57,7 @@ async def lifespan(_app: FastAPI): APP = FastAPI(lifespan=lifespan) +APP.add_middleware(AppAPIAuthMiddleware) SD_BOT = AsyncTalkBot( "/stable_diffusion", "Stable Diffusion", @@ -128,7 +129,6 @@ async def stable_diffusion_process_request(message: TalkBotMessage): @APP.post("/stable_diffusion") async def stable_diffusion( message: Annotated[TalkBotMessage, Depends(atalk_bot_msg)], - _nc: Annotated[AsyncNextcloudApp, Depends(anc_app)], background_tasks: BackgroundTasks, ): if message.object_name == "message" and message.actor_id.startswith("users/"): diff --git a/requirements.txt b/requirements.txt index 7f14a1e..8ee03d6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -nc_py_api[app]>=0.9.0 +nc_py_api[app]>=0.10.0 diffusers>=0.23.1 transformers>=4.36.1 accelerate