-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
132 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import argparse | ||
import dataclasses | ||
import logging | ||
import os | ||
|
||
from storyteller import StoryTeller, StoryTellerConfig | ||
from storyteller.utils import set_log_level, set_seed | ||
|
||
|
||
def get_args() -> argparse.Namespace: | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--writer_prompt", | ||
type=str, | ||
default="Once upon a time, unicorns roamed the Earth.", | ||
) | ||
parser.add_argument( | ||
"--painter_prompt_prefix", type=str, default="Beautiful painting" | ||
) | ||
parser.add_argument("--num_images", type=int, default=10) | ||
parser.add_argument("--output_dir", type=str, default="out") | ||
parser.add_argument("--seed", type=int, default=42) | ||
default_config = StoryTellerConfig() | ||
for key, value in dataclasses.asdict(default_config).items(): | ||
parser.add_argument(f"--{key}", type=type(value), default=value) | ||
args = parser.parse_args() | ||
return args | ||
|
||
|
||
def main() -> None: | ||
args = get_args() | ||
set_seed(args.seed) | ||
set_log_level(logging.WARNING) | ||
os.environ["TOKENIZERS_PARALLELISM"] = "false" | ||
config = StoryTellerConfig() | ||
for field in dataclasses.fields(config): | ||
name = field.name | ||
setattr(config, name, getattr(args, name)) | ||
story_teller = StoryTeller(config) | ||
os.makedirs(args.output_dir, exist_ok=True) | ||
story_teller.generate( | ||
args.writer_prompt, args.painter_prompt_prefix, args.num_images, args.output_dir | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
from dataclasses import dataclass | ||
from pathlib import Path | ||
|
||
import torch | ||
|
||
|
||
@dataclass | ||
class StoryTellerConfig: | ||
image_size: int = 512 | ||
max_new_tokens: int = 50 | ||
writer: str = "gpt2" | ||
painter: str = "stabilityai/stable-diffusion-2" | ||
speaker: str = "tts_models/en/ljspeech/glow-tts" | ||
writer_device: str = "cuda:0" | ||
painter_device: str = "cuda:0" | ||
output_dir: str = Path(__file__).parent.parent / "out" | ||
seed: int = 42 | ||
diffusion_prompt_prefix: str = "Beautiful painting" | ||
writer_device: str = "cuda:0" if torch.cuda.is_available() else "cpu" | ||
painter_device: str = "cuda:0" if torch.cuda.is_available() else "cpu" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters