日本語
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}")