361 lines
17 KiB
Python
361 lines
17 KiB
Python
from flask import Flask, request, jsonify
|
||
import json
|
||
import time
|
||
from DataProcess import Add_Collaboration_Brief_FrontEnd
|
||
from AgentCoord.RehearsalEngine_V2.ExecutePlan import executePlan
|
||
from AgentCoord.PlanEngine.basePlan_Generator import generate_basePlan
|
||
from AgentCoord.PlanEngine.fill_stepTask import fill_stepTask
|
||
from AgentCoord.PlanEngine.fill_stepTask_TaskProcess import (
|
||
fill_stepTask_TaskProcess,
|
||
)
|
||
from AgentCoord.PlanEngine.branch_PlanOutline import branch_PlanOutline
|
||
from AgentCoord.PlanEngine.branch_TaskProcess import branch_TaskProcess
|
||
from AgentCoord.PlanEngine.AgentSelectModify import (
|
||
AgentSelectModify_init,
|
||
AgentSelectModify_addAspect,
|
||
)
|
||
import os
|
||
import yaml
|
||
import argparse
|
||
|
||
# initialize global variables
|
||
yaml_file = os.path.join(os.getcwd(), "config", "config.yaml")
|
||
try:
|
||
with open(yaml_file, "r", encoding="utf-8") as file:
|
||
yaml_data = yaml.safe_load(file)
|
||
except Exception:
|
||
yaml_file = {}
|
||
USE_CACHE: bool = os.getenv("USE_CACHE")
|
||
if USE_CACHE is None:
|
||
USE_CACHE = yaml_data.get("USE_CACHE", False)
|
||
else:
|
||
USE_CACHE = USE_CACHE.lower() in ["true", "1", "yes"]
|
||
AgentBoard = None
|
||
AgentProfile_Dict = {}
|
||
c1 = '''
|
||
|
||
=====数联网搜索结果=====
|
||
|
||
1. 论文
|
||
|
||
- 《Surface Defect Detection and Evaluation for Marine Vessels using Multi-Stage Deep Learning》提出一个面向船舶制造与检修的多阶段深度学习流水线,用于船体表面缺陷检测与评估,重点识别和量化与船舶制造材料腐蚀相关的现象,包括腐蚀(rust)、附着物(fouling)、涂层剥离(delamination)等。研究特别关注船舶材料腐蚀在不同涂层颜色、光照条件和相机角度下的鲁棒性,有助于提高船舶制造过程中对材料腐蚀的检测与管理能力。论文强调其方法在船舶材料表面腐蚀监测和维修决策中的应用价值。链接:https://arxiv.org/abs/2203.09580
|
||
论文复现链接:http://8.130.138.52:21001/#/view/reproduction?doid=newID/5a4fef68-a138-4adb-ba88-43aa4474c08c
|
||
|
||
- 《Efficient Metal Corrosion Area Detection Model Combining Convolution and Transformer (MCD-Net)》提出了一种高效的金属腐蚀区域检测模型。该模型创新性地结合了卷积编码器与视觉Transformer序列编码器,利用注意力融合模块增强边界识别,并采用基于得分的多尺度增强机制来突出腐蚀区域。该方法在阴影、遮挡和复杂纹理条件下依然能保持高精度,在公开数据集上取得了优异的F1性能,特别适用于船舶制造与检修中对船体钢板和涂层腐蚀的自动化识别与量化分析。链接:https://www.mdpi.com/2076-3417/14/21/9900
|
||
论文复现链接:http://8.130.138.52:21001/#/view/reproduction?doid=newID/b200a489-e2c8-4dbd-8767-682d15dd4c04
|
||
|
||
- 《Mechanical Failure and Metal Degradation of Ships and Marine Structures》系统探讨了船舶与海洋结构中金属材料(包括高强钢、不锈钢、铜合金、钛合金等)在海洋环境下的机械损伤与电化学腐蚀协同作用问题。重点分析了"机械载荷+腐蚀"耦合导致的疲劳、裂纹及腐蚀裂纹等失效机制,并对相应的检测、预警与保护措施进行了深入讨论。链接:https://doi.org/10.3390/met13020272
|
||
|
||
- 《Research Progress of Marine Anti-Fouling Coatings》(2024)全面综述了海洋防污涂层的研究进展,涵盖自我抛光涂料、生物可降解涂料、低表面能涂层、仿生涂层和纳米涂层等新型涂层技术。虽然重点在于防污,但文中指出许多防污机制与防腐蚀机制相互关联,通过阻碍生物附着可有效减少微生物引起的腐蚀和表面破坏。链接:https://doi.org/10.3390/coatings14091227
|
||
|
||
- 《Corrosion-Wear Behavior of Shipbuilding Steels (EH40, FH40, 921A) in Seawater》研究了三种常用船用钢(EH40、FH40、921A)在海水环境中磨损与腐蚀共同作用下的复合失效行为。通过机械-电化学方法系统测定了腐蚀磨损损失、表面形貌变化和耐腐蚀性能差异,发现在此类工况中921A钢表现最佳。《Journal of Chinese Society for Corrosion and Protection》, Vol 45(4): 894-904, 2025
|
||
|
||
- 《Sulfur-Selenium Alloy Coatings for Universal Corrosion Resistance》设计了一种硫-硒合金涂层,能够在包括模拟海水和硫酸盐还原菌生物环境在内的各种条件下为钢材提供高效的防腐蚀保护(约99.9%效率),腐蚀速率比裸钢低6-7个数量级。该涂层具有良好的机械性能、非多孔结构,能有效阻碍多种扩散性腐蚀因子的渗透。arXiv:2009.02451
|
||
|
||
2. 代码
|
||
|
||
- CoaST - Anti-corrosive coatings research (DTU, Denmark):丹麦技术大学的CoaST项目专注于抗腐蚀涂层的性能表征与失效机制分析。该项目采用电化学测试与表面/界面无损检测技术相结合的方法,系统评估涂层的保护效果与失效途径,为船舶腐蚀防护提供了重要的研究平台。链接:https://www.kt.dtu.dk/research/coast/research-areas/anti-corrosive-coatings
|
||
|
||
- Surface Defect Detection 仓库:该仓库集成了多种表面缺陷检测算法,为实现船舶腐蚀检测提供了可靠的代码基础和参考架构。链接:https://github.com/Charmve/Surface-Defect-Detection
|
||
|
||
- Hugging Face 预训练模型:平台提供了轻量级的腐蚀检测模型,可直接下载并微调,用于快速验证和部署。链接:https://huggingface.co/mahdavian/corrosion-model
|
||
|
||
3. 数据集
|
||
|
||
用于训练和验证MCD-Net模型的相关数据集包括:
|
||
|
||
- iamcloud/Corrosion_Dataset:一个包含约2000多张标注图像的数据集(ImageFolder格式,Apache-2.0协议),专门收录材料腐蚀图像,适用于船舶腐蚀监测模型的训练。链接:https://huggingface.co/datasets/iamcloud/Corrosion_Dataset
|
||
|
||
- Francesco/corrosion-bi3q3:此数据集提供了多种腐蚀实例,可用于支持船舶涂层损坏与基体腐蚀的自动化检测任务。链接:https://huggingface.co/datasets/Francesco/corrosion-bi3q3。
|
||
|
||
4. 研究团队
|
||
|
||
- 海洋腐蚀与防护全国重点实验室是我国在该领域最具权威性的国家级研究机构,依托于中国船舶集团旗下725所。实验室提供从材料、设计到运维的全生命周期腐蚀控制解决方案,其核心优势在于能够进行多技术(如“阴极保护+涂层”)的综合集成研发与验证。其研究成果广泛应用于船舶、海洋平台等国家重大工程,为保障我国海洋装备的安全与耐久性提供了关键支撑。
|
||
|
||
- 水性船舶防腐涂层新材料项目团队是一支源自东北石油大学的创新创业团队,专注于推动船舶涂料行业的环保化转型。团队致力于攻克水性涂料在船舶高湿环境下干燥慢、早期耐水性差的技术瓶颈,旨在开发出兼具优异防腐性能和施工便利性的水性体系,以替代传统溶剂型涂料,其目标是实现进口产品替代并大幅减少船舶制造与维修过程中的VOCs排放。
|
||
|
||
- 微纳一体化防腐耐磨技术研发团队是以广州航海学院青年技术骨干为核心的新锐力量。团队针对铝合金在极端海洋环境中的腐蚀-磨损难题,创新性地提出了“微米级氧化陶瓷层+纳米自润滑固化层+改性硅烷钝化层”的三层复合防护体系。该技术使防护层的结合强度、耐磨性(提升2000倍)和耐腐蚀性能(自腐蚀电流密度降低6个数量级)实现了质的飞跃。
|
||
|
||
- 北京大学南京创新研究院BXCFD团队专注于自主可控的高性能计算流体力学软件研发。团队在船舶与海洋工程水动力学领域取得关键突破,其自主研发的软件在船舶兴波阻力预报精度上达到国际先进水平,并成功实现了对复杂的船-桨-舵6自由度运动的耦合高精度模拟,为船舶水动力性能研究与优化提供了强大的国产化工具。
|
||
|
||
- 清华大学多相流与生物流动力学实验室由罗先武教授带领,长期专注于流体机械及工程领域。团队重点研究高速船舶喷水推进装置的基础理论与空化流动机理,其研究成果为攻克喷水推进系统中的空化、振动与噪声问题提供了坚实的理论依据和技术支持,对我国高性能船舶推进技术的发展具有重要意义。
|
||
|
||
'''
|
||
context = {"材料腐蚀":c1}
|
||
Request_Cache: dict[str, str] = {}
|
||
app = Flask(__name__)
|
||
|
||
|
||
@app.route("/fill_stepTask_TaskProcess", methods=["post"])
|
||
def Handle_fill_stepTask_TaskProcess():
|
||
incoming_data = request.get_json()
|
||
requestIdentifier = str(
|
||
(
|
||
"/fill_stepTask_TaskProcess",
|
||
incoming_data["General Goal"],
|
||
incoming_data["stepTask_lackTaskProcess"],
|
||
)
|
||
)
|
||
|
||
if USE_CACHE:
|
||
if requestIdentifier in Request_Cache:
|
||
time.sleep(1)
|
||
return jsonify(Request_Cache[requestIdentifier])
|
||
|
||
filled_stepTask = fill_stepTask_TaskProcess(
|
||
General_Goal=incoming_data["General Goal"],
|
||
stepTask=incoming_data["stepTask_lackTaskProcess"],
|
||
AgentProfile_Dict=AgentProfile_Dict,
|
||
)
|
||
filled_stepTask = Add_Collaboration_Brief_FrontEnd(filled_stepTask)
|
||
Request_Cache[requestIdentifier] = filled_stepTask
|
||
response = jsonify(filled_stepTask)
|
||
return response
|
||
|
||
|
||
@app.route("/agentSelectModify_init", methods=["post"])
|
||
def Handle_agentSelectModify_init():
|
||
incoming_data = request.get_json()
|
||
requestIdentifier = str(
|
||
(
|
||
"/agentSelectModify_init",
|
||
incoming_data["General Goal"],
|
||
incoming_data["stepTask"],
|
||
)
|
||
)
|
||
|
||
if USE_CACHE:
|
||
if requestIdentifier in Request_Cache:
|
||
return jsonify(Request_Cache[requestIdentifier])
|
||
|
||
scoreTable = AgentSelectModify_init(
|
||
stepTask=incoming_data["stepTask"],
|
||
General_Goal=incoming_data["General Goal"],
|
||
Agent_Board=AgentBoard,
|
||
)
|
||
Request_Cache[requestIdentifier] = scoreTable
|
||
response = jsonify(scoreTable)
|
||
return response
|
||
|
||
|
||
@app.route("/agentSelectModify_addAspect", methods=["post"])
|
||
def Handle_agentSelectModify_addAspect():
|
||
incoming_data = request.get_json()
|
||
requestIdentifier = str(
|
||
("/agentSelectModify_addAspect", incoming_data["aspectList"])
|
||
)
|
||
|
||
if USE_CACHE:
|
||
if requestIdentifier in Request_Cache:
|
||
return jsonify(Request_Cache[requestIdentifier])
|
||
|
||
scoreTable = AgentSelectModify_addAspect(
|
||
aspectList=incoming_data["aspectList"], Agent_Board=AgentBoard
|
||
)
|
||
Request_Cache[requestIdentifier] = scoreTable
|
||
response = jsonify(scoreTable)
|
||
return response
|
||
|
||
|
||
@app.route("/fill_stepTask", methods=["post"])
|
||
def Handle_fill_stepTask():
|
||
incoming_data = request.get_json()
|
||
requestIdentifier = str(
|
||
(
|
||
"/fill_stepTask",
|
||
incoming_data["General Goal"],
|
||
incoming_data["stepTask"],
|
||
)
|
||
)
|
||
|
||
if USE_CACHE:
|
||
if requestIdentifier in Request_Cache:
|
||
time.sleep(1)
|
||
return jsonify(Request_Cache[requestIdentifier])
|
||
|
||
filled_stepTask = fill_stepTask(
|
||
General_Goal=incoming_data["General Goal"],
|
||
stepTask=incoming_data["stepTask"],
|
||
Agent_Board=AgentBoard,
|
||
AgentProfile_Dict=AgentProfile_Dict,
|
||
)
|
||
filled_stepTask = Add_Collaboration_Brief_FrontEnd(filled_stepTask)
|
||
Request_Cache[requestIdentifier] = filled_stepTask
|
||
response = jsonify(filled_stepTask)
|
||
return response
|
||
|
||
|
||
@app.route("/branch_PlanOutline", methods=["post"])
|
||
def Handle_branch_PlanOutline():
|
||
incoming_data = request.get_json()
|
||
requestIdentifier = str(
|
||
(
|
||
"/branch_PlanOutline",
|
||
incoming_data["branch_Number"],
|
||
incoming_data["Modification_Requirement"],
|
||
incoming_data["Existing_Steps"],
|
||
incoming_data["Baseline_Completion"],
|
||
incoming_data["Initial Input Object"],
|
||
incoming_data["General Goal"],
|
||
)
|
||
)
|
||
|
||
if USE_CACHE:
|
||
if requestIdentifier in Request_Cache:
|
||
return jsonify(Request_Cache[requestIdentifier])
|
||
|
||
branchList = branch_PlanOutline(
|
||
branch_Number=incoming_data["branch_Number"],
|
||
Modification_Requirement=incoming_data["Modification_Requirement"],
|
||
Existing_Steps=incoming_data["Existing_Steps"],
|
||
Baseline_Completion=incoming_data["Baseline_Completion"],
|
||
InitialObject_List=incoming_data["Initial Input Object"],
|
||
General_Goal=incoming_data["General Goal"],
|
||
)
|
||
branchList = Add_Collaboration_Brief_FrontEnd(branchList)
|
||
Request_Cache[requestIdentifier] = branchList
|
||
response = jsonify(branchList)
|
||
return response
|
||
|
||
|
||
@app.route("/branch_TaskProcess", methods=["post"])
|
||
def Handle_branch_TaskProcess():
|
||
incoming_data = request.get_json()
|
||
requestIdentifier = str(
|
||
(
|
||
"/branch_TaskProcess",
|
||
incoming_data["branch_Number"],
|
||
incoming_data["Modification_Requirement"],
|
||
incoming_data["Existing_Steps"],
|
||
incoming_data["Baseline_Completion"],
|
||
incoming_data["stepTaskExisting"],
|
||
incoming_data["General Goal"],
|
||
)
|
||
)
|
||
|
||
if USE_CACHE:
|
||
if requestIdentifier in Request_Cache:
|
||
return jsonify(Request_Cache[requestIdentifier])
|
||
|
||
branchList = branch_TaskProcess(
|
||
branch_Number=incoming_data["branch_Number"],
|
||
Modification_Requirement=incoming_data["Modification_Requirement"],
|
||
Existing_Steps=incoming_data["Existing_Steps"],
|
||
Baseline_Completion=incoming_data["Baseline_Completion"],
|
||
stepTaskExisting=incoming_data["stepTaskExisting"],
|
||
General_Goal=incoming_data["General Goal"],
|
||
AgentProfile_Dict=AgentProfile_Dict,
|
||
)
|
||
Request_Cache[requestIdentifier] = branchList
|
||
response = jsonify(branchList)
|
||
return response
|
||
|
||
|
||
@app.route("/generate_basePlan", methods=["post"])
|
||
def Handle_generate_basePlan():
|
||
incoming_data = request.get_json()
|
||
requestIdentifier = str(
|
||
(
|
||
"/generate_basePlan",
|
||
incoming_data["General Goal"],
|
||
incoming_data["Initial Input Object"],
|
||
)
|
||
)
|
||
|
||
if USE_CACHE:
|
||
if requestIdentifier in Request_Cache:
|
||
time.sleep(2)
|
||
return jsonify(Request_Cache[requestIdentifier])
|
||
|
||
basePlan = generate_basePlan(
|
||
General_Goal=incoming_data["General Goal"],
|
||
Agent_Board=AgentBoard,
|
||
AgentProfile_Dict=AgentProfile_Dict,
|
||
InitialObject_List=incoming_data["Initial Input Object"],
|
||
context="\n请注意,目标是给出解决方案,而不是工程实现,不需要实验验证,也不需要推广计划。"
|
||
)
|
||
basePlan_withRenderSpec = Add_Collaboration_Brief_FrontEnd(basePlan)
|
||
Request_Cache[requestIdentifier] = basePlan_withRenderSpec
|
||
response = jsonify(basePlan_withRenderSpec)
|
||
return response
|
||
|
||
|
||
@app.route("/executePlan", methods=["post"])
|
||
def Handle_executePlan():
|
||
incoming_data = request.get_json()
|
||
cur_context = ""
|
||
if "材料腐蚀" in incoming_data["plan"]["General Goal"]:
|
||
cur_context = context["材料腐蚀"]
|
||
|
||
requestIdentifier = str(
|
||
(
|
||
"/executePlan",
|
||
incoming_data["num_StepToRun"],
|
||
incoming_data["RehearsalLog"],
|
||
incoming_data["plan"],
|
||
)
|
||
)
|
||
|
||
if USE_CACHE:
|
||
if requestIdentifier in Request_Cache:
|
||
time.sleep(3)
|
||
return jsonify(Request_Cache[requestIdentifier])
|
||
|
||
RehearsalLog = executePlan(
|
||
incoming_data["plan"],
|
||
incoming_data["num_StepToRun"],
|
||
incoming_data["RehearsalLog"],
|
||
AgentProfile_Dict,
|
||
context=cur_context
|
||
)
|
||
Request_Cache[requestIdentifier] = RehearsalLog
|
||
response = jsonify(RehearsalLog)
|
||
return response
|
||
|
||
|
||
@app.route("/_saveRequestCashe", methods=["GET"])
|
||
def Handle_saveRequestCashe():
|
||
with open(
|
||
os.path.join(os.getcwd(), "RequestCache", "Request_Cache.json"), "w"
|
||
) as json_file:
|
||
json.dump(Request_Cache, json_file, indent=4)
|
||
response = jsonify(
|
||
{"code": 200, "content": "request cashe sucessfully saved: " + os.path.join(os.getcwd(), "RequestCache", "Request_Cache.json")}
|
||
)
|
||
return response
|
||
|
||
|
||
@app.route("/setAgents", methods=["POST"])
|
||
def set_agents():
|
||
global AgentBoard, AgentProfile_Dict
|
||
AgentBoard = request.json
|
||
AgentProfile_Dict = {}
|
||
for item in AgentBoard:
|
||
name = item["Name"]
|
||
profile = item["Profile"]
|
||
AgentProfile_Dict[name] = profile
|
||
return jsonify({"code": 200, "content": "set agentboard successfully"})
|
||
|
||
|
||
def init():
|
||
global AgentBoard, AgentProfile_Dict, Request_Cache
|
||
with open(
|
||
os.path.join(os.getcwd(), "RequestCache", "Request_Cache.json"), "r"
|
||
) as json_file:
|
||
Request_Cache = json.load(json_file)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
parser = argparse.ArgumentParser(
|
||
description="start the backend for AgentCoord"
|
||
)
|
||
parser.add_argument(
|
||
"--port",
|
||
type=int,
|
||
default=8017,
|
||
help="set the port number, 8017 by defaul.",
|
||
)
|
||
args = parser.parse_args()
|
||
init()
|
||
app.run(host="0.0.0.0", port=args.port, debug=True)
|