edit: ict센터입고세팅을 기본값으로 설정, ict 설정시 sftp비활성화, l14_336 사용 못하던것 수정
This commit is contained in:
22
config.py
22
config.py
@@ -1,13 +1,13 @@
|
|||||||
class Config:
|
class Config:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.set_fermat()
|
self.set_ict()
|
||||||
self.use_imagen = True
|
self.use_imagen = True
|
||||||
|
|
||||||
def set_fermat(self):
|
def set_fermat(self):
|
||||||
"""
|
"""
|
||||||
내부 서버용
|
내부 서버용
|
||||||
"""
|
"""
|
||||||
self.config = 'rel'
|
self.config = 'dev'
|
||||||
self.remote_folder = "/home/fermat/STORAGE/01.Projects/A2TEC/K_EYEWEAR/02.ML_DATA/Image_generator_result"
|
self.remote_folder = "/home/fermat/STORAGE/01.Projects/A2TEC/K_EYEWEAR/02.ML_DATA/Image_generator_result"
|
||||||
self.sftp_host = "192.168.200.230"
|
self.sftp_host = "192.168.200.230"
|
||||||
self.sftp_port = 22
|
self.sftp_port = 22
|
||||||
@@ -30,20 +30,8 @@ class Config:
|
|||||||
os.makedirs(self.remote_folder)
|
os.makedirs(self.remote_folder)
|
||||||
|
|
||||||
def set_ict(self):
|
def set_ict(self):
|
||||||
pass
|
self.config = 'release'
|
||||||
# self.config = 'rel'
|
self.local_folder = "./result" # 결과물 저장 폴더
|
||||||
# self.remote_folder = "/home/fermat/STORAGE/01.Projects/A2TEC/K_EYEWEAR/02.ML_DATA/Image_generator_result"
|
|
||||||
# self.sftp_host = "192.168.200.230"
|
|
||||||
# self.sftp_port = 22
|
|
||||||
# self.sftp_id = "fermat"
|
|
||||||
# self.sftp_pw = "1234"
|
|
||||||
|
|
||||||
def toggle_imagen(self):
|
|
||||||
if self.use_imagen:
|
|
||||||
self.use_imagen = False
|
|
||||||
else:
|
|
||||||
self.use_imagen = True
|
|
||||||
|
|
||||||
rest_config = Config()
|
rest_config = Config()
|
||||||
rest_config.set_dev()
|
# rest_config.set_dev()
|
||||||
rest_config.toggle_imagen()
|
|
||||||
@@ -103,12 +103,12 @@ class FEMUsageInfo(Enum):
|
|||||||
token=HUGGINGFACE_TOKEN,
|
token=HUGGINGFACE_TOKEN,
|
||||||
index_type=INDEX_TYPE_COSINE)]
|
index_type=INDEX_TYPE_COSINE)]
|
||||||
|
|
||||||
openaiclip_vit_b14_336_l2 = [FEOpenAIClipViT, FEM.FEMArguments(
|
openaiclip_vit_l14_336_l2 = [FEOpenAIClipViT, FEM.FEMArguments(
|
||||||
trained_model=os.path.join(PRETRAINED_MODEL_PATH,ViTL14_336),
|
trained_model=os.path.join(PRETRAINED_MODEL_PATH,ViTL14_336),
|
||||||
token=HUGGINGFACE_TOKEN,
|
token=HUGGINGFACE_TOKEN,
|
||||||
index_type=INDEX_TYPE_L2)]
|
index_type=INDEX_TYPE_L2)]
|
||||||
|
|
||||||
openaiclip_vit_b14_336_cos = [FEOpenAIClipViT, FEM.FEMArguments(
|
openaiclip_vit_l14_336_cos = [FEOpenAIClipViT, FEM.FEMArguments(
|
||||||
trained_model=os.path.join(PRETRAINED_MODEL_PATH,ViTL14_336),
|
trained_model=os.path.join(PRETRAINED_MODEL_PATH,ViTL14_336),
|
||||||
token=HUGGINGFACE_TOKEN,
|
token=HUGGINGFACE_TOKEN,
|
||||||
index_type=INDEX_TYPE_COSINE)]
|
index_type=INDEX_TYPE_COSINE)]
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ def gemini_image(prompt, folder=None):
|
|||||||
image_path = ''
|
image_path = ''
|
||||||
client = genai.Client(api_key="AIzaSyB7tu67y9gOkJkpQtvI5OAYSzUzwv9qwnE")
|
client = genai.Client(api_key="AIzaSyB7tu67y9gOkJkpQtvI5OAYSzUzwv9qwnE")
|
||||||
|
|
||||||
|
for i in range(3):
|
||||||
response = client.models.generate_content(
|
response = client.models.generate_content(
|
||||||
model="gemini-2.0-flash-preview-image-generation",
|
model="gemini-2.0-flash-preview-image-generation",
|
||||||
contents=prompt,
|
contents=prompt,
|
||||||
@@ -37,4 +38,8 @@ def gemini_image(prompt, folder=None):
|
|||||||
|
|
||||||
LOG.info(f"image generate : {image_path}")
|
LOG.info(f"image generate : {image_path}")
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
|
if os.path.exists(image_path):
|
||||||
|
return image_path
|
||||||
|
|
||||||
return image_path
|
return image_path
|
||||||
@@ -49,12 +49,11 @@ class Config:
|
|||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class LocalConfig(Config):
|
class ReleaseConfig(Config):
|
||||||
TRUSTED_HOSTS = ['*']
|
TRUSTED_HOSTS = ['*']
|
||||||
ALLOW_SITE = ['*']
|
ALLOW_SITE = ['*']
|
||||||
DEBUG: bool = True
|
DEBUG: bool = True
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ProdConfig(Config):
|
class ProdConfig(Config):
|
||||||
TRUSTED_HOSTS = ['*']
|
TRUSTED_HOSTS = ['*']
|
||||||
@@ -74,8 +73,6 @@ class DevConfig(Config):
|
|||||||
TRUSTED_HOSTS = ['*']
|
TRUSTED_HOSTS = ['*']
|
||||||
ALLOW_SITE = ['*']
|
ALLOW_SITE = ['*']
|
||||||
DEBUG: bool = True
|
DEBUG: bool = True
|
||||||
DB_URL: str = environ.get('DB_URL', f'mysql+pymysql://{consts.DB_USER_ID}:{consts.DB_USER_PW}@{consts.DB_ADDRESS}/{consts.DB_NAME}_dev?charset={consts.DB_CHARSET}')
|
|
||||||
REST_SERVER_PORT = consts.REST_SERVER_PORT + 1
|
|
||||||
|
|
||||||
SW_TITLE = '[Dev] ' + consts.SW_TITLE
|
SW_TITLE = '[Dev] ' + consts.SW_TITLE
|
||||||
|
|
||||||
@@ -103,9 +100,11 @@ def conf():
|
|||||||
환경 불러오기
|
환경 불러오기
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
config = dict(prod=ProdConfig, local=LocalConfig, test=TestConfig, dev=DevConfig, my=MyConfig)
|
from config import rest_config
|
||||||
return config[environ.get('API_ENV', 'local')]()
|
|
||||||
return config[environ.get('API_ENV', 'dev')]()
|
config = dict(prod=ProdConfig, release=ReleaseConfig, test=TestConfig, dev=DevConfig, my=MyConfig)
|
||||||
return config[environ.get('API_ENV', 'my')]()
|
return config[environ.get('API_ENV', rest_config.config)]()
|
||||||
return config[environ.get('API_ENV', 'test')]()
|
# return config[environ.get('API_ENV', 'dev')]()
|
||||||
|
# return config[environ.get('API_ENV', 'my')]()
|
||||||
|
# return config[environ.get('API_ENV', 'test')]()
|
||||||
|
|
||||||
|
|||||||
@@ -20,9 +20,9 @@ from main_rest.app.utils.date_utils import D
|
|||||||
from main_rest.app.utils.parsing_utils import image_to_base64_string
|
from main_rest.app.utils.parsing_utils import image_to_base64_string
|
||||||
from custom_logger.main_log import main_logger as LOG
|
from custom_logger.main_log import main_logger as LOG
|
||||||
|
|
||||||
from custom_apps.bingimagecreator.utils import DallEArgument,dalle3_generate_image
|
# from custom_apps.bingimagecreator.utils import DallEArgument,dalle3_generate_image
|
||||||
from custom_apps.bingart.bingart import BingArtGenerator
|
# from custom_apps.bingart.bingart import BingArtGenerator
|
||||||
from custom_apps.imagen.custom_imagen import imagen_generate_image, imagen_generate_image_path, imagen_generate_temp_image_path
|
# from custom_apps.imagen.custom_imagen import imagen_generate_image, imagen_generate_image_path, imagen_generate_temp_image_path
|
||||||
from custom_apps.utils import cookie_manager
|
from custom_apps.utils import cookie_manager
|
||||||
from custom_apps.gemini.main import gemini_image
|
from custom_apps.gemini.main import gemini_image
|
||||||
from main_rest.app.utils.parsing_utils import download_range
|
from main_rest.app.utils.parsing_utils import download_range
|
||||||
@@ -144,12 +144,17 @@ async def imagen(request: Request, request_body_info: M.ImageGenerateReq):
|
|||||||
# download_count=request_body_info.downloadCount
|
# download_count=request_body_info.downloadCount
|
||||||
# )
|
# )
|
||||||
temp_image_path = gemini_image(request_body_info.prompt)
|
temp_image_path = gemini_image(request_body_info.prompt)
|
||||||
_remote_folder = os.path.join(rest_config.remote_folder,"imagen")
|
|
||||||
|
|
||||||
|
if rest_config.config != 'release':
|
||||||
|
_remote_folder = os.path.join(rest_config.remote_folder,"imagen")
|
||||||
# remote save
|
# remote save
|
||||||
sftp_client.remote_copy_data(
|
sftp_client.remote_copy_data(
|
||||||
temp_image_path,
|
temp_image_path,
|
||||||
os.path.join(_remote_folder,f"imagen_{request_body_info.prompt}_{1}_{D.date_file_name()}.png"))
|
os.path.join(_remote_folder,f"imagen_{request_body_info.prompt}_{1}_{D.date_file_name()}.png"))
|
||||||
|
else:
|
||||||
|
_local_forder = os.path.join(rest_config.local_folder,"image_generate","imagen")
|
||||||
|
os.makedirs(_local_forder,exist_ok=True)
|
||||||
|
shutil.copy(temp_image_path, os.path.join(_local_forder,f"imagen_{request_body_info.prompt}_{1}_{D.date_file_name()}.png"))
|
||||||
|
|
||||||
# Clean up temporary files
|
# Clean up temporary files
|
||||||
if 'temp_image_path' in locals():
|
if 'temp_image_path' in locals():
|
||||||
@@ -266,6 +271,7 @@ async def vactor_vit(request: Request, request_body_info: M.VectorImageSearchVit
|
|||||||
result_image_paths = vector_response_dict.get('img_list').get('result_image_paths')
|
result_image_paths = vector_response_dict.get('img_list').get('result_image_paths')
|
||||||
result_percents = vector_response_dict.get('img_list').get('result_percents')
|
result_percents = vector_response_dict.get('img_list').get('result_percents')
|
||||||
|
|
||||||
|
if rest_config.config != 'release':
|
||||||
# 원격지 폴더 생성
|
# 원격지 폴더 생성
|
||||||
remote_directory = os.path.join(rest_config.remote_folder, f"imagen_query_{request_body_info.modelType}_{request_body_info.indexType}_{request_body_info.prompt}_{D.date_file_name()}")
|
remote_directory = os.path.join(rest_config.remote_folder, f"imagen_query_{request_body_info.modelType}_{request_body_info.indexType}_{request_body_info.prompt}_{D.date_file_name()}")
|
||||||
sftp_client.remote_mkdir(remote_directory)
|
sftp_client.remote_mkdir(remote_directory)
|
||||||
@@ -275,6 +281,15 @@ async def vactor_vit(request: Request, request_body_info: M.VectorImageSearchVit
|
|||||||
|
|
||||||
for img_path, img_percent in zip(result_image_paths,result_percents):
|
for img_path, img_percent in zip(result_image_paths,result_percents):
|
||||||
sftp_client.remote_copy_data(local_path=img_path, remote_path=os.path.join(remote_directory,f"search_{img_percent}.png"))
|
sftp_client.remote_copy_data(local_path=img_path, remote_path=os.path.join(remote_directory,f"search_{img_percent}.png"))
|
||||||
|
else:
|
||||||
|
local_directory = os.path.join(rest_config.local_folder, f"imagen_query_{request_body_info.modelType}_{request_body_info.indexType}_{request_body_info.prompt}_{D.date_file_name()}")
|
||||||
|
os.makedirs(local_directory, exist_ok=True)
|
||||||
|
|
||||||
|
shutil.copy(query_image_path, os.path.join(local_directory,"query.png"))
|
||||||
|
|
||||||
|
for img_path, img_percent in zip(result_image_paths,result_percents):
|
||||||
|
shutil.copy(img_path, os.path.join(local_directory,f"search_{img_percent}.png"))
|
||||||
|
|
||||||
|
|
||||||
# Clean up temporary files
|
# Clean up temporary files
|
||||||
if 'query_image_path' in locals():
|
if 'query_image_path' in locals():
|
||||||
@@ -414,9 +429,12 @@ async def vactor_vit_report(request: Request, request_body_info: M.VectorImageSe
|
|||||||
if json.loads(vactor_response.text)["error"] != None:
|
if json.loads(vactor_response.text)["error"] != None:
|
||||||
raise Exception(f"vector error: {json.loads(vactor_response.text)['error']}")
|
raise Exception(f"vector error: {json.loads(vactor_response.text)['error']}")
|
||||||
|
|
||||||
|
if rest_config.config != 'release':
|
||||||
# remote 폴더에 이미지 저장
|
# remote 폴더에 이미지 저장
|
||||||
sftp_client.remote_copy_data(local_path=report_image_path,
|
sftp_client.remote_copy_data(local_path=report_image_path,
|
||||||
remote_path=os.path.join(rest_config.remote_folder, f"imagen_report_vit_{request_body_info.prompt}_{D.date_file_name()}.png"))
|
remote_path=os.path.join(rest_config.remote_folder, f"imagen_report_vit_{request_body_info.prompt}_{D.date_file_name()}.png"))
|
||||||
|
else:
|
||||||
|
shutil.copy(report_image_path, os.path.join(rest_config.local_folder, f"imagen_report_vit_{request_body_info.prompt}_{D.date_file_name()}.png"))
|
||||||
|
|
||||||
# Clean up temporary files
|
# Clean up temporary files
|
||||||
if 'query_image_path' in locals():
|
if 'query_image_path' in locals():
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import paramiko
|
import paramiko
|
||||||
|
from config import rest_config
|
||||||
|
|
||||||
class CustomSFTPClient():
|
class CustomSFTPClient():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -26,5 +27,5 @@ class CustomSFTPClient():
|
|||||||
|
|
||||||
sftp_client = None
|
sftp_client = None
|
||||||
|
|
||||||
if sftp_client is None:
|
if sftp_client is None and rest_config.config != 'release':
|
||||||
sftp_client = CustomSFTPClient()
|
sftp_client = CustomSFTPClient()
|
||||||
Reference in New Issue
Block a user