Spaces:
Running
Running
File size: 17,625 Bytes
973f016 |
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 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import json\n",
"import random"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"<>:1: SyntaxWarning: invalid escape sequence '\\c'\n",
"<>:3: SyntaxWarning: invalid escape sequence '\\d'\n",
"<>:1: SyntaxWarning: invalid escape sequence '\\c'\n",
"<>:3: SyntaxWarning: invalid escape sequence '\\d'\n",
"C:\\Users\\rajst\\AppData\\Local\\Temp\\ipykernel_11856\\1444736939.py:1: SyntaxWarning: invalid escape sequence '\\c'\n",
" image_data=pd.read_csv(\"data_set_formation\\custom_prompts_df.csv\")\n",
"C:\\Users\\rajst\\AppData\\Local\\Temp\\ipykernel_11856\\1444736939.py:3: SyntaxWarning: invalid escape sequence '\\d'\n",
" with open(\"data_set_formation\\data.json\") as read:\n"
]
}
],
"source": [
"image_data=pd.read_csv(\"data_set_formation\\custom_prompts_df.csv\")\n",
"\n",
"with open(\"data_set_formation\\data.json\") as read:\n",
" text_data=json.load(read)\n",
"# prompt_data="
]
},
{
"cell_type": "code",
"execution_count": 7,
"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>image_file</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>painting of King Henry VIII carrying an umbrella</td>\n",
" <td>images/0/custom_0_0.png</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Fox Mulder and a chinchilla walking down a roa...</td>\n",
" <td>images/0/custom_1_0.png</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>photo of a gas burner by a soft pretzel</td>\n",
" <td>images/0/custom_2_0.png</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>photo of Shyster standing street lights on at ...</td>\n",
" <td>images/0/custom_3_0.png</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>cute young man eating a plant over a fence in ...</td>\n",
" <td>images/0/custom_5_0.png</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>99995</th>\n",
" <td>photo of a natural kite at Westminster Abbey</td>\n",
" <td>images/102/custom_102419_0.png</td>\n",
" </tr>\n",
" <tr>\n",
" <th>99996</th>\n",
" <td>smooth rum with a clock in the style of a digi...</td>\n",
" <td>images/102/custom_102420_0.png</td>\n",
" </tr>\n",
" <tr>\n",
" <th>99997</th>\n",
" <td>a lovable elephant by the Gamla Stan, Stockholm</td>\n",
" <td>images/102/custom_102421_0.png</td>\n",
" </tr>\n",
" <tr>\n",
" <th>99998</th>\n",
" <td>photo of Courtney Love with a hot dog</td>\n",
" <td>images/102/custom_102422_0.png</td>\n",
" </tr>\n",
" <tr>\n",
" <th>99999</th>\n",
" <td>Maniac jumping on a skateboard near a fence</td>\n",
" <td>images/102/custom_102423_0.png</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>100000 rows × 2 columns</p>\n",
"</div>"
],
"text/plain": [
" prompt \\\n",
"0 painting of King Henry VIII carrying an umbrella \n",
"1 Fox Mulder and a chinchilla walking down a roa... \n",
"2 photo of a gas burner by a soft pretzel \n",
"3 photo of Shyster standing street lights on at ... \n",
"4 cute young man eating a plant over a fence in ... \n",
"... ... \n",
"99995 photo of a natural kite at Westminster Abbey \n",
"99996 smooth rum with a clock in the style of a digi... \n",
"99997 a lovable elephant by the Gamla Stan, Stockholm \n",
"99998 photo of Courtney Love with a hot dog \n",
"99999 Maniac jumping on a skateboard near a fence \n",
"\n",
" image_file \n",
"0 images/0/custom_0_0.png \n",
"1 images/0/custom_1_0.png \n",
"2 images/0/custom_2_0.png \n",
"3 images/0/custom_3_0.png \n",
"4 images/0/custom_5_0.png \n",
"... ... \n",
"99995 images/102/custom_102419_0.png \n",
"99996 images/102/custom_102420_0.png \n",
"99997 images/102/custom_102421_0.png \n",
"99998 images/102/custom_102422_0.png \n",
"99999 images/102/custom_102423_0.png \n",
"\n",
"[100000 rows x 2 columns]"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"image_data"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"data_dict={\"prompt\":[],\"label\":[]}"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"queries = [\n",
" # General Descriptions\n",
" \"Generate a beautiful sunset over the ocean.\",\n",
" \"Create a futuristic cityscape at night.\",\n",
" \"Show a cozy cabin in the middle of a snowy forest.\",\n",
" \"Draw a tropical beach with palm trees and clear blue water.\",\n",
" \"Design a medieval castle on a hilltop.\",\n",
" \n",
" # Character-Focused Queries\n",
" \"Generate a young woman with long red hair in a fantasy setting.\",\n",
" \"Create a warrior in futuristic armor holding a glowing sword.\",\n",
" \"Draw a friendly robot helping people in a park.\",\n",
" \"Design a wise old wizard with a long beard and staff.\",\n",
" \"Illustrate a child playing with a puppy in a garden.\",\n",
" \n",
" # Animal and Nature Queries\n",
" \"Show a majestic tiger in a dense jungle.\",\n",
" \"Create a flock of birds flying over a mountain range.\",\n",
" \"Draw a koi fish pond with colorful fish.\",\n",
" \"Generate a close-up of a butterfly on a flower.\",\n",
" \"Illustrate a desert landscape with cacti and a setting sun.\",\n",
" \n",
" # Architectural and Object Queries\n",
" \"Design a futuristic spaceship hovering above Earth.\",\n",
" \"Create a vintage car driving on a country road.\",\n",
" \"Draw a small café on a busy European street.\",\n",
" \"Generate a treehouse in the middle of a forest.\",\n",
" \"Show a steampunk-style clock tower.\",\n",
" \n",
" # Abstract or Conceptual Queries\n",
" \"Create an image representing the concept of time.\",\n",
" \"Design a surreal landscape with floating islands.\",\n",
" \"Generate an artwork of colors blending like a rainbow.\",\n",
" \"Illustrate the feeling of calmness in visual form.\",\n",
" \"Show a dreamlike city made of crystal.\",\n",
" \n",
" # Cultural or Historical Themes\n",
" \"Illustrate an ancient Egyptian pyramid under the stars.\",\n",
" \"Show a samurai in traditional armor standing in a bamboo forest.\",\n",
" \"Draw a Viking ship sailing through a storm.\",\n",
" \"Create an Indian temple with intricate carvings.\",\n",
" \"Generate a Renaissance-style painting of a feast.\",\n",
" \n",
" # Event or Scene Queries\n",
" \"Show a birthday party with balloons and a cake.\",\n",
" \"Create an image of people camping under the stars.\",\n",
" \"Draw a bustling market in a small village.\",\n",
" \"Illustrate a concert with a crowd and colorful lights.\",\n",
" \"Generate an image of a wedding ceremony by the beach.\",\n",
" \n",
" # Seasonal and Holiday Themes\n",
" \"Show a Christmas scene with a decorated tree and snow.\",\n",
" \"Generate a spooky Halloween setting with pumpkins and ghosts.\",\n",
" \"Create a spring meadow full of flowers and butterflies.\",\n",
" \"Draw an autumn forest with falling leaves.\",\n",
" \"Illustrate a New Year celebration with fireworks.\"\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"for i in queries:\n",
" data_dict['prompt'].append(i.lower())\n",
" data_dict['label'].append(\"image\")"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"counter=0\n",
"detail_list=[\"painting\",\"image\",\"photo\",\"frame\",\"picture\",\"potrait\",\"pic\",\"snapshot\"]\n",
"for i in image_data['prompt']:\n",
" if any([paint_key in i for paint_key in [\"painting\",\"image\",\"photo\",\"frame\",\"picture\",\"potrait\",\"pic\",\"snapshot\"]]):\n",
" data_dict['prompt'].append(i.lower().replace(random.choice(detail_list),\"image\"))\n",
" data_dict['label'].append(\"image\")\n",
" counter+=1\n",
" if counter==20000:\n",
" break\n",
"counter=0\n",
"for j in text_data[:20000]:\n",
" data_dict['prompt'].append(j['note'].lower())\n",
" data_dict['label'].append(\"text\")\n",
" counter+=1\n",
" if counter==15000:\n",
" break"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"counter=0\n",
"for z in text_data[15000:]:\n",
" if any([paint_key in z['note'] for paint_key in [\"painting\",\"image\",\"photo\",\"frame\",\"picture\",\"potrait\",\"pic\",\"snapshot\"]]):\n",
" data_dict['prompt'].append(z['note'].lower())\n",
" data_dict['label'].append(\"text\")\n",
" counter+=1\n",
" if counter==5000:\n",
" break"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 13,
"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>label</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>generate a beautiful sunset over the ocean.</td>\n",
" <td>image</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>create a futuristic cityscape at night.</td>\n",
" <td>image</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>show a cozy cabin in the middle of a snowy for...</td>\n",
" <td>image</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>draw a tropical beach with palm trees and clea...</td>\n",
" <td>image</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>design a medieval castle on a hilltop.</td>\n",
" <td>image</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>40035</th>\n",
" <td>i was watching a documentary and it spoke of s...</td>\n",
" <td>text</td>\n",
" </tr>\n",
" <tr>\n",
" <th>40036</th>\n",
" <td>should i buy a dslr or a new phone for photogr...</td>\n",
" <td>text</td>\n",
" </tr>\n",
" <tr>\n",
" <th>40037</th>\n",
" <td>okay, i see. so it depends on how serious i am...</td>\n",
" <td>text</td>\n",
" </tr>\n",
" <tr>\n",
" <th>40038</th>\n",
" <td>it is just to take photos of my family</td>\n",
" <td>text</td>\n",
" </tr>\n",
" <tr>\n",
" <th>40039</th>\n",
" <td>is there any topical treatment i can apply to ...</td>\n",
" <td>text</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>40040 rows × 2 columns</p>\n",
"</div>"
],
"text/plain": [
" prompt label\n",
"0 generate a beautiful sunset over the ocean. image\n",
"1 create a futuristic cityscape at night. image\n",
"2 show a cozy cabin in the middle of a snowy for... image\n",
"3 draw a tropical beach with palm trees and clea... image\n",
"4 design a medieval castle on a hilltop. image\n",
"... ... ...\n",
"40035 i was watching a documentary and it spoke of s... text\n",
"40036 should i buy a dslr or a new phone for photogr... text\n",
"40037 okay, i see. so it depends on how serious i am... text\n",
"40038 it is just to take photos of my family text\n",
"40039 is there any topical treatment i can apply to ... text\n",
"\n",
"[40040 rows x 2 columns]"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.DataFrame(data_dict)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"folder_path = 'formatted_data/'\n",
"\n",
"# Get the list of all files in the folder\n",
"file_names = os.listdir(folder_path)\n",
"max_file_name=max([int(i.split(\"_\")[-1][:-4]) for i in file_names])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Confussing prompts"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"# from langchain_community.llms import Ollama\n",
"# llm = Ollama(model=\"llava:34b \",num_ctx=10000)\n",
"# enhancement=\"I need to train a model to distinguish between text and images. Please create a list of challenging prompts where the model needs to decide whether to generate text or identify an image.\"\n",
"# prompt = enhancement\n",
"# # result = llm.invoke(prompt)\n",
"# value=llm.invoke(prompt)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"# print(str(value))"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"pd.DataFrame(data_dict).to_csv(\"formatted_data/data_\"+str(max_file_name+1)+\".csv\",index=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "env",
"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.12.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|