as-cle-bert commited on
Commit
adc3639
1 Parent(s): 626e10d

Create PokemonCards.py

Browse files
Files changed (1) hide show
  1. PokemonCards.py +28 -0
PokemonCards.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset
2
+ import random as r
3
+
4
+ dataset = load_dataset("TheFusion21/PokemonCards")
5
+ image_urls = dataset["train"]["image_url"]
6
+ image_des = dataset["train"]["caption"]
7
+ image_name = dataset["train"]["name"]
8
+ image_set_name = dataset["train"]["set_name"]
9
+
10
+ def choose_random_cards(n_cards: int = 5):
11
+ global image_urls, image_des, image_name, image_set_name
12
+ indexes = []
13
+ n = 0
14
+ while n < n_cards:
15
+ l = r.randint(0,len(image_urls))
16
+ if l not in indexes:
17
+ n+=1
18
+ indexes.append(l)
19
+ else:
20
+ continue
21
+ basestr = ""
22
+ c = 0
23
+ for idx in indexes:
24
+ c+=1
25
+ llmstr = f"CARD {c}:\n\nNAME:\n{image_name[idx]}\n\SET_NAME:\n{image_set_name[idx]}\n\nDESCRIPTION:\n{image_des[idx]}"
26
+ basestr+=llmstr+"\n\n\n"
27
+ urls = [image_urls[i] for i in indexes]
28
+ return basestr, urls