diff --git a/install.py b/install.py index a96083f..a41a4ca 100644 --- a/install.py +++ b/install.py @@ -1 +1,6 @@ -print("hello world auto-photoshop-sd plugin") \ No newline at end of file +import launch + +print("Auto-Photoshop-SD plugin is installing") +if not launch.is_installed("duckduckgo_search"): + launch.run_pip("install duckduckgo_search==2.8.0", "requirements for Auto-Photoshop Image Search") + \ No newline at end of file diff --git a/scripts/main.py b/scripts/main.py index 1b7d61a..c35b67c 100644 --- a/scripts/main.py +++ b/scripts/main.py @@ -8,4 +8,63 @@ import io import os.path import numpy import itertools +import gradio as gr import torch +from fastapi import FastAPI +from fastapi import APIRouter, Request +from fastapi.responses import StreamingResponse +from modules import script_callbacks, scripts, shared + + +import sys +python_server_dir = 'server/python_server' +extension_dir = scripts.basedir() +python_server_full_path = os.path.join(extension_dir,python_server_dir) +print("python_server_full_path: ",python_server_full_path) +sys.path.insert(0, python_server_full_path) +import search + +router = APIRouter() +@router.get("/config") +async def get_state(): + print("hello get /config auto-photoshop-sd") + res = "hello get /config auto-photoshop-sd" + return {"res": res} + +@router.post('/search/image/') +async def searchImage(request:Request): + try: + json = await request.json() + except: + json = {} + + + try: + keywords = json.get('keywords','cute dogs') + images = await search.imageSearch(keywords) + print(images) + + + return {"images":images} + except: + print("keywords",keywords) + # print(f'{request}') + return {"error": "error message: can't preform an image search"} + + + + +def on_app_started(demo: gr.Blocks, app: FastAPI): + # print("hello on_app_started auto-photoshop-plugin") + + if shared.cmd_opts.api: + app.include_router(router, prefix="/sdapi/auto-photoshop-sd", tags=['Auto Photoshop SD Plugin API']) + + + else: + print("COMMANDLINE_ARGS does not contain --api, API won't be mounted.") + + # logger.warning("COMMANDLINE_ARGS does not contain --api, API won't be mounted.") + # if you wanted to do anything massive to the UI, you could modify demo, but why? + +script_callbacks.on_app_started(on_app_started) \ No newline at end of file diff --git a/scripts/test.py b/scripts/test.py new file mode 100644 index 0000000..f265777 --- /dev/null +++ b/scripts/test.py @@ -0,0 +1,5 @@ +# import sys +# sys.path.insert(0, 'server/python_server') +# import search + +# print("hello test.py") \ No newline at end of file diff --git a/sdapi_py_re.js b/sdapi_py_re.js index 450aab1..ae6a65b 100644 --- a/sdapi_py_re.js +++ b/sdapi_py_re.js @@ -406,7 +406,9 @@ async function requestGetOptions() { async function imageSearch(keywords) { let json = {} - const full_url = 'http://127.0.0.1:8000/search/image/' + + + const full_url = `${g_sd_url}/sdapi/auto-photoshop-sd/search/image/` try { payload = { keywords: keywords, diff --git a/server/python_server/search.py b/server/python_server/search.py index e184f31..6aa4e64 100644 --- a/server/python_server/search.py +++ b/server/python_server/search.py @@ -1,4 +1,11 @@ -from duckduckgo_search import ddg_images + +try: + from duckduckgo_search import ddg_images +except ImportError: + raise ImportError( + "duckduckgo_search is required to image search. Please install it with `pip install duckduckgo_search`." + ) + async def imageSearch(keywords = 'cute cats'):