Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
H
hh_ccs
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
贺阳
hh_ccs
Commits
5049b46c
提交
5049b46c
authored
10月 29, 2025
作者:
贺阳
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
涂抹预览
上级
145b4da1
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
173 行增加
和
10 行删除
+173
-10
ai_image_edit_service.py
ccs_base/wizard/ai_image_edit_service.py
+88
-0
batch_get_pod_info_wizard.py
ccs_base/wizard/batch_get_pod_info_wizard.py
+0
-0
batch_get_pod_info_wizard_views.xml
ccs_base/wizard/batch_get_pod_info_wizard_views.xml
+16
-10
image-to-image.py
ccs_base/wizard/image-to-image.py
+69
-0
没有找到文件。
ccs_base/wizard/ai_image_edit_service.py
0 → 100644
浏览文件 @
5049b46c
# -*- coding: utf-8 -*-
import
base64
import
requests
from
dashscope
import
MultiModalConversation
import
dashscope
import
logging
_logger
=
logging
.
getLogger
(
__name__
)
# 设置DashScope的API地址
dashscope
.
base_http_api_url
=
'https://dashscope.aliyuncs.com/api/v1'
class
AIImageEditService
:
"""AI图片编辑服务 - 使用阿里云百炼的qwen-image-edit模型"""
def
__init__
(
self
,
api_key
=
'sk-e41914f0d9c94035a5ae1322e9a61fb1'
):
self
.
api_key
=
api_key
self
.
model
=
"qwen-image-edit"
def
edit_image_remove_text
(
self
,
image_base64
,
text_to_remove
=
"AGN UCLINK LOGISITICS LTD"
):
"""
使用AI模型移除图片中的指定文字
:param image_base64: 图片的base64编码
:param text_to_remove: 要移除的文字
:return: 处理后的图片base64编码,失败返回None
"""
try
:
# 构建消息
messages
=
[
{
"role"
:
"user"
,
"content"
:
[
{
"image"
:
f
"data:image/png;base64,{image_base64}"
},
{
"text"
:
f
"将图片中的{text_to_remove}这一段文字抹去,保持背景完全一致"
}
]
}
]
# 调用AI模型
response
=
MultiModalConversation
.
call
(
api_key
=
self
.
api_key
,
model
=
self
.
model
,
messages
=
messages
,
stream
=
False
,
watermark
=
False
,
negative_prompt
=
" "
)
if
response
.
status_code
==
200
:
# 获取处理后图片的URL
image_url
=
response
.
output
.
choices
[
0
]
.
message
.
content
[
0
][
'image'
]
_logger
.
info
(
f
"AI图片编辑成功,图片URL: {image_url}"
)
# 下载图片并转换为base64
edited_image_base64
=
self
.
download_and_convert_to_base64
(
image_url
)
return
edited_image_base64
else
:
_logger
.
error
(
f
"AI图片编辑失败,HTTP返回码:{response.status_code}"
)
_logger
.
error
(
f
"错误码:{response.code}"
)
_logger
.
error
(
f
"错误信息:{response.message}"
)
return
None
except
Exception
as
e
:
_logger
.
error
(
f
"AI图片编辑异常: {str(e)}"
)
return
None
def
download_and_convert_to_base64
(
self
,
image_url
,
timeout
=
300
):
"""
下载图片并转换为base64
:param image_url: 图片URL
:param timeout: 超时时间
:return: base64编码的图片数据
"""
try
:
response
=
requests
.
get
(
image_url
,
stream
=
True
,
timeout
=
timeout
)
response
.
raise_for_status
()
# 将图片内容转换为base64
image_data
=
response
.
content
image_base64
=
base64
.
b64encode
(
image_data
)
.
decode
(
'utf-8'
)
_logger
.
info
(
"图片下载并转换为base64成功"
)
return
image_base64
except
requests
.
exceptions
.
RequestException
as
e
:
_logger
.
error
(
f
"图片下载失败: {str(e)}"
)
return
None
ccs_base/wizard/batch_get_pod_info_wizard.py
浏览文件 @
5049b46c
差异被折叠。
点击展开。
ccs_base/wizard/batch_get_pod_info_wizard_views.xml
浏览文件 @
5049b46c
...
...
@@ -9,17 +9,17 @@
<field
name=
"arch"
type=
"xml"
>
<form
string=
"Batch Get POD Info"
>
<!-- 批量获取POD信息 -->
<sheet>
<!-- <group> -->
<group>
<group>
<field
name=
"sync_last_mile_pod"
widget=
"boolean_toggle"
/>
</group>
<group>
<field
name=
"remove_specified_text"
widget=
"boolean_toggle"
/>
</group>
<group>
<field
name=
"sync_match_node"
widget=
"boolean_toggle"
/>
</group>
<field
name=
"sync_last_mile_pod"
widget=
"boolean_toggle"
attrs=
"{'invisible': [('pdf_file', '=', False)]}"
/>
</group>
<group>
<field
name=
"remove_specified_text"
widget=
"boolean_toggle"
attrs=
"{'invisible': [('pdf_file', '!=', False)]}"
/>
</group>
<group>
<field
name=
"sync_match_node"
widget=
"boolean_toggle"
attrs=
"{'invisible': [('pdf_file', '=', False)]}"
/>
</group>
<!-- </group> -->
<div
class=
"alert alert-info"
role=
"alert"
>
<strong>
Description:
</strong>
<!-- 说明: -->
...
...
@@ -32,8 +32,14 @@
<div
class=
"alert alert-danger"
role=
"alert"
attrs=
"{'invisible': [('show_error_message', '=', False)]}"
>
<field
name=
"show_error_message"
/>
</div>
<div>
<field
name=
"pdf_file"
filename=
"pdf_filename"
widget=
"pdf_viewer"
readonly=
"1"
attrs=
"{'invisible': [('pdf_file', '=', False)]}"
/>
</div>
<footer>
<button
string=
"Confirm"
type=
"object"
name=
"confirm"
class=
"btn-primary"
/>
<!-- 预览按钮:处理PDF并显示合并后的文件 -->
<button
string=
"Preview"
type=
"object"
name=
"action_preview"
class=
"btn-primary"
attrs=
"{'invisible': [('pdf_file', '!=', False)]}"
/>
<!-- 确认按钮:使用已处理的文件数据进行回写和同步 -->
<button
string=
"Confirm"
type=
"object"
name=
"confirm"
class=
"btn-primary"
attrs=
"{'invisible': [('pdf_file', '=', False)]}"
/>
<button
string=
"Close"
special=
"cancel"
/>
</footer>
</sheet>
...
...
ccs_base/wizard/image-to-image.py
0 → 100644
浏览文件 @
5049b46c
import
json
import
os
from
dashscope
import
MultiModalConversation
import
dashscope
import
base64
import
requests
dashscope
.
base_http_api_url
=
'https://dashscope.aliyuncs.com/api/v1'
image_path
=
"./图片识别2.png"
def
download_image
(
image_url
,
save_path
=
'output.png'
):
try
:
response
=
requests
.
get
(
image_url
,
stream
=
True
,
timeout
=
300
)
# 设置超时
response
.
raise_for_status
()
# 如果HTTP状态码不是200,则引发异常
with
open
(
save_path
,
'wb'
)
as
f
:
for
chunk
in
response
.
iter_content
(
chunk_size
=
8192
):
f
.
write
(
chunk
)
print
(
f
"图像已成功下载到: {save_path}"
)
except
requests
.
exceptions
.
RequestException
as
e
:
print
(
f
"图像下载失败: {e}"
)
with
open
(
image_path
,
"rb"
)
as
image_file
:
image_base64
=
base64
.
b64encode
(
image_file
.
read
())
.
decode
(
'utf-8'
)
# 模型支持输入1-3张图片
messages
=
[
{
"role"
:
"user"
,
"content"
:
[
{
"image"
:
f
"data:image/png;base64,{image_base64}"
},
{
"text"
:
"将图片中的AGN UCLINK LOGISITICS LTD这一段文字抹去"
}
]
}
]
# 新加坡和北京地域的API Key不同。获取API Key:https://help.aliyun.com/zh/model-studio/get-api-key
# 若没有配置环境变量,请用百炼 API Key 将下行替换为:api_key="sk-xxx"
# api_key = os.getenv("DASHSCOPE_API_KEY")
# 模型仅支持单轮对话,复用了多轮对话的接口
response
=
MultiModalConversation
.
call
(
api_key
=
'sk-e41914f0d9c94035a5ae1322e9a61fb1'
,
model
=
"qwen-image-edit"
,
messages
=
messages
,
stream
=
False
,
watermark
=
False
,
negative_prompt
=
" "
)
if
response
.
status_code
==
200
:
# 如需查看完整响应,请取消下行注释
# print(json.dumps(response, ensure_ascii=False))
print
(
"输出图像的URL:"
,
response
.
output
.
choices
[
0
]
.
message
.
content
[
0
][
'image'
])
image_url
=
response
.
output
.
choices
[
0
]
.
message
.
content
[
0
][
'image'
]
download_image
(
image_url
,
save_path
=
'处理图片.png'
)
else
:
print
(
f
"HTTP返回码:{response.status_code}"
)
print
(
f
"错误码:{response.code}"
)
print
(
f
"错误信息:{response.message}"
)
print
(
"请参考文档:https://help.aliyun.com/zh/model-studio/developer-reference/error-code"
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论