edit : 이미지생성 api(gemini) 추가

This commit is contained in:
2025-09-23 09:55:40 +09:00
parent 605a7660c4
commit 39d5683eee
5 changed files with 64 additions and 3 deletions

View File

@@ -26,6 +26,7 @@ class Config:
self.sftp_port = 22
self.sftp_id = "fermat"
self.sftp_pw = "fermat3514"
self.db_pw = "1234"
if not os.path.exists(self.remote_folder):
os.makedirs(self.remote_folder)
@@ -34,6 +35,8 @@ class Config:
self.config = 'release'
self.local_folder = "./result" # 결과물 저장 폴더
self.db_pw = "Fermat3514!"
if not os.path.exists(self.local_folder):
os.makedirs(self.local_folder)

View File

@@ -8,6 +8,7 @@
- 2022-01-14/hsj100@a2tec.co.kr : refactoring
@brief: consts
"""
from config import rest_config
# SUPPORT PROJECT
SUPPORT_PROJECT_BASIC = 'PROJECT_BASIC'
@@ -87,7 +88,7 @@ NUM_RETRY_UUID_GEN = 3
DB_ADDRESS = "localhost"
DB_PORT = 53306
DB_USER_ID = 'root'
DB_USER_PW = 'Fermat3514!'
DB_USER_PW = rest_config.db_pw
DB_NAME = 'FM_TEST'
DB_CHARSET = 'utf8mb4'

View File

@@ -587,6 +587,7 @@ class ImageGenerateReq(BaseModel):
"""
### [Request] image generate request
"""
prefix : Optional[str] = Field(default="하얀색 배경", description="접두사", example="하얀색 배경")
prompt : str = Field(description='프롬프트', example='검은색 안경')
class BingCookieSetReq(BaseModel):

View File

@@ -137,7 +137,7 @@ router = APIRouter(prefix="/services")
# # img_length = imagen_generate_image(prompt=request_body_info.prompt,
# # download_count=request_body_info.downloadCount
# # )
# temp_image_path = gemini_image(request_body_info.prompt)
# temp_image_path = gemini_image(request_body_info.prompt)
# if rest_config.config != 'release':
# _remote_folder = os.path.join(rest_config.remote_folder,"imagen")
@@ -415,6 +415,61 @@ router = APIRouter(prefix="/services")
# return response.set_error(error=e)
@router.post("/imageGenerator", summary="이미지 데이터 생성", response_model=M.ImageGenerateDataRes)
async def image_generator(request: Request, request_body_info: M.ImageGenerateReq):
"""
## 이미지 생성
> 입력된 prompt로 이미지 생성 그후 결과 이미지데이터 return
### Input
> 접두어(prefix)는 null값을 주어도 기본값 사용, 빈("")값 사용시 prefix는 사용안함
> 최종 입력시 prefix, prompt 조합하여 내부적으로 최종 문장 완성
### Output
> - 결과(imageData)는 base64로 변환된 데이터(image)
### Options
> - prefix -> 접두어 (기본값: 하얀색 배경)
> - prompt -> 프롬프트
### Notice
> - 최종이미지에 배경이 없어야 이미지 검색시 유리하기때문에 꼭 prefix 옵션은 사용
"""
response = M.ImageGenerateDataRes()
try:
if request_body_info.prefix == None:
request_body_info.prefix = M.ImageGenerateReq.model_fields.get("prefix").default
full_prompt = f"{request_body_info.prefix}, {request_body_info.prompt}" if request_body_info.prefix else f"{request_body_info.prompt}"
temp_image_path = gemini_image(full_prompt) #TODO(jwkim) imagen3 으로 변경예정
if os.path.exists(temp_image_path):
image_data = image_to_base64_string(temp_image_path)
# Clean up temporary files
if 'temp_image_path' in locals():
if os.path.exists(temp_image_path):
os.remove(temp_image_path)
del temp_image_path
return response.set_message(image_data)
else:
raise Exception(f"image not generated(prefix: {request_body_info.prefix}, prompt:{request_body_info.prompt})")
except Exception as e:
LOG.error(traceback.format_exc())
# Clean up temporary files
if 'temp_image_path' in locals():
if os.path.exists(temp_image_path):
os.remove(temp_image_path)
del temp_image_path
return response.set_error(error=e)
@router.post("/vectorImageSearch/vit/inputImage/data", summary="벡터 이미지 검색(clip-vit) - input image(data)", response_model=M.VectorImageSerachDataRes)
async def vactor_vit_input_img_data(request: Request, request_body_info: M.VectorImageSearchVitInputImgReq):

View File

@@ -8,6 +8,7 @@
- 2022-01-14/hsj100@a2tec.co.kr : refactoring
@brief: consts
"""
from config import rest_config
# SUPPORT PROJECT
SUPPORT_PROJECT_BASIC = 'PROJECT_BASIC'
@@ -87,7 +88,7 @@ NUM_RETRY_UUID_GEN = 3
DB_ADDRESS = "localhost"
DB_PORT = 53306
DB_USER_ID = 'root'
DB_USER_PW = 'Fermat3514!'
DB_USER_PW = rest_config.db_pw
DB_NAME = 'FM_TEST'
DB_CHARSET = 'utf8mb4'