简体中文
pip install sunra-client
subscribe
import sunra_client result = sunra_client.subscribe( "black-forest-labs/flux-kontext-pro/text-to-image", arguments={ "prompt": '一个吉卜力风格的海边小镇,有彩色房屋,晾衣绳飘扬,猫咪在窗台上睡觉。', "width": 1024, "height": 768, "output_format": 'jpeg' }, with_logs=True, on_enqueue=print, on_queue_update=print, ) print(result)
request_id
import sunra_client handler = sunra_client.submit( "black-forest-labs/flux-kontext-pro/text-to-image", arguments={ "prompt": '一个吉卜力风格的海边小镇,有彩色房屋,晾衣绳飘扬,猫咪在窗台上睡觉。', "width": 1024, "height": 768, "output_format": 'jpeg' }, webhook_url="https://optional.webhook.url/for/results", ) request_id = handler.request_id
import sunra_client status = sunra_client.status(request_id, with_logs=True)
import sunra_client result = sunra_client.result(request_id)
import sunra_client # 初始化同步客户端 client = sunra_client.SyncClient() try: # 从给定路径上传文件 file_url = client.upload_file(path="path/to/your/image.png") print(f"文件上传成功:{file_url}") # 此URL现在可以与模型端点一起使用 except FileNotFoundError: print("错误:在指定路径未找到文件。") except Exception as e: print(f"发生错误:{e}")
import sunra_client from PIL import Image import io # 初始化同步客户端 client = sunra_client.SyncClient() # 在内存中创建图像,例如使用 Pillow image = Image.new("RGB", (600, 400), color = 'red') byte_arr = io.BytesIO() image.save(byte_arr, format='PNG') image_bytes = byte_arr.getvalue() # 使用 `upload` 方法上传内存中的图像数据 image_url = client.upload( data=image_bytes, content_type="image/png" ) print(f"图像上传成功:{image_url}")