Skip to content

Commit

Permalink
Prompt override (dmarx#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmarx authored Oct 9, 2022
1 parent 2c416eb commit 1680cc1
Showing 1 changed file with 42 additions and 9 deletions.
51 changes: 42 additions & 9 deletions Video_Killed_The_Radio_Star_Defusion.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,13 @@
"workspace.active_project = project_name\n",
"\n",
"with open('config.yaml','w') as fp:\n",
" OmegaConf.save(config=workspace, f=fp.name)"
" OmegaConf.save(config=workspace, f=fp.name)\n",
"\n",
"# reset workspace\n",
"if 'df' in locals():\n",
" del df\n",
"if 'df_regen' in locals():\n",
" del df_regen"
]
},
{
Expand Down Expand Up @@ -560,6 +566,10 @@
" 'bool': {'type': 'tickCross'}\n",
"}\n",
"\n",
"# reset workspace\n",
"if 'df_regen' in locals():\n",
" del df_regen\n",
"\n",
"df = pd.DataFrame(prompt_starts).rename(\n",
" columns={\n",
" 'ts':'Timestamp (sec)',\n",
Expand All @@ -570,6 +580,8 @@
"if 'td' in df:\n",
" del df['td']\n",
"\n",
"df['override_prompt'] = ''\n",
"\n",
"df_pre = copy.deepcopy(df)\n",
"pn.widgets.Tabulator(df, formatters=tabulator_formatters)\n"
]
Expand Down Expand Up @@ -637,6 +649,7 @@
" for i, rec in enumerate(prompt_starts):\n",
" rec['ts'] = float(df.loc[i,'Timestamp (sec)'])\n",
" rec['prompt'] = df.loc[i,'Lyric']\n",
" rec['override_prompt'] = df.loc[i,'override_prompt']\n",
" \n",
" # ...actually, I think the above code might not do anything\n",
" # probably need to checkpoint prompt_starts into the storyboard on disk.\n",
Expand Down Expand Up @@ -709,7 +722,7 @@
"\n",
"d_ = dict(\n",
" _=''\n",
" , theme_prompt = \"deepdream, mural designed by a local artist\" # @param {type:'string'}\n",
" , theme_prompt = \"deepdeam, mural designed by a local artist\" # @param {type:'string'}\n",
" , height = 512 # @param {type:'integer'}\n",
" , width = 512 # @param {type:'integer'}\n",
" , display_frames_as_we_get_them = True # @param {type:'boolean'}\n",
Expand Down Expand Up @@ -754,6 +767,9 @@
" regen=True\n",
" if regen:\n",
" rec['frame0_fpath'] = None\n",
" rec['prompt'] = df_regen.loc[i, 'Lyric']\n",
" rec['override_prompt'] = df_regen.loc[i, 'override_prompt']\n",
" print(rec)\n",
" archive_images(i, root=root)\n",
" print(\"archival process complete\")\n",
"\n",
Expand All @@ -767,14 +783,22 @@
"\n",
"print(\"Ensuring each prompt has an associated image\")\n",
"for idx, rec in enumerate(prompt_starts):\n",
" print(\n",
" f\"[{idx} | {rec['ts']}] - {rec['prompt']}\"\n",
" )\n",
" lyric = rec['prompt']\n",
" prompt = f\"{lyric}, {theme_prompt}\"\n",
" override = rec.get('override_prompt','').strip()\n",
" if override:\n",
" print('override prompt detected')\n",
" prompt = override\n",
" print(\n",
" f\"\\n[{idx} | {rec['ts']}] - {lyric} - {prompt}\"\n",
" )\n",
" \n",
" if prompt_lag and (idx > 0):\n",
" rec_prev = prompt_starts[idx -1]\n",
" prompt = f\"{rec_prev['prompt']}, {prompt}\"\n",
" prev_prompt = rec_prev['override_prompt']\n",
" if not prev_prompt:\n",
" prev_prompt = rec_prev['prompt']\n",
" prompt = f\"{prev_prompt}, {prompt}\"\n",
" if rec.get('frame0_fpath') is None:\n",
" init_image = list(get_image_for_prompt(\n",
" prompt,\n",
Expand Down Expand Up @@ -812,7 +836,7 @@
"# flag regens #\n",
"###############\n",
"\n",
"df_regen = pd.DataFrame(prompt_starts)[['ts','prompt']].rename(\n",
"df_regen = pd.DataFrame(prompt_starts)[['ts','prompt','override_prompt']].rename(\n",
" columns={\n",
" 'ts':'Timestamp (sec)',\n",
" 'prompt':'Lyric',\n",
Expand All @@ -822,7 +846,7 @@
"df_regen['keep'] = True\n",
"\n",
"# move the \"keep\" column to the front\n",
"df_regen= df_regen[['keep', 'Timestamp (sec)', 'Lyric']]\n",
"df_regen= df_regen[['keep', 'Timestamp (sec)', 'Lyric', 'override_prompt']]\n",
"\n",
"pn.widgets.Tabulator(\n",
" df_regen,\n",
Expand Down Expand Up @@ -982,8 +1006,12 @@
" curr_variation_count = len(images_fpaths)\n",
" print(curr_variation_count)\n",
" if curr_variation_count < n_variations:\n",
" # to do: \n",
" # * prompt lag\n",
" lyric = rec['prompt']\n",
" prompt = f\"{lyric}, {theme_prompt}\"\n",
" if rec.get('override_prompt'):\n",
" prompt = rec['override_prompt']\n",
"\n",
" init_image = Image.open(rec['frame0_fpath'])\n",
" # next line is here to permit user to specify more variations for a specific entry\n",
Expand Down Expand Up @@ -1029,9 +1057,14 @@
"from subprocess import Popen, PIPE\n",
"\n",
"from omegaconf import OmegaConf\n",
"from prefetch_generator import BackgroundGenerator\n",
"from tqdm.autonotebook import tqdm\n",
"\n",
"try:\n",
" from prefetch_generator import BackgroundGenerator\n",
"except:\n",
" !pip install prefetch_generator \n",
" from prefetch_generator import BackgroundGenerator\n",
"\n",
"from vktrs.tsp import (\n",
" tsp_permute_frames,\n",
" batched_tsp_permute_frames,\n",
Expand Down

0 comments on commit 1680cc1

Please sign in to comment.