Browse Source

ai创意工厂需要的接口组合

master
majiahui@haimaqingfan.com 2 years ago
parent
commit
2d570bf96d
  1. 58
      main.py

58
main.py

@ -16,7 +16,7 @@ RE_CHINA_NUMS = "[1-9].(.*)"
# 允许的文件类型
ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg', 'gif'}
fenhao_list = [";", ""]
moahao_list = [":", ""]
prompt_picture_dict = {
@ -24,7 +24,7 @@ prompt_picture_dict = {
"2": "图中的商品:{},有什么亮点,写一段营销话语",
"3": "图中的商品:{},有以下亮点:\n{}\n根据这些优势亮点,写一段营销文本让商品卖的更好",
"4": "图中的商品:{},有哪些不足之处可以改进?",
"5": "图中{}的渲染图做哪些调整可以更吸引消费者",
"5": "图中{}的渲染图做哪些调整可以更吸引消费者,请分条列举,例如:“1.xxx, 2.xxx”",
"6": "根据图中的商品:{},生成一个商品名称,要求商品名称格式中包含的信息(有品牌名,有产品名,有细分产品种类词,比如猫砂,篮球鞋等,有三到五个卖点和形容词)",
}
@ -134,20 +134,33 @@ def type_1(path_list, commodity, input_type):
prompy_text = prompt_picture_dict[input_type]
prompy_text = prompy_text.format(commodity)
for path in path_list:
cycle_num = 0
while True:
result = picture_model_predict(path, prompy_text)
result_list = str(result).split("\n")
result_list = [i for i in result_list if i != ""]
if len(result_list) > 3:
result_list_len = True
for i in result_list:
response_re = re.findall(RE_CHINA_NUMS, i)
for result_dan in result_list:
dan_maohao = False
response_re = re.findall(RE_CHINA_NUMS, result_dan)
if response_re == []:
dan_result_geshi = False
continue
if "" not in i:
for maohao in moahao_list:
if maohao in result_dan:
dan_maohao = True
break
if dan_maohao == False:
dan_result_geshi_maohao = False
continue
break
cycle_num += 1
if cycle_num == 4:
return 400, []
if result_list_len == True and dan_result_geshi == True and dan_result_geshi_maohao == True:
break
@ -156,9 +169,7 @@ def type_1(path_list, commodity, input_type):
response_re = re.findall(RE_CHINA_NUMS, i)
guanjianci = response_re[0].split("")
maidian_list.append([i, guanjianci])
return_list.append(maidian_list)
return code, return_list
def type_2(path_list, commodity, input_type, additional):
@ -242,8 +253,11 @@ def type_5(path_list, commodity, input_type):
for path in path_list:
while True:
cycle_num = 0
if result_list_type == True:
break
if cycle_num == 4:
return 400, []
result = picture_model_predict(path, prompy_text)
result_list = str(result).split("\n")
result_list = [i for i in result_list if i != ""]
@ -358,13 +372,35 @@ def upload_file():
# 业务逻辑
try:
type_list = str(type_str).split(",")
result = []
code = 200
result = {
"main": [],
"spilt": []
}
for type_dan in type_list:
main_dan = []
slice_dan = []
print("type:", type_dan)
code, result_dan = picture_main(path_list, commodity, type_dan, additional)
result.append(result_dan)
if code == 400:
break
if type_dan == "1":
result_dan_new = []
for i in result_dan[0]:
result_dan_new.append(i[0])
slice_dan.append(i[1])
main_dan = [result_dan_new]
else:
main_dan = result_dan
if slice_dan != []:
result["spilt"].append({type_dan: slice_dan})
result["main"].append({type_dan: main_dan})
return_text = {"texts": result, "probabilities": None, "status_code": code}
print(return_text)
except:
return_text = {"texts": "运算出错", "probabilities": None, "status_code": 400}
log.log('start at',

Loading…
Cancel
Save