Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -57,29 +57,27 @@ def run(url,quality,output_format,storage,access_key_id,access_key_secret,securi
|
|
57 |
|
58 |
# 网络图片 URL 和本地保存路径
|
59 |
tmp_file_name = uuid.uuid4()
|
60 |
-
|
61 |
-
temp_compressed = f'{tmp_file_name}_compressed_image.jpg'
|
62 |
|
63 |
# 步骤 1:下载图片到本地
|
64 |
downloaded_image = download_image(url)
|
65 |
|
66 |
if downloaded_image:
|
67 |
if access_key_id and endpoint and bucket_name:
|
|
|
68 |
# 步骤 3:上传到阿里云 OSS
|
69 |
-
oss_url = upload_to_oss(
|
70 |
|
71 |
# 步骤 4:删除本地的临时文件
|
72 |
-
delete_local_file(
|
73 |
-
delete_local_file(temp_compressed) # 删除压缩后的图片
|
74 |
if oss_url:
|
75 |
return f"图片上传成功,URL:{oss_url}"
|
76 |
else:
|
77 |
return "上传到 OSS 失败"
|
78 |
else:
|
79 |
-
with open(
|
80 |
image_base64 = base64.b64encode(f.read())
|
81 |
-
delete_local_file(
|
82 |
-
delete_local_file(temp_compressed) # 删除压缩后的图片
|
83 |
return image_base64
|
84 |
else:
|
85 |
return '图片下载失败'
|
|
|
57 |
|
58 |
# 网络图片 URL 和本地保存路径
|
59 |
tmp_file_name = uuid.uuid4()
|
60 |
+
result_image = f'{tmp_file_name}_compressed_image.jpg'
|
|
|
61 |
|
62 |
# 步骤 1:下载图片到本地
|
63 |
downloaded_image = download_image(url)
|
64 |
|
65 |
if downloaded_image:
|
66 |
if access_key_id and endpoint and bucket_name:
|
67 |
+
output_image_path = remove_metadata(downloaded_image,result_image)
|
68 |
# 步骤 3:上传到阿里云 OSS
|
69 |
+
oss_url = upload_to_oss(output_image_path, upload_filename, bucket_name, access_key_id, access_key_secret,securityToken, endpoint)
|
70 |
|
71 |
# 步骤 4:删除本地的临时文件
|
72 |
+
delete_local_file(result_image) # 删除压缩后的图片
|
|
|
73 |
if oss_url:
|
74 |
return f"图片上传成功,URL:{oss_url}"
|
75 |
else:
|
76 |
return "上传到 OSS 失败"
|
77 |
else:
|
78 |
+
with open(result_image,'rb') as f:
|
79 |
image_base64 = base64.b64encode(f.read())
|
80 |
+
delete_local_file(result_image) # 删除压缩后的图片
|
|
|
81 |
return image_base64
|
82 |
else:
|
83 |
return '图片下载失败'
|