Documentation Index
Fetch the complete documentation index at: https://docs.sunra.ai/llms.txt
Use this file to discover all available pages before exploring further.
Python용 클라이언트 라이브러리는 Sunra의 서비스와 상호 작용하기 쉬운 인터페이스를 제공합니다.
프로젝트에 클라이언트를 통합하려면 pip를 사용하여 설치하십시오.
엔드포인트 호출
Sunra는 대기열 시스템을 통해 엔드포인트 요청을 관리하여 안정성과 확장성을 보장합니다. 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)
파일 업로드
비동기 요청에 사용할 URL을 얻으려면 파일을 업로드하십시오. 이는 이미지-비디오 또는 음성-텍스트 변환기와 같은 파일을 처리하는 모델에 필수적입니다.
로컬 파일 업로드
로컬 파일 시스템에서 파일을 쉽게 업로드할 수 있습니다. 이는 로컬 데이터를 처리하는 스크립트나 응용 프로그램에 유용합니다.
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}")
메모리 내 데이터 업로드
PIL(Pillow)로 만든 이미지 내용이나 웹 요청에서 받은 파일과 같이 메모리에 있는 데이터를 업로드할 수도 있습니다.
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}")
도움이나 토론을 위해 커뮤니티에 가입하십시오.
저희가 도와드리겠습니다!