🚧 Mount app to WebUI

main
huchenlei 2023-05-17 22:23:11 -04:00
parent 8301b752bc
commit c29c28ffbe
4 changed files with 30 additions and 18 deletions

View File

@ -4,10 +4,14 @@
<meta charset="UTF-8">
<link rel="icon" href="/favicon.ico">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title>
<title>Openpose Editor</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
<script>
// Accessing data passed from FastAPI
window.dataFromServer = {{ data | safe }};
</script>
</body>
</html>

View File

@ -3,32 +3,34 @@ from fastapi import FastAPI, Request
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from jinja2 import FileSystemLoader
from pydantic import BaseModel
import modules.scripts as scripts
import modules.script_callbacks as script_callbacks
VERSION = '0.0.1'
EXTENSION_DIR = 'extensions/sd-webui-openpose-editor'
TEMPLATES_DIR = f'{EXTENSION_DIR}/templates'
import os
class Item(BaseModel):
# base64 encoded image.
image: str
# stringified pose JSON.
pose: str
custom_templates_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'custom_templates')
EXTENSION_DIR = 'extensions/sd-webui-openpose-editor'
DIST_DIR = f'{EXTENSION_DIR}/dist'
def mount_openpose_api(_: gr.Blocks, app: FastAPI):
templates = Jinja2Templates(directory=TEMPLATES_DIR)
# Configure the Jinja2 template loader to search for templates in both folders
app.jinja_loader = FileSystemLoader([custom_templates_path])
@app.get("/openpose_editor/greeting", response_class=HTMLResponse)
async def display_greeting(request: Request):
print('pose:', os.getcwd())
return templates.TemplateResponse('greetings.html', {"request": request, 'name': "Charlie"})
templates = Jinja2Templates(directory=DIST_DIR)
app.mount('/openpose_editor', StaticFiles(directory=DIST_DIR, html=True), name='openpose_editor')
@app.post('/openpose_editor')
async def index():
pass
@app.get('/openpose_editor_index/', response_class=HTMLResponse)
async def index_get(request: Request):
return templates.TemplateResponse('index.html', {"request": request})
@app.post('/openpose_editor_index/', response_class=HTMLResponse)
async def index_post(request: Request, item: Item):
return templates.TemplateResponse('index.html', {"request": request, "data": item.dict()})
script_callbacks.on_app_started(mount_openpose_api)

3
test_post.py Normal file
View File

@ -0,0 +1,3 @@
import requests
print(requests.post('http://localhost:7860/openpose_editor_index/', json={"image": 'AAA', 'pose': 'pose'}).text)

View File

@ -6,6 +6,9 @@ import vueJsx from '@vitejs/plugin-vue-jsx'
// https://vitejs.dev/config/
export default defineConfig({
base: process.env.NODE_ENV === 'production'
? '/openpose_editor/'
: '/',
plugins: [vue(), vueJsx()],
resolve: {
alias: {