edit : imagen -> gemini로 변경, bingimg -> 사용불가 , 벡터검색api 이미지저장이아닌 데이터 전송하는 api 추가 , vactor -> vector 오타 수정

This commit is contained in:
2025-07-30 13:29:24 +09:00
parent 8e28a22825
commit 44bd86562d
45 changed files with 507 additions and 223 deletions

View File

@@ -56,7 +56,7 @@ Implementation
"""
def get_models(index_type, model_type):
from vactor_rest.app import models as M
from vector_rest.app import models as M
model = None

View File

@@ -57,9 +57,9 @@ class BingArtGenerator:
else:
return None
def link_to_img(self, img_links:list):
def link_to_img_remote(self, img_links:list):
"""
이미지 링크로 이미지 파일 저장
이미지 링크로 이미지 파일 원격지에 저장
"""
jpeg_index = 1
@@ -80,6 +80,20 @@ class BingArtGenerator:
return 0
else:
self.link_to_img(img_links=image_links)
self.link_to_img_remote(img_links=image_links)
return len(image_links)
def get_query_image(self,prompt):
create_time = D.date_file_name()
image_links = self.get_image_links(prompt,1)
if image_links == None:
return 0
else:
image = image_links[0]
query_path = os.path.join(TEMP_FOLDER,f"query_bingarg_{create_time}.png")
urllib.request.urlretrieve(image, query_path)
return query_path

View File

@@ -1,5 +1,7 @@
import os
import shutil
import torch
import faiss
from custom_apps.faiss_imagenet.utils import preprocessing, preprocessing_quary, normalize, get_dataset_list
from custom_apps.faiss_imagenet.const import *
@@ -15,17 +17,29 @@ def search_idxs(image_path,dataset_bin=DATASET_BIN,index_type="hnsw",search_num=
DIM = 1280
# res = faiss.StandardGpuResources()
# __res = faiss.StandardGpuResources()
dataset_fvces, dataset_index = preprocessing(DIM,dataset_bin,index_type)
org_fvces, org_index = preprocessing_quary(DIM,image_path,index_type)
# cpu -> gpu
# gpu_idx = faiss.index_cpu_to_gpu_multiple_py([res], 0, dataset_index)
# __gpu_idx = faiss.index_cpu_to_gpu_multiple_py([__res], 0, org_index)
dists, idxs = dataset_index.search(normalize(org_fvces), search_num)
# print(dists[0])
# print(idxs[0])
index_image_save(image_path, dists[0], idxs[0])
# del dataset_fvces, dataset_index, org_fvces, org_index, dists, idxs
# del res, __res, gpu_idx, __gpu_idx
# torch.cuda.empty_cache()
# import gc
# gc.collect()
def index_image_save(query_image_path, dists, idxs):
directory_path, file = os.path.split(query_image_path)
_name, extension = os.path.splitext(file)

View File

@@ -0,0 +1,40 @@
import os
import time
from google import genai
from google.genai import types
from PIL import Image
from io import BytesIO
from main_rest.app.utils.date_utils import D
from const import TEMP_FOLDER
def gemini_image(prompt, folder=None):
from custom_logger.main_log import main_logger as LOG
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']
)
)
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)
return image_path

View File

@@ -15,6 +15,7 @@ class ImagenConst:
project_id = "glasses-imagen"
location = "asia-east1"
model = "imagen-3.0-generate-001"
# model = "imagen-3.0-fast-generate-001"
def imagen_generate_image(prompt,download_count=1):

View File

@@ -1,6 +1,6 @@
class CookieManager:
DEFAULT_COOKIE = "19S_ux18UhHzxHMsY5gTYwqk2YjYahwxssgJyx0AybuAjDa_kZKWFauqMSrtb1a80s89VjmLwKWIGhvpZxLOzkwcMXAuShkgFwGSVlD8ayI7qgQiCabE9-UFByw4QJ_ZSAnOnskn5iPydk4vaZZEayTR--u7-mVglsaANK6rGOQPeu8q-Sa6cjVCUQR9kkjEtz-J4wf2MQ6inXuC41IbCi8QwmZyHkwxOy6U6CqPiREg"
DEFAULT_COOKIE = "1dcelksYDmBzN1R2heBkdpHpku-E2Qr8KAA4bToiSqFBtLUDGPMgKXrpc0X_oVhSCzcX3rk3kB8GgwILUNdvrhgO9Zu_BgcpromvlpjUg1jukhL6v3SBE-YOBQqzBC6OanguFOfAAlFJjB7ZJBzoPQzdrKU7L8yMQZZ-BAsfr18M6MnWy1aaEWljSmOA7_fTql5RcjCPNk_FZBeFXolnOIdNfLqGIFWsPKM8nNZVXNSs"
def __init__(self):
self.cookie = self.DEFAULT_COOKIE