2022-06-29 19:53:25 +00:00
|
|
|
import tempfile
|
|
|
|
from cog import BasePredictor, Path, Input
|
|
|
|
|
2022-07-01 23:44:24 +00:00
|
|
|
from min_dalle import MinDalle
|
2022-06-29 19:53:25 +00:00
|
|
|
|
|
|
|
class Predictor(BasePredictor):
|
|
|
|
def setup(self):
|
2022-07-01 23:44:24 +00:00
|
|
|
self.model = MinDalle(is_mega=True)
|
2022-06-29 19:53:25 +00:00
|
|
|
|
|
|
|
def predict(
|
|
|
|
self,
|
|
|
|
text: str = Input(
|
|
|
|
description="Text for generating images.",
|
|
|
|
),
|
|
|
|
seed: int = Input(
|
2022-07-02 13:20:42 +00:00
|
|
|
description="Specify a random seed.",
|
2022-06-29 19:53:25 +00:00
|
|
|
),
|
|
|
|
) -> Path:
|
2022-07-02 13:20:42 +00:00
|
|
|
image = self.model.generate_image(text, seed, grid_size=3)
|
2022-06-29 19:53:25 +00:00
|
|
|
out_path = Path(tempfile.mkdtemp()) / "output.png"
|
|
|
|
image.save(str(out_path))
|
|
|
|
|
|
|
|
return out_path
|