-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
48 lines (37 loc) · 1.48 KB
/
Copy pathmain.py
File metadata and controls
48 lines (37 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from fastapi import FastAPI
import fastapi as _fapi
import schemas as _schemas
import services as _services
from prompt import *
from img2img import img2img
from txt2img import *
import io
import pydantic as pydantic
app = FastAPI()
import base64
from http.client import HTTPException
@app.get("/")
def read_root():
return {"message": "Welcome to Stable Diffussers API"}
# Endpoint to test the Front-end and backend
@app.get("/api")
async def root():
return {"message": "Welcome to the Demo of StableDiffusers with FastAPI"}
@app.post("/generate-image")
async def modify_image_test(text_prompt:_schemas.SpringRequest):
imgPrompt=_schemas.ImageCreate(prompt = prompt_api(text_prompt.prompt))
#imgPrompt=_schemas.ImageCreate(prompt = text_prompt.prompt)
image_url = await txt2img(imgPrompt)
return image_url
@app.post("/modify-image")
async def modify_image_test(imgPrompt:_schemas.SpringRequest):
image_url=imgPrompt.imageURL # 이미지 url
tmp = image_url.split('=')
seed = str(tmp[1]).split('.')[0]
seed_check = imgPrompt.seed
if seed_check == False : seed = -1
logging.info(f"input seed: {seed}")
imgPromptCreate=_schemas.ImageCreate(prompt = prompt_api(imgPrompt.prompt)) # 이미지 프롬프트
#imgPromptCreate=_schemas.ImageCreate(prompt = imgPrompt.prompt) # 이미지 프롬프트
result = await img2img(img_url=image_url,imgPrompt=imgPromptCreate, seed=seed)
return result