aboutsummaryrefslogtreecommitdiffstats
path: root/extensions-builtin/Lora/scripts
diff options
context:
space:
mode:
authorSayo <ws11579@gmail.com>2023-05-08 12:38:10 +0000
committerSayo <ws11579@gmail.com>2023-05-08 12:38:10 +0000
commitf9abe4cddcdc6704be02633d9d5ed9640d6b9008 (patch)
tree51fa484dc7e7d92309a6bfe2bcb9d2ffdb432a7b /extensions-builtin/Lora/scripts
parent34a82a345abe89faafbd43fa34f40dd110559071 (diff)
downloadstable-diffusion-webui-gfx803-f9abe4cddcdc6704be02633d9d5ed9640d6b9008.tar.gz
stable-diffusion-webui-gfx803-f9abe4cddcdc6704be02633d9d5ed9640d6b9008.tar.bz2
stable-diffusion-webui-gfx803-f9abe4cddcdc6704be02633d9d5ed9640d6b9008.zip
Add api method to get LoRA models with prompt
Diffstat (limited to 'extensions-builtin/Lora/scripts')
-rw-r--r--extensions-builtin/Lora/scripts/api.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/extensions-builtin/Lora/scripts/api.py b/extensions-builtin/Lora/scripts/api.py
new file mode 100644
index 00000000..f1f2e2fc
--- /dev/null
+++ b/extensions-builtin/Lora/scripts/api.py
@@ -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]
+