File size: 10,334 Bytes
342b9c8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "57421672",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import requests\n",
"import time\n",
"import urllib.parse as urlparse"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "436f88be",
"metadata": {},
"outputs": [],
"source": [
"BASE_URL = \"https://ps6bzj7vlp0okc-3754.proxy.runpod.net/\""
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "efe7ba74",
"metadata": {},
"outputs": [],
"source": [
"def txt2img(prompt: str, name: str):\n",
" while True:\n",
" try:\n",
" url = urlparse.urljoin(BASE_URL, \"txt2img\")\n",
" payload = {\n",
" \"prompt\": prompt,\n",
" \"negative_prompt\": None,\n",
" \"width\": \"1024\",\n",
" \"height\": \"1024\",\n",
" \"samples\": 1,\n",
" \"num_inference_steps\": \"8\",\n",
" \"seed\": 1337,\n",
" \"guidance_scale\": 3,\n",
" \"safety_checker\": \"no\",\n",
" }\n",
"\n",
" headers = {\"Content-Type\": \"application/x-www-form-urlencoded\"}\n",
"\n",
" response = requests.post(url, headers=headers, data=payload)\n",
" response_json = response.json()\n",
" link = response_json[\"links\"][0]\n",
"\n",
" time.sleep(2)\n",
"\n",
" response = requests.get(link, stream=True)\n",
" \n",
" while b\"<!DOCTYPE\" in response.content:\n",
" time.sleep(1)\n",
" response = requests.get(link, stream=True)\n",
" \n",
" with open(f\"{name}.png\", \"wb\") as file:\n",
" file.write(response.content)\n",
" break\n",
" \n",
" except Exception as e:\n",
" print(f\"Exception: {e}\")\n",
" time.sleep(2)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "1a7eb1fa",
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv(\"PartiPrompts.tsv\", sep=\"\\t\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "d7badb13",
"metadata": {},
"outputs": [],
"source": [
"df.fillna(\"\", inplace=True)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "18bec64f",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Prompt</th>\n",
" <th>Category</th>\n",
" <th>Challenge</th>\n",
" <th>Note</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>bond</td>\n",
" <td>Abstract</td>\n",
" <td>Basic</td>\n",
" <td>Biology-inspired concepts with multiple meanings</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>element</td>\n",
" <td>Abstract</td>\n",
" <td>Basic</td>\n",
" <td>Biology-inspired concepts with multiple meanings</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>molecule</td>\n",
" <td>Abstract</td>\n",
" <td>Basic</td>\n",
" <td>Biology-inspired concepts with multiple meanings</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>life</td>\n",
" <td>Abstract</td>\n",
" <td>Basic</td>\n",
" <td>Biology-inspired concepts with multiple meanings</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>protein</td>\n",
" <td>Abstract</td>\n",
" <td>Basic</td>\n",
" <td>Biology-inspired concepts with multiple meanings</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1627</th>\n",
" <td>a wooden post with a yellow '3' painted on top</td>\n",
" <td>Outdoor Scenes</td>\n",
" <td>Writing & Symbols</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>1628</th>\n",
" <td>a wooden post in front of a patch of tall grass</td>\n",
" <td>Outdoor Scenes</td>\n",
" <td>Writing & Symbols</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>1629</th>\n",
" <td>a wooden post with a blue '5' painted on top</td>\n",
" <td>Outdoor Scenes</td>\n",
" <td>Writing & Symbols</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>1630</th>\n",
" <td>a series of musical notes on a black t-shirt</td>\n",
" <td>Artifacts</td>\n",
" <td>Writing & Symbols</td>\n",
" <td></td>\n",
" </tr>\n",
" <tr>\n",
" <th>1631</th>\n",
" <td>a series of musical notes on a computer screen</td>\n",
" <td>Artifacts</td>\n",
" <td>Writing & Symbols</td>\n",
" <td></td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>1632 rows × 4 columns</p>\n",
"</div>"
],
"text/plain": [
" Prompt Category \\\n",
"0 bond Abstract \n",
"1 element Abstract \n",
"2 molecule Abstract \n",
"3 life Abstract \n",
"4 protein Abstract \n",
"... ... ... \n",
"1627 a wooden post with a yellow '3' painted on top Outdoor Scenes \n",
"1628 a wooden post in front of a patch of tall grass Outdoor Scenes \n",
"1629 a wooden post with a blue '5' painted on top Outdoor Scenes \n",
"1630 a series of musical notes on a black t-shirt Artifacts \n",
"1631 a series of musical notes on a computer screen Artifacts \n",
"\n",
" Challenge Note \n",
"0 Basic Biology-inspired concepts with multiple meanings \n",
"1 Basic Biology-inspired concepts with multiple meanings \n",
"2 Basic Biology-inspired concepts with multiple meanings \n",
"3 Basic Biology-inspired concepts with multiple meanings \n",
"4 Basic Biology-inspired concepts with multiple meanings \n",
"... ... ... \n",
"1627 Writing & Symbols \n",
"1628 Writing & Symbols \n",
"1629 Writing & Symbols \n",
"1630 Writing & Symbols \n",
"1631 Writing & Symbols \n",
"\n",
"[1632 rows x 4 columns]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "de59ebb7",
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1611: a black t-shirt with the peace sign on it, artifacts,\n",
"1612: a store front with 'grassy meadow' written on it, outdoor scenes,\n",
"1613: a store front with 'awesomepurchase' written on it, outdoor scenes,\n",
"1614: a laptop screen showing an internet search, artifacts,\n",
"1615: a laptop screen showing a bunch of photographs, artifacts,\n",
"1616: a laptop screen showing a document being edited, artifacts,\n",
"1617: a book with the words 'don't panic!' written on it, artifacts,\n"
]
}
],
"source": [
"for index, row in df.iterrows():\n",
" if index <= 1617:\n",
" continue\n",
" index = f\"{index:04}\"\n",
" prompt = f\"{row['Prompt'].lower()}, {row['Category'].lower()}, {row['Note'].lower()}\".strip()\n",
" print(f\"{index}: {prompt}\")\n",
" txt2img(prompt, index)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "46638846",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|