繁體中文
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}")