edit: ict센터입고세팅을 기본값으로 설정, ict 설정시 sftp비활성화, l14_336 사용 못하던것 수정

This commit is contained in:
2025-08-06 16:04:02 +09:00
parent 4f23392cf2
commit 90609c08b8
6 changed files with 82 additions and 71 deletions

View File

@@ -1,13 +1,13 @@
class Config:
def __init__(self):
self.set_fermat()
self.set_ict()
self.use_imagen = True
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.sftp_host = "192.168.200.230"
self.sftp_port = 22
@@ -30,20 +30,8 @@ class Config:
os.makedirs(self.remote_folder)
def set_ict(self):
pass
# self.config = 'rel'
# 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
self.config = 'release'
self.local_folder = "./result" # 결과물 저장 폴더
rest_config = Config()
rest_config.set_dev()
rest_config.toggle_imagen()
# rest_config.set_dev()

View File

@@ -103,12 +103,12 @@ class FEMUsageInfo(Enum):
token=HUGGINGFACE_TOKEN,
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),
token=HUGGINGFACE_TOKEN,
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),
token=HUGGINGFACE_TOKEN,
index_type=INDEX_TYPE_COSINE)]

View File

@@ -16,25 +16,30 @@ def gemini_image(prompt, folder=None):
image_path = ''
client = genai.Client(api_key="AIzaSyB7tu67y9gOkJkpQtvI5OAYSzUzwv9qwnE")
response = client.models.generate_content(
model="gemini-2.0-flash-preview-image-generation",
contents=prompt,
config=types.GenerateContentConfig(
response_modalities=['TEXT', 'IMAGE']
for i in range(3):
response = client.models.generate_content(
model="gemini-2.0-flash-preview-image-generation",
contents=prompt,
config=types.GenerateContentConfig(
response_modalities=['TEXT', 'IMAGE']
)
)
)
if folder == None:
folder = TEMP_FOLDER
if folder == None:
folder = TEMP_FOLDER
if not os.path.exists(folder):
os.makedirs(folder)
for part in response.candidates[0].content.parts:
if part.inline_data is not None:
image = Image.open(BytesIO((part.inline_data.data)))
image_path = os.path.join(folder,f"gemini_{D.date_file_name()}_query.png")
image.save(image_path)
LOG.info(f"image generate : {image_path}")
time.sleep(2)
if os.path.exists(image_path):
return image_path
if not os.path.exists(folder):
os.makedirs(folder)
for part in response.candidates[0].content.parts:
if part.inline_data is not None:
image = Image.open(BytesIO((part.inline_data.data)))
image_path = os.path.join(folder,f"gemini_{D.date_file_name()}_query.png")
image.save(image_path)
LOG.info(f"image generate : {image_path}")
time.sleep(2)
return image_path

View File

@@ -49,12 +49,11 @@ class Config:
@dataclass
class LocalConfig(Config):
class ReleaseConfig(Config):
TRUSTED_HOSTS = ['*']
ALLOW_SITE = ['*']
DEBUG: bool = True
@dataclass
class ProdConfig(Config):
TRUSTED_HOSTS = ['*']
@@ -74,8 +73,6 @@ class DevConfig(Config):
TRUSTED_HOSTS = ['*']
ALLOW_SITE = ['*']
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
@@ -103,9 +100,11 @@ def conf():
환경 불러오기
:return:
"""
config = dict(prod=ProdConfig, local=LocalConfig, test=TestConfig, dev=DevConfig, my=MyConfig)
return config[environ.get('API_ENV', 'local')]()
return config[environ.get('API_ENV', 'dev')]()
return config[environ.get('API_ENV', 'my')]()
return config[environ.get('API_ENV', 'test')]()
from config import rest_config
config = dict(prod=ProdConfig, release=ReleaseConfig, test=TestConfig, dev=DevConfig, my=MyConfig)
return config[environ.get('API_ENV', rest_config.config)]()
# return config[environ.get('API_ENV', 'dev')]()
# return config[environ.get('API_ENV', 'my')]()
# return config[environ.get('API_ENV', 'test')]()

View File

@@ -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 custom_logger.main_log import main_logger as LOG
from custom_apps.bingimagecreator.utils import DallEArgument,dalle3_generate_image
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.bingimagecreator.utils import DallEArgument,dalle3_generate_image
# 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.utils import cookie_manager
from custom_apps.gemini.main import gemini_image
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
# )
temp_image_path = gemini_image(request_body_info.prompt)
_remote_folder = os.path.join(rest_config.remote_folder,"imagen")
# remote save
sftp_client.remote_copy_data(
temp_image_path,
os.path.join(_remote_folder,f"imagen_{request_body_info.prompt}_{1}_{D.date_file_name()}.png"))
if rest_config.config != 'release':
_remote_folder = os.path.join(rest_config.remote_folder,"imagen")
# remote save
sftp_client.remote_copy_data(
temp_image_path,
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
if 'temp_image_path' in locals():
@@ -266,16 +271,26 @@ 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_percents = vector_response_dict.get('img_list').get('result_percents')
# 원격지 폴더 생성
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_copy_data(local_path=query_image_path, remote_path=os.path.join(remote_directory,"query.png"))
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"))
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()}")
sftp_client.remote_mkdir(remote_directory)
# 원격지에 이미지 저장
sftp_client.remote_copy_data(local_path=query_image_path, remote_path=os.path.join(remote_directory,"query.png"))
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"))
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
if 'query_image_path' in locals():
if os.path.exists(query_image_path):
@@ -414,10 +429,13 @@ async def vactor_vit_report(request: Request, request_body_info: M.VectorImageSe
if json.loads(vactor_response.text)["error"] != None:
raise Exception(f"vector error: {json.loads(vactor_response.text)['error']}")
# remote 폴더에 이미지 저장
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"))
if rest_config.config != 'release':
# remote 폴더에 이미지 저장
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"))
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
if 'query_image_path' in locals():
if os.path.exists(query_image_path):

View File

@@ -1,4 +1,5 @@
import paramiko
from config import rest_config
class CustomSFTPClient():
def __init__(self):
@@ -26,5 +27,5 @@ class CustomSFTPClient():
sftp_client = None
if sftp_client is None:
if sftp_client is None and rest_config.config != 'release':
sftp_client = CustomSFTPClient()