Merge pull request #10194 from DumoeDss/dev
Add api method to get LoRA models with prompt
This commit is contained in:
commit
7e02a00c81
@ -3,6 +3,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
import torch
|
import torch
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
import scripts.api as api
|
||||||
|
|
||||||
from modules import shared, devices, sd_models, errors, scripts
|
from modules import shared, devices, sd_models, errors, scripts
|
||||||
|
|
||||||
@ -443,9 +444,13 @@ def infotext_pasted(infotext, params):
|
|||||||
if added:
|
if added:
|
||||||
params["Prompt"] += "\n" + "".join(added)
|
params["Prompt"] += "\n" + "".join(added)
|
||||||
|
|
||||||
|
|
||||||
available_loras = {}
|
available_loras = {}
|
||||||
available_lora_aliases = {}
|
available_lora_aliases = {}
|
||||||
loaded_loras = []
|
loaded_loras = []
|
||||||
|
|
||||||
list_available_loras()
|
list_available_loras()
|
||||||
|
try:
|
||||||
|
import modules.script_callbacks as script_callbacks
|
||||||
|
script_callbacks.on_app_started(api.api)
|
||||||
|
except:
|
||||||
|
pass
|
31
extensions-builtin/Lora/scripts/api.py
Normal file
31
extensions-builtin/Lora/scripts/api.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
from fastapi import FastAPI
|
||||||
|
import gradio as gr
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import lora
|
||||||
|
|
||||||
|
def get_lora_prompts(path):
|
||||||
|
directory, filename = os.path.split(path)
|
||||||
|
name_without_ext = os.path.splitext(filename)[0]
|
||||||
|
new_filename = name_without_ext + '.civitai.info'
|
||||||
|
try:
|
||||||
|
new_path = os.path.join(directory, new_filename)
|
||||||
|
if os.path.exists(new_path):
|
||||||
|
with open(new_path, 'r') as f:
|
||||||
|
data = json.load(f)
|
||||||
|
trained_words = data.get('trainedWords', [])
|
||||||
|
if len(trained_words) > 0:
|
||||||
|
result = ','.join(trained_words)
|
||||||
|
return result
|
||||||
|
else:
|
||||||
|
return ''
|
||||||
|
else:
|
||||||
|
return ''
|
||||||
|
except Exception as e:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
def api(_: gr.Blocks, app: FastAPI):
|
||||||
|
@app.get("/sdapi/v1/loras")
|
||||||
|
async def get_loras():
|
||||||
|
return [{"name": name, "path": lora.available_loras[name].filename, "prompt": get_lora_prompts(lora.available_loras[name].filename)} for name in lora.available_loras]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user