移除配置
This commit is contained in:
		@@ -11,13 +11,11 @@ from towhee import pipe, ops
 | 
			
		||||
from fastapi import APIRouter, HTTPException, File, UploadFile, Response, status, Header
 | 
			
		||||
from models.milvus import get_collection, collection_name
 | 
			
		||||
from models.mysql import get_cursor, conn
 | 
			
		||||
#from models.resnet import Resnet50
 | 
			
		||||
 | 
			
		||||
from configs.config import UPLOAD_PATH
 | 
			
		||||
from utilities.download import download_image
 | 
			
		||||
 | 
			
		||||
router = APIRouter()
 | 
			
		||||
#MODEL = Resnet50()
 | 
			
		||||
 | 
			
		||||
RESNET50 = (pipe.input('img').map('img', 'vec', ops.image_embedding.timm(model_name='resnet50')).output('vec'))
 | 
			
		||||
 | 
			
		||||
@@ -37,40 +35,8 @@ async def create_index():
 | 
			
		||||
    collection.load()
 | 
			
		||||
    return {'status': True, 'count': collection.num_entities}
 | 
			
		||||
 | 
			
		||||
'''
 | 
			
		||||
# 批量生成向量
 | 
			
		||||
@router.get('/create_vector', summary='生成向量', description='手动生成向量', include_in_schema=False)
 | 
			
		||||
async def create_vector(count: int = 10):
 | 
			
		||||
    cursor = get_cursor()
 | 
			
		||||
    cursor.execute(f"SELECT id,thumbnail_image,article_id,milvus_id FROM `web_images` WHERE thumbnail_image IS NOT NULL AND article_id IS NOT NULL AND milvus_id != 2048 AND width IS NOT NULL LIMIT 0,{count}")
 | 
			
		||||
    images = cursor.fetchall()
 | 
			
		||||
    cursor.close()
 | 
			
		||||
    for item in images:
 | 
			
		||||
        print(item)
 | 
			
		||||
        # 先查询 milvus 中是否存在
 | 
			
		||||
        collection = get_collection(collection_name)
 | 
			
		||||
        data = collection.query(expr=f'id in [{item["id"]}]', output_fields=None, partition_names=None, timeout=None) # offset, limit
 | 
			
		||||
        if len(data) > 0:
 | 
			
		||||
            cursor = get_cursor()
 | 
			
		||||
            cursor.execute(f"UPDATE web_images SET milvus_id=2048 WHERE id={item['id']}")
 | 
			
		||||
            conn.commit()
 | 
			
		||||
            cursor.close()
 | 
			
		||||
            continue
 | 
			
		||||
        try:
 | 
			
		||||
            img_path = os.path.join(UPLOAD_PATH, os.path.basename(item['thumbnail_image']))
 | 
			
		||||
            download_image(item['thumbnail_image']).save(img_path, 'png', save_all=True)
 | 
			
		||||
            feat = MODEL.resnet50_extract_feat(img_path)
 | 
			
		||||
            collection.insert([[item['id']], [feat], [item['article_id']]])
 | 
			
		||||
            cursor = get_cursor()
 | 
			
		||||
            cursor.execute(f"UPDATE web_images SET milvus_id=2048 WHERE id={item['id']}")
 | 
			
		||||
            conn.commit()
 | 
			
		||||
            cursor.close()
 | 
			
		||||
        except Exception as e:
 | 
			
		||||
            print(e)
 | 
			
		||||
    print('END')
 | 
			
		||||
    return images
 | 
			
		||||
'''
 | 
			
		||||
 | 
			
		||||
# 重建指定图像的向量
 | 
			
		||||
@router.put('/{image_id}', summary='覆写向量', description='重建指定图像的向量')
 | 
			
		||||
async def rewrite_image(image_id: int):
 | 
			
		||||
    print('START', image_id, '重建向量')
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user