new file: app.py new file: app/ali_oss.py new file: app/app.py new file: app/app_common.py new file: app/config.py new file: app/coze.py new file: app/generate_api.py new file: app/html_crypto.py new file: app/main.py new file: app/web_source/admin.html new file: app/web_source/brand.html new file: app/web_source/home.html new file: app/web_source/index.html new file: app/web_source/login.html new file: app_common.py new file: blueprints/__init__.py new file: blueprints/__pycache__/__init__.cpython-311.pyc new file: blueprints/__pycache__/__init__.cpython-39.pyc new file: blueprints/__pycache__/admin.cpython-311.pyc new file: blueprints/__pycache__/admin.cpython-39.pyc new file: blueprints/__pycache__/auth.cpython-311.pyc new file: blueprints/__pycache__/auth.cpython-39.pyc new file: blueprints/__pycache__/brand.cpython-311.pyc new file: blueprints/__pycache__/brand.cpython-39.pyc new file: blueprints/__pycache__/image.cpython-311.pyc new file: blueprints/__pycache__/image.cpython-39.pyc new file: blueprints/__pycache__/main.cpython-311.pyc new file: blueprints/__pycache__/main.cpython-39.pyc new file: blueprints/admin.py new file: blueprints/auth.py new file: blueprints/brand.py new file: blueprints/image.py new file: blueprints/main.py new file: brand_spider/__pycache__/main.cpython-39.pyc new file: brand_spider/__pycache__/web_dec.cpython-39.pyc new file: brand_spider/main.py new file: brand_spider/web_dec.py new file: config.py new file: coze.py new file: generate_api.py new file: html_crypto.py new file: main.py new file: static/bg.jpg new file: "static/\345\223\201\347\211\214\346\226\207\346\241\243\346\240\274\345\274\217_\346\250\241\346\235\277.xlsx" new file: "static/\346\250\241\346\235\2772-\344\273\245\346\226\207\344\273\266\345\244\271\346\226\271\345\274\217\344\270\212\344\274\240.zip" new file: tool/.device_id new file: tool/__pycache__/devices.cpython-311.pyc new file: tool/__pycache__/devices.cpython-39.pyc new file: tool/devices.py
92 lines
2.9 KiB
Python
92 lines
2.9 KiB
Python
import requests
|
||
import time
|
||
|
||
from config import base_url, coze_token
|
||
|
||
|
||
|
||
|
||
|
||
def upload_file(file_path,_coze_token =coze_token):
|
||
url = f"{base_url}/files/upload"
|
||
headers = {
|
||
"Authorization": f"Bearer {_coze_token}"
|
||
}
|
||
print(file_path)
|
||
with open(file_path, 'rb') as f:
|
||
files = {
|
||
'file': f
|
||
}
|
||
# with open(f"{time.time()".replace(".","_")+".png","wb") as file:
|
||
# file.write(f.read())
|
||
# allow_redirects=True 模拟 curl 的 --location,默认即为 True
|
||
response = requests.post(url, headers=headers, files=files, allow_redirects=True)
|
||
data = response.json()
|
||
print("上传图片->>",data)
|
||
return data
|
||
|
||
def workflow_run(workflow_id, parameters,_coze_token = coze_token,is_async=True):
|
||
url = f"{base_url}/workflow/run"
|
||
headers = {
|
||
"Authorization": f"Bearer {_coze_token}",
|
||
"Content-Type": "application/json"
|
||
}
|
||
|
||
# 请求体(JSON 格式)
|
||
payload = {
|
||
"parameters": parameters,
|
||
# "parameters": {
|
||
# "name": "包包",
|
||
# "ratio": "3:4",
|
||
# "menu": 3,
|
||
# "resolution": "2K",
|
||
# "count": 1,
|
||
# "desc": "1、一个中国美女手上挎着这个包,2、站在商场内",
|
||
# "language": "中文",
|
||
# "style": "极简高级"
|
||
# },
|
||
"workflow_id": workflow_id,
|
||
"is_async" : is_async,
|
||
}
|
||
# 发送 POST 请求(使用 json 参数自动序列化并设置 Content-Type)
|
||
response = requests.post(url, headers=headers, json=payload)
|
||
data = response.json()
|
||
|
||
print("图片生成参数->>",payload)
|
||
print("图片生成->>",data)
|
||
return data
|
||
|
||
|
||
def query_result(workflow_id, execute_id,_coze_token=coze_token):
|
||
url = f"{base_url}/workflows/{workflow_id}/run_histories/{execute_id}"
|
||
headers = {
|
||
"Authorization": f"Bearer {_coze_token}",
|
||
"Content-Type": "application/json"
|
||
}
|
||
response = requests.get(url, headers=headers)
|
||
data = response.json()
|
||
print(f"【{execute_id}】结果查询->>",data)
|
||
return data
|
||
|
||
if __name__ == '__main__':
|
||
from config import workflow_id
|
||
|
||
parameters = {
|
||
"images": [
|
||
{
|
||
"file_id": "7612667079497613350",
|
||
|
||
},{
|
||
"file_id": "7612667042990768174",
|
||
},{
|
||
"file_id": "7612667111332577332",
|
||
}
|
||
]
|
||
}
|
||
# resp = workflow_run("7607680760402100258",parameters,_coze_token="sat_ZVNLR9Om54A3iMlJWAasHF9kbtDZnR3BjwjAxRwe8x7igEW446y5ROyVlW1UlpVX")
|
||
# print(resp)
|
||
|
||
# resp = query_result("7607680760402100258","7612668958797447187",_coze_token="sat_ZVNLR9Om54A3iMlJWAasHF9kbtDZnR3BjwjAxRwe8x7igEW446y5ROyVlW1UlpVX")
|
||
# print(resp)
|
||
resp = upload_file("D:\私单交付\maixiang_AI\测试图片数据\IMG_2686.JPG",_coze_token="sat_ZVNLR9Om54A3iMlJWAasHF9kbtDZnR3BjwjAxRwe8x7igEW446y5ROyVlW1UlpVX")
|
||
print(resp) |