Spaces:
Build error
Build error
update api
Browse filesFiles changed (2)
- caller.py+35-4
- requirements.txt+5-5
2 unmodified lines345678910111213144 unmodified lines1920212223249 unmodified lines34353637383947 unmodified lines87888990919293942 unmodified lines# This source code is licensed under the license found in the# LICENSE file in the root directory of this source tree.from PIL import Image, ImageFilterfrom loguru import loggerimport requestsimport base64import jsonimport io# 接口 URLt2i_url = 'https://magicarena.bytedance.com/api/evaluate/v1/algo/process'4 unmodified lines'X-USE-PPE': '1'}class SeedT2ICaller():def __init__(self, cfg, *args, **kwargs):self.cfg = cfg9 unmodified lines# "width": 64,# "height": 64})logger.info(f"{req_json}")# 请求发送response = requests.post(47 unmodified linesdata=json.dumps({'AlgoType': 2,'ReqJson': req_json,'BinaryData': [binary]# 'Base': base}))2 unmodified lines3456789101112131415161718194 unmodified lines242526272829303132333435363738394041424344454647484950515253549 unmodified lines6465666768697047 unmodified lines1181191201211221231241252 unmodified lines# This source code is licensed under the license found in the# LICENSE file in the root directory of this source tree.import requestsimport base64import jsonimport ioimport osimport hashlibimport hmacimport timeimport randomfrom PIL import Image, ImageFilterfrom loguru import logger# 接口 URLt2i_url = 'https://magicarena.bytedance.com/api/evaluate/v1/algo/process'4 unmodified lines'X-USE-PPE': '1'}APP_KEY = os.environ['APP_KEY']SECRET_KEY = os.environ["SECRET_KEY"]def get_auth(app_key, secret_key):# 生成随机数作为 noncenonce = str(random.randint(0, 2**31 - 1))# 获取当前时间戳timestamp = str(int(time.time()))# 调用 get_sign 函数生成签名sign = get_sign(nonce, timestamp, secret_key)return {"AppKey": app_key,"Timestamp":timestamp,"Nonce":nonce,"Sign": sign}def get_sign(nonce, timestamp, secret_key):keys = [nonce, secret_key, timestamp]keys.sort()key_str = ''.join(keys)sha1_hash = hashlib.sha1()sha1_hash.update(key_str.encode('utf-8'))signature = sha1_hash.hexdigest()return signature.lower()class SeedT2ICaller():def __init__(self, cfg, *args, **kwargs):self.cfg = cfg9 unmodified lines# "width": 64,# "height": 64})authInfo = get_auth(APP_KEY, SECRET_KEY)logger.info(f"{req_json}")# 请求发送response = requests.post(47 unmodified linesdata=json.dumps({'AlgoType': 2,'ReqJson': req_json,'BinaryData': [binary],'AuthInfo': get_auth(APP_KEY, SECRET_KEY)}))
12345gradionumpyloguruPillowrequests12345gradio==4.44.1numpy==1.23.5loguru==0.7.0Pillow==9.4.0requests==2.32.3
caller.py+35-4
requirements.txt+5-5