Spaces:
Build error
Build error
update api
Browse filesFiles changed (2)
- caller.py+35-4
- requirements.txt+5-5
2 unmodified lines345676789101112131415161718194 unmodified lines242526272829303132333435363738394041424344454647484950515253549 unmodified lines6465666768697047 unmodified lines11811912090911211221231241252 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 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): # 生成随机数作为 nonce nonce = 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 lines data=json.dumps({ 'AlgoType': 2, 'ReqJson': req_json, 'BinaryData': [binary] # 'Base': base 'BinaryData': [binary], 'AuthInfo': get_auth(APP_KEY, SECRET_KEY) }) )
1234512345gradionumpyloguruPillowrequestsgradio==4.44.1numpy==1.23.5loguru==0.7.0Pillow==9.4.0requests==2.32.3caller.py+35-4
requirements.txt+5-5