chawin.chen commited on
Commit
4e455e5
·
1 Parent(s): d2c707c
Files changed (1) hide show
  1. api_routes.py +17 -17
api_routes.py CHANGED
@@ -983,7 +983,7 @@ async def upload_file(
983
  # 如果没有扩展名,使用空扩展名(保持用户上传文件的原始格式)
984
 
985
  # 生成唯一ID
986
- unique_id = str(uuid.uuid4()).replace('-', '')
987
  extra_meta_base = {
988
  "source": "upload_file",
989
  "file_type": fileType,
@@ -1122,7 +1122,7 @@ async def analyze_face(
1122
  contents = await file.read()
1123
  np_arr = np.frombuffer(contents, np.uint8)
1124
  image = cv2.imdecode(np_arr, cv2.IMREAD_COLOR)
1125
- original_md5_hash = str(uuid.uuid4()).replace('-', '')
1126
  original_image_filename = f"{original_md5_hash}_original.webp"
1127
  original_image_path = os.path.join(IMAGES_DIR, original_image_filename)
1128
  save_image_high_quality(image, original_image_path, quality=SAVE_QUALITY, upload_to_bos=False)
@@ -1307,7 +1307,7 @@ async def analyze_face(
1307
  continue
1308
 
1309
  # 生成MD5哈希
1310
- original_md5_hash = str(uuid.uuid4()).replace("-", "")
1311
  original_image_filename = f"{original_md5_hash}_original.webp"
1312
 
1313
  logger.info(
@@ -1564,7 +1564,7 @@ async def search_by_image(
1564
  image_data = await file.read()
1565
 
1566
  # 保存临时图片文件
1567
- temp_image_path = f"/tmp/search_image_{uuid.uuid4().hex}.webp"
1568
  try:
1569
  # 解码图片
1570
  np_arr = np.frombuffer(image_data, np.uint8)
@@ -2180,7 +2180,7 @@ async def restore_old_photo(
2180
 
2181
  try:
2182
  contents = await file.read()
2183
- original_md5_hash = str(uuid.uuid4()).replace('-', '')
2184
  # 如果前端传递了md5参数则使用,否则使用original_md5_hash
2185
  actual_md5 = md5 if md5 else original_md5_hash
2186
  restored_filename = f"{actual_md5}_restore.webp"
@@ -2326,7 +2326,7 @@ async def colorize_photo(
2326
 
2327
  try:
2328
  contents = await file.read()
2329
- original_md5_hash = str(uuid.uuid4()).replace('-', '')
2330
  # 如果前端传递了md5参数则使用,否则使用original_md5_hash
2331
  actual_md5 = md5 if md5 else original_md5_hash
2332
  colored_filename = f"{actual_md5}_upcolor.webp"
@@ -2558,7 +2558,7 @@ async def anime_stylize_photo(
2558
  f"Original image already exists for anime style: {original_filename}")
2559
  original_bos_uploaded = False
2560
 
2561
- styled_uuid = uuid.uuid4().hex
2562
  styled_filename = f"{styled_uuid}_anime_style_{style_type}.webp"
2563
 
2564
  # 获取风格描述
@@ -2657,7 +2657,7 @@ async def grayscale_photo(
2657
 
2658
  try:
2659
  contents = await file.read()
2660
- original_md5_hash = str(uuid.uuid4()).replace('-', '')
2661
  grayscale_filename = f"{original_md5_hash}_grayscale.webp"
2662
 
2663
  logger.info(f"Starting image grayscale: {file.filename}, size={file.size}, md5={original_md5_hash}")
@@ -2772,7 +2772,7 @@ async def upscale_photo(
2772
 
2773
  try:
2774
  contents = await file.read()
2775
- original_md5_hash = str(uuid.uuid4()).replace('-', '')
2776
  # 如果前端传递了md5参数则使用,否则使用original_md5_hash
2777
  actual_md5 = md5 if md5 else original_md5_hash
2778
  upscaled_filename = f"{actual_md5}_upscale.webp"
@@ -2936,7 +2936,7 @@ async def remove_background(
2936
  logger.info(f"User selected robustVideoMatting model but no face detected in image, switching to {model} model")
2937
 
2938
  # 生成唯一ID
2939
- unique_id = str(uuid.uuid4()).replace('-', '') # 32位UUID
2940
 
2941
  # 根据是否有透明背景决定文件扩展名
2942
  if background_color and background_color.lower() != "none":
@@ -3111,7 +3111,7 @@ async def rvm_remove_background(
3111
 
3112
  try:
3113
  contents = await file.read()
3114
- unique_id = str(uuid.uuid4()).replace('-', '') # 32位UUID
3115
 
3116
  # 根据是否有透明背景决定文件扩展名
3117
  if background_color and background_color.lower() != "none":
@@ -3361,7 +3361,7 @@ async def split_grid_image(
3361
 
3362
  try:
3363
  contents = await file.read()
3364
- original_md5_hash = str(uuid.uuid4()).replace('-', '')
3365
 
3366
  # 根据宫格类型确定行列数
3367
  if grid_type == 4:
@@ -3519,7 +3519,7 @@ async def compress_image(
3519
 
3520
  try:
3521
  contents = await file.read()
3522
- unique_id = str(uuid.uuid4()).replace('-', '')[:32] # 12位随机ID
3523
  compressed_filename = f"{unique_id}_compress.{outputFormat.lower()}"
3524
  logger.info(
3525
  f"Starting to compress image: {file.filename}, "
@@ -4152,7 +4152,7 @@ async def match_celebrity_face(
4152
  raise HTTPException(status_code=400,
4153
  detail="图片中未检测到人脸,请重新上传。")
4154
 
4155
- temp_filename = f"{uuid.uuid4().hex}_celebrity_query.webp"
4156
  temp_path = os.path.join(IMAGES_DIR, temp_filename)
4157
  if not save_image_high_quality(image, temp_path, quality=SAVE_QUALITY):
4158
  raise HTTPException(status_code=500,
@@ -4307,7 +4307,7 @@ async def match_celebrity_face(
4307
 
4308
  face_filename = None
4309
  if crop is not None and crop.size > 0:
4310
- face_filename = f"{uuid.uuid4().hex}_face_1.webp"
4311
  face_path = os.path.join(IMAGES_DIR, face_filename)
4312
  if not save_image_high_quality(crop, face_path,
4313
  quality=SAVE_QUALITY):
@@ -4414,8 +4414,8 @@ async def face_similarity_verification(
4414
  contents2 = await file2.read()
4415
 
4416
  # 生成唯一标识符
4417
- md5_hash1 = str(uuid.uuid4()).replace('-', '')
4418
- md5_hash2 = str(uuid.uuid4()).replace('-', '')
4419
 
4420
  # 生成文件名
4421
  original_filename1 = f"{md5_hash1}_original1.webp"
 
983
  # 如果没有扩展名,使用空扩展名(保持用户上传文件的原始格式)
984
 
985
  # 生成唯一ID
986
+ unique_id = f"ugc_{str(uuid.uuid4()).replace('-', '')}"
987
  extra_meta_base = {
988
  "source": "upload_file",
989
  "file_type": fileType,
 
1122
  contents = await file.read()
1123
  np_arr = np.frombuffer(contents, np.uint8)
1124
  image = cv2.imdecode(np_arr, cv2.IMREAD_COLOR)
1125
+ original_md5_hash = f"ugc_{str(uuid.uuid4()).replace('-', '')}"
1126
  original_image_filename = f"{original_md5_hash}_original.webp"
1127
  original_image_path = os.path.join(IMAGES_DIR, original_image_filename)
1128
  save_image_high_quality(image, original_image_path, quality=SAVE_QUALITY, upload_to_bos=False)
 
1307
  continue
1308
 
1309
  # 生成MD5哈希
1310
+ original_md5_hash = f"ugc_{str(uuid.uuid4()).replace('-', '')}"
1311
  original_image_filename = f"{original_md5_hash}_original.webp"
1312
 
1313
  logger.info(
 
1564
  image_data = await file.read()
1565
 
1566
  # 保存临时图片文件
1567
+ temp_image_path = f"/tmp/search_image_ugc_{uuid.uuid4().hex}.webp"
1568
  try:
1569
  # 解码图片
1570
  np_arr = np.frombuffer(image_data, np.uint8)
 
2180
 
2181
  try:
2182
  contents = await file.read()
2183
+ original_md5_hash = f"ugc_{str(uuid.uuid4()).replace('-', '')}"
2184
  # 如果前端传递了md5参数则使用,否则使用original_md5_hash
2185
  actual_md5 = md5 if md5 else original_md5_hash
2186
  restored_filename = f"{actual_md5}_restore.webp"
 
2326
 
2327
  try:
2328
  contents = await file.read()
2329
+ original_md5_hash = f"ugc_{str(uuid.uuid4()).replace('-', '')}"
2330
  # 如果前端传递了md5参数则使用,否则使用original_md5_hash
2331
  actual_md5 = md5 if md5 else original_md5_hash
2332
  colored_filename = f"{actual_md5}_upcolor.webp"
 
2558
  f"Original image already exists for anime style: {original_filename}")
2559
  original_bos_uploaded = False
2560
 
2561
+ styled_uuid = f"ugc_{uuid.uuid4().hex}"
2562
  styled_filename = f"{styled_uuid}_anime_style_{style_type}.webp"
2563
 
2564
  # 获取风格描述
 
2657
 
2658
  try:
2659
  contents = await file.read()
2660
+ original_md5_hash = f"ugc_{str(uuid.uuid4()).replace('-', '')}"
2661
  grayscale_filename = f"{original_md5_hash}_grayscale.webp"
2662
 
2663
  logger.info(f"Starting image grayscale: {file.filename}, size={file.size}, md5={original_md5_hash}")
 
2772
 
2773
  try:
2774
  contents = await file.read()
2775
+ original_md5_hash = f"ugc_{str(uuid.uuid4()).replace('-', '')}"
2776
  # 如果前端传递了md5参数则使用,否则使用original_md5_hash
2777
  actual_md5 = md5 if md5 else original_md5_hash
2778
  upscaled_filename = f"{actual_md5}_upscale.webp"
 
2936
  logger.info(f"User selected robustVideoMatting model but no face detected in image, switching to {model} model")
2937
 
2938
  # 生成唯一ID
2939
+ unique_id = f"ugc_{str(uuid.uuid4()).replace('-', '')}" # 32位UUID加上ugc_前缀
2940
 
2941
  # 根据是否有透明背景决定文件扩展名
2942
  if background_color and background_color.lower() != "none":
 
3111
 
3112
  try:
3113
  contents = await file.read()
3114
+ unique_id = f"ugc_{str(uuid.uuid4()).replace('-', '')}" # 32位UUID加上ugc_前缀
3115
 
3116
  # 根据是否有透明背景决定文件扩展名
3117
  if background_color and background_color.lower() != "none":
 
3361
 
3362
  try:
3363
  contents = await file.read()
3364
+ original_md5_hash = f"ugc_{str(uuid.uuid4()).replace('-', '')}"
3365
 
3366
  # 根据宫格类型确定行列数
3367
  if grid_type == 4:
 
3519
 
3520
  try:
3521
  contents = await file.read()
3522
+ unique_id = f"ugc_{str(uuid.uuid4()).replace('-', '')}" # 带有 ugc_ 前缀的 UUID
3523
  compressed_filename = f"{unique_id}_compress.{outputFormat.lower()}"
3524
  logger.info(
3525
  f"Starting to compress image: {file.filename}, "
 
4152
  raise HTTPException(status_code=400,
4153
  detail="图片中未检测到人脸,请重新上传。")
4154
 
4155
+ temp_filename = f"ugc_{uuid.uuid4().hex}_celebrity_query.webp"
4156
  temp_path = os.path.join(IMAGES_DIR, temp_filename)
4157
  if not save_image_high_quality(image, temp_path, quality=SAVE_QUALITY):
4158
  raise HTTPException(status_code=500,
 
4307
 
4308
  face_filename = None
4309
  if crop is not None and crop.size > 0:
4310
+ face_filename = f"ugc_{uuid.uuid4().hex}_face_1.webp"
4311
  face_path = os.path.join(IMAGES_DIR, face_filename)
4312
  if not save_image_high_quality(crop, face_path,
4313
  quality=SAVE_QUALITY):
 
4414
  contents2 = await file2.read()
4415
 
4416
  # 生成唯一标识符
4417
+ md5_hash1 = f"ugc_{str(uuid.uuid4()).replace('-', '')}"
4418
+ md5_hash2 = f"ugc_{str(uuid.uuid4()).replace('-', '')}"
4419
 
4420
  # 生成文件名
4421
  original_filename1 = f"{md5_hash1}_original1.webp"