From 34a82a345abe89faafbd43fa34f40dd110559071 Mon Sep 17 00:00:00 2001 From: Sayo Date: Mon, 8 May 2023 19:55:05 +0800 Subject: [PATCH] Add api method to get LoRA models --- extensions-builtin/Lora/lora.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/extensions-builtin/Lora/lora.py b/extensions-builtin/Lora/lora.py index d488b5ae4..8fc1ddcac 100644 --- a/extensions-builtin/Lora/lora.py +++ b/extensions-builtin/Lora/lora.py @@ -2,7 +2,9 @@ import glob import os import re import torch -from typing import Union +from typing import Union, List, Optional +from fastapi import FastAPI +import gradio as gr from modules import shared, devices, sd_models, errors, scripts @@ -443,9 +445,19 @@ def infotext_pasted(infotext, params): if added: params["Prompt"] += "\n" + "".join(added) +def api(_: gr.Blocks, app: FastAPI): + @app.get("/sdapi/v1/loras") + async def getloras(): + return [{"name": name, "path": available_loras[name].filename, "prompt": ""} for name in available_loras] + available_loras = {} available_lora_aliases = {} loaded_loras = [] list_available_loras() +try: + import modules.script_callbacks as script_callbacks + script_callbacks.on_app_started(api) +except: + pass \ No newline at end of file