Spaces:
Sleeping
Sleeping
Update providers/together_provider.py
Browse files
providers/together_provider.py
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# providers/together_provider.py
|
| 2 |
+
from typing import List
|
| 3 |
+
from together import Together
|
| 4 |
+
from .base import ImageProvider
|
| 5 |
+
|
| 6 |
+
_DEFAULT_MODEL = "black-forest-labs/FLUX.1-dev"
|
| 7 |
+
|
| 8 |
+
class TogetherImageProvider(ImageProvider):
|
| 9 |
+
"""
|
| 10 |
+
Together Images API (FLUX family).
|
| 11 |
+
Docs: https://docs.together.ai/docs/images-overview
|
| 12 |
+
https://docs.together.ai/reference/images
|
| 13 |
+
"""
|
| 14 |
+
def __init__(self, api_key: str, model: str = _DEFAULT_MODEL):
|
| 15 |
+
# The SDK reads TOGETHER_API_KEY from env automatically,
|
| 16 |
+
# but we also pass it explicitly to be safe.
|
| 17 |
+
self.client = Together(api_key=api_key)
|
| 18 |
+
self.model = model
|
| 19 |
+
|
| 20 |
+
def generate_image(self, prompt: str, size: str = "1024x1024", n: int = 1) -> List[str]:
|
| 21 |
+
width, height = (int(x) for x in size.split("x"))
|
| 22 |
+
# steps 24–30 are a good sweet spot for interiors; dev is fast, pro is premium.
|
| 23 |
+
resp = self.client.images.generate(
|
| 24 |
+
prompt=prompt,
|
| 25 |
+
model=self.model,
|
| 26 |
+
width=width,
|
| 27 |
+
height=height,
|
| 28 |
+
steps=28,
|
| 29 |
+
n=n,
|
| 30 |
+
response_format="b64_json", # return base64 in JSON
|
| 31 |
+
)
|
| 32 |
+
# Each item exposes .b64_json
|
| 33 |
+
return [d.b64_json for d in resp.data]
|