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(
|
2022-07-02 14:46:56 +00:00
|
|
|
description='Text',
|
|
|
|
default='court sketch of godzilla on trial'
|
2022-06-29 19:53:25 +00:00
|
|
|
),
|
|
|
|
seed: int = Input(
|
2022-07-02 14:46:56 +00:00
|
|
|
description='Seed',
|
|
|
|
default=6
|
2022-06-29 19:53:25 +00:00
|
|
|
),
|
2022-07-02 14:05:16 +00:00
|
|
|
grid_size: int = Input(
|
2022-07-02 14:46:56 +00:00
|
|
|
description='Grid Size',
|
2022-07-02 14:32:17 +00:00
|
|
|
ge=1,
|
2022-07-03 16:14:24 +00:00
|
|
|
le=4,
|
2022-07-02 20:36:51 +00:00
|
|
|
default=3
|
2022-07-02 14:05:16 +00:00
|
|
|
)
|
2022-06-29 19:53:25 +00:00
|
|
|
) -> Path:
|
2022-07-02 14:05:16 +00:00
|
|
|
image = self.model.generate_image(text, seed, grid_size=grid_size)
|
2022-07-02 14:46:56 +00:00
|
|
|
out_path = Path(tempfile.mkdtemp()) / 'output.png'
|
2022-06-29 19:53:25 +00:00
|
|
|
image.save(str(out_path))
|
|
|
|
|
|
|
|
return out_path
|