Commit
·
5943094
0
Parent(s):
dataset info
Browse files- .gitignore +2 -0
- README.md +38 -0
- dataset.csv +14 -0
- scraper.py +123 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
.DS_Store
|
2 |
+
.env
|
README.md
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# outfitter-advice
|
2 |
+
|
3 |
+
On the OUTFITS subreddit, users frequently post multiple images and ask commenters to pick one (with a numeric comment like "2")
|
4 |
+
|
5 |
+
This evaluation collects the top two comments and their relative scores (for example, if there is overwhelming support for
|
6 |
+
one option over another, your evaluation should score differently from a close match).
|
7 |
+
|
8 |
+
The first and second images in the "images" field are the top and secondary images. You should shuffle them before evaluating. <br/>
|
9 |
+
If there is overwhelming support for the top choice, the second choice will be arbitrary and given 1 vote.
|
10 |
+
|
11 |
+
## Standards and Practices
|
12 |
+
|
13 |
+
### Rules of the Road
|
14 |
+
|
15 |
+
- This should only evaluate posts with Male, Female, or Nonbinary Advice flair (no unsolicited advice)
|
16 |
+
- Remove posts from the dataset if the image, user, or post is deleted
|
17 |
+
- Do not post or comment on the subreddit
|
18 |
+
- Do not upload the images separately from Reddit
|
19 |
+
|
20 |
+
### Technical Details
|
21 |
+
|
22 |
+
- Only pick posts which select between multiple outfits (not freeform advice, shoes, etc)
|
23 |
+
- Limited string replace support for first, second, third, last, etc.
|
24 |
+
- A top comment which mentions multiple outfits is not parseable, so the post is not parseable
|
25 |
+
- This assumes that a comment supports the outfit which they mentioned
|
26 |
+
- This assumes that the user posted one image per outfit (i.e. outfit 3 = third image)
|
27 |
+
- If there is overwhelming support for the top choice, the second choice will be arbitrary and given 1 vote.
|
28 |
+
|
29 |
+
## Code
|
30 |
+
|
31 |
+
Python script preparing /r/OUTFITS posts for a multimodal evaluation: scraper.py
|
32 |
+
|
33 |
+
### Dependencies
|
34 |
+
|
35 |
+
Requires a Reddit app_id, secret, and user_agent saved in `.env` in JSON format. See https://praw.readthedocs.io/en/stable/getting_started/quick_start.html
|
36 |
+
|
37 |
+
Pip install:
|
38 |
+
- praw
|
dataset.csv
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
post_id,gender_flair,title,selftext,images,firstChoiceVotes,secondChoice
|
2 |
+
1m7t7m3,M,Which outfit translates who I am the most?,Need some advice on my style and what to do to take it to the next level,"https://preview.redd.it/vha2f75omqef1.jpg?width=1152&format=pjpg&auto=webp&s=0be961938f64c2a93b0908c7ceab929687ddc0ef,https://preview.redd.it/r5w6wp5omqef1.jpg?width=1152&format=pjpg&auto=webp&s=1fb970b3efba6ea3962a57963157c9d417acbf27,https://preview.redd.it/2ai7ka6omqef1.jpg?width=3060&format=pjpg&auto=webp&s=1213725f563ea6414907abddee965ad6fe3f57a1,https://preview.redd.it/6nasl67omqef1.jpg?width=1080&format=pjpg&auto=webp&s=bef426fcb7d707506899ec6712f073e95da5a17c",17,14
|
3 |
+
1m42jjy,M,Going to a concert. Which one looks better?,I’m still learning to dress better. Please be nice. ,"https://preview.redd.it/0qp2rsvkdvdf1.jpg?width=3024&format=pjpg&auto=webp&s=b3bcce5ee2dc8abeb312d1e167da5b8ddd1c827b,https://preview.redd.it/m9gh6tvkdvdf1.jpg?width=3024&format=pjpg&auto=webp&s=7ab5f371ac8bb871a5eaa68b7fc09fd1677a3e81,https://preview.redd.it/6qovckvkdvdf1.jpg?width=3024&format=pjpg&auto=webp&s=352c55e9a263fbf7d6d12c7495c6a2c534b8ffcb",770,1
|
4 |
+
1m9vff2,F,Birthday night out outfit for over 40°C (105°F),"Please help me pick one of these, I need to go out in a couple of hours. Also, I would really appreciate any suggestions on how to accessorize them. When wearing dresses I don't usuallt do anything extra with the outfit, especially when it's this warm outside.
|
5 |
+
|
6 |
+
I'm leaning towards the blue one, I think it looks a lot better in person and the material feels nice.
|
7 |
+
|
8 |
+
The last time I went out on my birthday was over 10 years ago, so I might be overthinking this","https://preview.redd.it/upbxjwhgg8ff1.jpg?width=1838&format=pjpg&auto=webp&s=44239f75ab57ce97b95a02fe0c463b5cc2648f15,https://preview.redd.it/b90krxbgg8ff1.jpg?width=2092&format=pjpg&auto=webp&s=fe7a0e7caeffd677d26238ae829def447e6aa85d,https://preview.redd.it/76audxufg8ff1.jpg?width=1604&format=pjpg&auto=webp&s=f1ddc5bad185e116192e5145efc47071f80603fe,https://preview.redd.it/r6thf64gg8ff1.jpg?width=2006&format=pjpg&auto=webp&s=e8bddb5a3d91936bcf3c828490b49516275cc833",21,19
|
9 |
+
1m99giq,F,"Used to live in black, now I’m embracing color. Which one works best?",All summer outfits ,"https://preview.redd.it/ujs3myelu2ff1.jpg?width=1284&format=pjpg&auto=webp&s=a996d416c0ef2890ada32e81b1c0e6bd56965bf4,https://preview.redd.it/nnpie0glu2ff1.jpg?width=895&format=pjpg&auto=webp&s=ae738d2f212f8f341b232856b75e366091d42cd7,https://preview.redd.it/r2dol8flu2ff1.jpg?width=2247&format=pjpg&auto=webp&s=0383f99f58d8ea9ba96fd4d492ac46dc0b52ee2c,https://preview.redd.it/sr9vt0glu2ff1.jpg?width=1284&format=pjpg&auto=webp&s=02e2e7e080fff0e170c92267f9000a7d67eeb636",17,11
|
10 |
+
1m8bbal,F,Help which skirt looks better," the maxi one make me look thinner but it it is too heavy
|
11 |
+
The draped one is more fun but I feel it make me look short ",https://preview.redd.it/90aufgmo1vef1.jpg?width=905&format=pjpg&auto=webp&s=e31e15c72e4348e89e4c2dcb2952ad0fc85c084a,202,1
|
12 |
+
1m6tbon,F,Tomorrow night there's a themed BYOB by the water! Which one?,"Okay, so the first picture is my normal style. Like casual but cute? Idek. Lol. Tomorrow night my friends and I are going to a down by the water themed tropical/floral painting night. They always dress super cute and I'm more comfortable in casual outfits but, want to try. Which one 😬 I'm not into fashion at all! ","https://preview.redd.it/leshndafdief1.jpg?width=1250&format=pjpg&auto=webp&s=b7b025c09872c33f5b82ffa98335e58f6354330d,https://preview.redd.it/cuwmwacfdief1.jpg?width=1137&format=pjpg&auto=webp&s=5e567c7c247e9017b9fe7518391aa111d98842b8,https://preview.redd.it/snmqh76fdief1.jpg?width=819&format=pjpg&auto=webp&s=00c8a01b184458150b1a46ed56ca88a67fcfdf75,https://preview.redd.it/l9okfcvedief1.jpg?width=1001&format=pjpg&auto=webp&s=a8ad9dd077032cbf7f72876e43c6c34fc9303559",59,51
|
13 |
+
1m6gp2q,F,Outfit Help?!?!,Please help. I cannot figure out what to wear to a get together tomorrow. I’m very insecure about my body and feel like I look gross in everything. We’re going to a casual bar in an urban suburb for context. Please ignore my unmade bed lol. I have another outfit that I’m thinking and just haven’t taken a picture of myself in it. It’s like pink shorts with a black top. TIA. Please be nice 💕,"https://preview.redd.it/3o7tmv42zfef1.jpg?width=1576&format=pjpg&auto=webp&s=2446126483ada4afa8d221cabb6c7e5d17e52e12,https://preview.redd.it/k559mw42zfef1.jpg?width=1576&format=pjpg&auto=webp&s=95e497f59e223f823a90df448cca20140d4c865a,https://preview.redd.it/l9fxyu42zfef1.jpg?width=1576&format=pjpg&auto=webp&s=c7c18c161ebd09c59958f8a7119883a220d48e6e,https://preview.redd.it/905juv42zfef1.jpg?width=1576&format=pjpg&auto=webp&s=7412efcbfe38ffdd69dd3e45070be009fd142c39",7,4
|
14 |
+
1m5z07q,F,Birthday Brunch Fit…What are we feeling?,"Sweet, Sporty, or a little Sultry perhaps? ","https://preview.redd.it/ud8u1n3qebef1.jpg?width=3024&format=pjpg&auto=webp&s=8cab062a702472b135478eb0f49a946c68e9d7e7,https://preview.redd.it/iem1vk3qebef1.jpg?width=3024&format=pjpg&auto=webp&s=f3d7cb079e2cce883d3fc3aedee6ee45fc5cfd96,https://preview.redd.it/c23h8n3qebef1.jpg?width=3024&format=pjpg&auto=webp&s=386e1fdb74ea6212f3091380e4e7050a226cef89",80,59
|
scraper.py
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import csv
|
2 |
+
import json
|
3 |
+
import os
|
4 |
+
import praw
|
5 |
+
import random
|
6 |
+
import re
|
7 |
+
import sys
|
8 |
+
|
9 |
+
env = json.load(open('.env', 'r'))
|
10 |
+
#print(env)
|
11 |
+
|
12 |
+
reddit = praw.Reddit(
|
13 |
+
client_id=env["app_id"],
|
14 |
+
client_secret=env["secret"],
|
15 |
+
user_agent=env["user_agent"]
|
16 |
+
)
|
17 |
+
|
18 |
+
def main(post_id):
|
19 |
+
post = reddit.submission(id=post_id)
|
20 |
+
post.comments.replace_more(limit=0)
|
21 |
+
sorted_comments = sorted(post.comments, key=lambda c: c.score, reverse=True)
|
22 |
+
|
23 |
+
if post.link_flair_text is None:
|
24 |
+
raise Exception("Must be a gender or non-binary fashion flair post")
|
25 |
+
elif "Men's" in post.link_flair_text:
|
26 |
+
gender = "M"
|
27 |
+
elif "Women's" in post.link_flair_text:
|
28 |
+
gender = "F"
|
29 |
+
elif "Non Binary" in post.link_flair_text:
|
30 |
+
gender = "X"
|
31 |
+
else:
|
32 |
+
raise Exception("Must be a gender or non-binary fashion flair post")
|
33 |
+
|
34 |
+
data = {
|
35 |
+
"post_id": post_id,
|
36 |
+
"gender_flair": gender,
|
37 |
+
"title": post.title,
|
38 |
+
"selftext": post.selftext,
|
39 |
+
"images": [],
|
40 |
+
}
|
41 |
+
|
42 |
+
image_urls = []
|
43 |
+
if post.is_gallery:
|
44 |
+
metadata = post.media_metadata
|
45 |
+
for item in post.gallery_data['items']:
|
46 |
+
url = metadata[item['media_id']]['s']['u'].replace("&", "&")
|
47 |
+
image_urls.append(url)
|
48 |
+
else:
|
49 |
+
raise Exception("Need multiple images for there to be a multimodal eval question")
|
50 |
+
|
51 |
+
lead_choices = {}
|
52 |
+
firstChoice = None
|
53 |
+
secondChoice = None
|
54 |
+
for c in sorted_comments:
|
55 |
+
text = c.body.strip().lower().replace('first', '1st').replace('second', '2nd').replace('third', '3rd').replace('fourth', '4th').replace('fifth', '5th')
|
56 |
+
text = text.replace('last', str(len(image_urls)))
|
57 |
+
selections = re.findall(r'\d', text)
|
58 |
+
if len(selections) == 0:
|
59 |
+
print("Skipped comment without digit")
|
60 |
+
continue
|
61 |
+
elif len(set(selections)) > 1:
|
62 |
+
print(text)
|
63 |
+
raise Exception("Encountered a top comment with multiple digits, complex")
|
64 |
+
selection = int(selections[0])
|
65 |
+
if selection not in lead_choices:
|
66 |
+
print(f"Found comment with {c.score} votes: {text}")
|
67 |
+
lead_choices[selection] = c.score
|
68 |
+
data["images"].append(image_urls[selection - 1])
|
69 |
+
if firstChoice is None:
|
70 |
+
firstChoice = selection
|
71 |
+
elif secondChoice is None:
|
72 |
+
secondChoice = selection
|
73 |
+
break
|
74 |
+
else:
|
75 |
+
print(f"Found repeat comment with {c.score} votes")
|
76 |
+
lead_choices[selection] += c.score
|
77 |
+
if lead_choices[selection] > 100:
|
78 |
+
print("Overwhelming support")
|
79 |
+
if selection == 1:
|
80 |
+
secondChoice = 2
|
81 |
+
else:
|
82 |
+
secondChoice = selection - 1
|
83 |
+
lead_choices[secondChoice] = 1
|
84 |
+
break
|
85 |
+
if len(lead_choices.keys()) != 2:
|
86 |
+
raise Exception("Did not find two distinct comments with single outfit suggestions")
|
87 |
+
|
88 |
+
data["firstChoiceVotes"] = lead_choices[firstChoice]
|
89 |
+
data["secondChoice"] = lead_choices[secondChoice]
|
90 |
+
if len(image_urls) > 2:
|
91 |
+
print("We are assuming that there is one image of each outfit")
|
92 |
+
used_set = set(image_urls)
|
93 |
+
remaining = [img for img in used_set if img not in data["images"]]
|
94 |
+
extra_images = random.sample(remaining, min(len(remaining), 2))
|
95 |
+
data["images"] += extra_images
|
96 |
+
|
97 |
+
# print(json.dumps(data, indent=2))
|
98 |
+
fieldnames = [
|
99 |
+
"post_id",
|
100 |
+
"gender_flair",
|
101 |
+
"title",
|
102 |
+
"selftext",
|
103 |
+
"images",
|
104 |
+
"firstChoiceVotes",
|
105 |
+
"secondChoice"
|
106 |
+
]
|
107 |
+
|
108 |
+
filename = "dataset.csv"
|
109 |
+
file_exists = os.path.isfile(filename)
|
110 |
+
with open(filename, mode="a", newline="", encoding="utf-8") as f:
|
111 |
+
writer = csv.DictWriter(f, fieldnames=fieldnames)
|
112 |
+
if not file_exists:
|
113 |
+
writer.writeheader()
|
114 |
+
row = data.copy()
|
115 |
+
row["images"] = ",".join(data["images"])
|
116 |
+
writer.writerow(row)
|
117 |
+
|
118 |
+
|
119 |
+
if __name__ == "__main__":
|
120 |
+
if len(sys.argv) != 2:
|
121 |
+
print("Usage: python outfit_scraper.py <reddit_post_id>")
|
122 |
+
sys.exit(1)
|
123 |
+
main(sys.argv[1])
|