make an automatic1111 extension

pull/78/head
Abdullah Alfaraj 2023-02-03 17:34:33 +03:00
parent 9e8a77388f
commit 51f57a66da
5 changed files with 81 additions and 3 deletions

View File

@ -1 +1,6 @@
print("hello world auto-photoshop-sd plugin")
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")

View File

@ -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)

5
scripts/test.py Normal file
View File

@ -0,0 +1,5 @@
# import sys
# sys.path.insert(0, 'server/python_server')
# import search
# print("hello test.py")

View File

@ -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,

View File

@ -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'):