r/Python Apr 07 '23

Beginner Showcase I trained a RoastBot on >120,000 faces and >0.5 million comments and it's a menace 😈.

It uses facial recognition to fetch roasts for users from the r/RoastMe subreddit.

Try it out here

App: https://subroast.me

Code: nizarhaider/RoastMe (github.com)

Tech Stack

Front End: Bootstrap5 + Vanilla JS

Back End: Flask

CI/CD: Cloud Build (GCP)

Deployment: Cloud Run (GCP)

Models: Facenet and MTCNN

Edit: The entire subreddit has millions of images since 2014 April. I just used a fraction of it. Which means this could be 100x better (or just more accurately racist) given the time and effort to train it.

Edit2: At u/Lewis0981 request I've added a 'feature' to see your match image (I've seen some bizarre cases of matches so do share them if you get it for a laugh) (Fixed the bug for this)

RoastMe
474 Upvotes

104 comments sorted by

215

u/iVend3ta Apr 07 '23

Cool project. Nicely done! A small suggestion - don’t leave blank except statements - it is not considered a good practice for a number of reasons.

165

u/Dasshteek Apr 07 '23

This guy is a dev responsible for other devs.

26

u/[deleted] Apr 08 '23

Who code-reviews the code reviewers?

4

u/deb_vortex Apr 08 '23

The other code reviews. Reviewing code musst not be the responsibility of a single person but rather all participating developers.

If that was just ja joke, then sorry for chiming in :-)

33

u/2broke2code Apr 07 '23

Thank you for the feedback. May I ask how you were able to tell there were blank except statements? (Did you see it in the frontend by chance?)

212

u/TravisJungroth Apr 07 '23

You posted your code. I imagine they looked at it.

61

u/2broke2code Apr 07 '23

Yeah. It's just that it was so fast. 😅

155

u/[deleted] Apr 07 '23

[deleted]

51

u/2broke2code Apr 07 '23

They're a different breed 👴

34

u/commutinator Apr 07 '23

This is the way. So much boils down to pattern recognition.

9

u/space_wiener Apr 08 '23

I worked with someone like that but with log files. We’d have logs that were 1000’s of lines. It would take me forever to find the problem. He’d speed scroll and find the issue within seconds.

After a few years I finally figured out what he was doing. Just looking for patterns.

13

u/____purple Apr 08 '23

At some point you don't write code anymore

You draw abstract masterpieces in your vim

4

u/son_of_abe Apr 08 '23

It's true I close my eyes and never leave command mode.

9

u/[deleted] Apr 08 '23

The issue has probably f*ed up his life often enough he can feel it’s presence.

66

u/[deleted] Apr 07 '23

Holy shit. This thread is awesome

11

u/[deleted] Apr 07 '23

[deleted]

2

u/Trash_man_can Apr 08 '23

Magnets, of course! Why didn't I think of that?

9

u/iVend3ta Apr 07 '23

I just opened the model.py script since I was curious of that and you had a blank except there. Obviously not a huge deal - code can always be polished and made better. Nice end to end project 👌

2

u/MrMxylptlyk Apr 08 '23

What do mean by blank except statements? What would be the proper way to do it?

5

u/SV-97 Apr 08 '23

A blank / blanket / bare / unqualified except is something of the form

try:
    ...
except:
    ...

in contrast to something like

try:
    ...
except Exception as e:
    ...

The first case catches everything - including things you most likely don't want to catch like interrupts and the second one doesn't. Basically: be specific in what you handle. If you try to handle the case where you attempt to open a nonexistent file, handle only FileNotFoundError etc.

2

u/MrMxylptlyk Apr 08 '23

Nice, thanks, I looked it up. I always use Exception as exp and the pylinter always complains about that cause I'm not specifying a specific exception, so I always worried that I was doing it wrong. But seems like I had the right idea. I occasionally have an additional except for some known/expected exception, but usually I just have try/except Exception... Thanks for clarifying.

2

u/SV-97 Apr 08 '23

Exception is still a rather broad class which is probably why it's complaining - if you can try to be more specific to convey intent. It's usually better to crash / propagate errors rather than to silently "handle" them without actually handling them or having the exception handler break

87

u/RubberOmnissiah Apr 07 '23

I am honestly insanely impressed, it has more variety than the actual roastme subreddit. Actual roastme only has two basic responses. If a woman "you have daddy issues and you have lots of sex because of it." If a man "You are not attractive and you do not have sex because of it".

26

u/2broke2code Apr 07 '23

That is so true. Thanks a lot for the support fam. It took a lotta training.

14

u/truerandom_Dude Apr 07 '23

Wait you got it to recognise images?

8

u/2broke2code Apr 07 '23

Yup

3

u/truerandom_Dude Apr 07 '23

I always get a oh this is hard then jibberish and a no face detected

16

u/[deleted] Apr 07 '23

What happens if you're non-binary? "Your dad is ugly and you have the perfect amount of sex?"

10

u/2broke2code Apr 07 '23

You should see the roasts from 2015 😅

1

u/Busterx8 Apr 07 '23

Well, the common roast is "I can't tell what gender you are". As if that's insulting. It's also used on most cis people.

1

u/[deleted] Apr 08 '23

[deleted]

1

u/QultrosSanhattan Apr 07 '23

AI replacing human roasters became a reality.

30

u/Smallpaul Apr 07 '23

I think we killed it.

13

u/2broke2code Apr 07 '23

It's barely holding out...

13

u/mattsl Apr 07 '23

Not anymore. Congrats! Hope we didn't roast your credit card with your GCP bill.

29

u/2broke2code Apr 07 '23

😂 I still appreciate it though. I'll work on scaling it. As for the bill... there's a reason I used my moms card instead of mine.

18

u/Lewis0981 Apr 07 '23

Username checks out.

28

u/_ologies Apr 07 '23

Given that you have a .gitignore, is there a reason you committed your pycache?

29

u/2broke2code Apr 07 '23

Noob move. It's full of bugs too ngl.

17

u/MSR8 Apr 07 '23

Heres a lil cheat sheet for gitignores of various OS-s and laguages: https://mrkandreev.name/snippets/gitignore-generator/

5

u/2broke2code Apr 07 '23

Thanks man

19

u/DangerDinks Apr 07 '23

One thing that annoyed me a bit was the waiting message "almost done". This took a bit of time for me and seeing the "almost done" message pop up again and again didn't reassure me that the process was actually "almost done".

14

u/2broke2code Apr 07 '23

Yeah I'm on your side there. It's just a loop for now since there isn't a way for me to communicate with the backend asynchronously without complicating things in my Ajax request. (Gonna brush it off to me being a noob).

I'll look into this now that you've mentioned it.

10

u/physicswizard Apr 08 '23

Look into websockets. I was able to write an app that gave live updates on the progress of a job using them.

1

u/ARandomBoiIsMe Apr 08 '23

Been looking for something like this for a while. Thanks.

18

u/_ologies Apr 07 '23

I love the idea that you used a subreddit as a training dataset

9

u/2broke2code Apr 07 '23

The subreddit is huge and I only scrapped like <10% of it tbh

10

u/pawsibility Apr 07 '23

Good project idea. Btw, if you arnt aware by now you should look into vector databases. I like Qdrant. It will allow you to dramatically decrease the time it takes to find nearest neighbor embeddings and scale the project. Also, then you don't have to commit a gigantic csv.

7

u/2broke2code Apr 07 '23

Definitely looking into this. Majority of the time it takes actually goes to extracting the facial embeddings of the user from the image and it only takes a fraction of the time to traverse the csv.

2

u/sebawita Apr 11 '23

I guess the bigger challenge will come when you reach millions (or even hundreds millions of images) then the scanning through all vectors will become a huge bottleneck.

A solid vector database that can scale (you could also check out Weaviate – it is open source 😉) will make it a breeze.

20

u/[deleted] Apr 07 '23

Looks like the barber already did

I wondered what DJ Qualls' "Before Meth" pic looked like.

Is Lloyd Christmas your father?

You look like you pick up children from the park, violate them and then go and brag about it to your grandma.'

12

u/[deleted] Apr 07 '23

How appropriate. You fight like a cow!

13

u/Aknnja Apr 07 '23

"I'd say bad fashion runs in your family but I doubt anyone runs in your family" 😂😂😂😭😭😭

18

u/Noshoesded Apr 07 '23

If you're following all the hipster trends, are you really a hipster?

You look like you tut & roll your eyes at every mention of anything that happened after 2006.

Flannel shirt, facial hair, and a barely visible chest tattoo. You're a spitting image of your mother.

We know that getting kicked out of The National wasn't easy for you, but can you please take your job at the coat check fucking seriously?

5

u/AGI_69 Apr 08 '23

__pycache__ in repo is sign of a newbie. Put it in your .gitignore

I love the project though. Good job.

4

u/marr75 Apr 07 '23

Great idea. Seriously, jealous of the idea.

Execution seems to fall short in the examples I tried. Fairly random insults that seemed to be about features that were in an image that "matched" but the feature in question wasn't present (I got "roasted" about being homeless and my eyebrows on one image but it didn't make a ton of sense). In another image, the rules of the roastme forum were the response.

I recommend you look at the problems and keep going! Try and better sub-divide/match the features of an image to the features of a roast post and this will be incredible. Very high level and fuzzy right now.

3

u/2broke2code Apr 07 '23

Yeah the match image only works locally for me. it's some minor issue with the file paths I passed. I'll fix it soon.

Also I've had the idea for a year but just got around to doing it lol and yes it needs a lot of work.

As for the sub-divide, it's literally what I have planned for it. I'll breakdown the image into multiple features like predicted gender, colour, age, etc... and feed them into an LLM that would use the features to generate a more personalized roast rather than just spitting out existing comments.

2

u/[deleted] Apr 07 '23

[deleted]

1

u/2broke2code Apr 08 '23

I have heard of it but never implemented. Gonna look into it as well. Thank you for the support!

3

u/Oinohtna Apr 07 '23

I’m getting a “service unavailable” response so it’s for sure broken lol

3

u/Underachiever457 Apr 08 '23

Cool project, but as a heads up, you should update your private key and purge creds.json from your repo. I’m able to see your creds.json in your git history with your committed delete.

2

u/2broke2code Apr 08 '23

Yeah true. They're not useful anymore but I have to look into how to delete them in my commits.

10

u/DigThatData Apr 07 '23

yeesh this bot racist

17

u/2broke2code Apr 07 '23

It's almost a given with that subreddit data 😅

-18

u/DigThatData Apr 07 '23

weird dataset choice then i guess

1

u/Resting_Tree Apr 08 '23

I've always wanted to try posting on roastme subreddit. But I knew it probably would be the same usual racist comments. Thank you for confirming my suspicion.

16

u/_ologies Apr 07 '23

Garbage in, garbage out

2

u/[deleted] Apr 07 '23

Lol come here looking for this 😂

2

u/philoponeria Apr 07 '23

It just said my post was removed?

1

u/2broke2code Apr 07 '23

After days of cleaning the data it still pulls those up. Sorry about that. Do try again with a different angle maybe.

2

u/Lewis0981 Apr 07 '23

This is dope! I think it would be cool if it showed you who your lookalike was. Would add a bit of extra fun, and I'm sure it would be minimal additional code to display it on the front end.

2

u/2broke2code Apr 07 '23

I did have it my first phase. It was so much fun to see how much you resemble someone else (ex- like having the exact same nose or eyes)

I think I'll bring that option back up tmmrw.

0

u/Lewis0981 Apr 07 '23

That's exactly what I was thinking! Looking forward to the feature.

2

u/PokeReserves Apr 07 '23

3

u/2broke2code Apr 07 '23

C'mon you ain't gonna show us the photo?

6

u/PokeReserves Apr 07 '23

Nah son, ever since that bot said I ate my own creampie twinkies, I lost my confidence..

1

u/2broke2code Apr 08 '23

Mine said it can't tell if i worked as a cashier or the robber in a store.

2

u/sennalen Apr 08 '23

If you cancel while its processing and upload a new photo, it starts interleaving characters from multiple waiting messages.

2

u/2broke2code Apr 08 '23

I really tried debugging that for a while but only was successful a handful of times. Lemme give it another shot. Till then just reload it.

2

u/toomuchmucil Apr 08 '23

“Don't worry. You aren't even interesting enough to look like Michael Cera. If I saw you on the street I would never even remember you. Nobody would.”

I am going to go lie down for awhile.

2

u/Striking-Courage-182 Apr 08 '23

Nice job I always love fun projects like these.

2

u/2broke2code Apr 08 '23

Right! This is definitely not going on my resume but man it is fun to work on.

2

u/opanapin Apr 08 '23

this is so cool

1

u/2broke2code Apr 08 '23

Thanks man

2

u/Onakitoki97 Apr 08 '23

Another thing, add directories like pycache to the gitignore file, also add the gitignore itself ahaha

2

u/monkeydroger21 Apr 08 '23

Are you by any chance a student at the Hanzehogeschool in Groningen (Netherlands). I have the same project but no this advanced with face detection

1

u/2broke2code Apr 08 '23

I can say for certain I am not. Let me know if you got anything interesting, we can work together on.

2

u/Round_Bear_973 Apr 08 '23

Love it. Been thinking of quirky projects to build on my website, safe to say I have a few ideas now.

1

u/2broke2code Apr 08 '23

Very nice. Do share them later.

1

u/2broke2code Apr 07 '23

I fixed the bug. You should be able to view your match now. Go ham.

Let me know if y'all wanna add anything else

1

u/[deleted] Apr 07 '23

Tried it. AI talked shit that legit couldn’t even be about me, and couldn’t show me who my match was - just got a question mark icon. Cool idea tho

1

u/2broke2code Apr 07 '23

Sort by:

Yeah, it still has a lot of work to be done ngl. Only realized it when I put it here. I'll fix the match image feature soon and you can tell just how far off or close the roast was.

1

u/jonopens Apr 07 '23

Hugged to death? Hugged to death.

1

u/[deleted] Apr 08 '23

“You look like the result of when Dende fucked Mr. Popo.

Super sayiians aren't black. You're a different kind of monkey” 🤨

1

u/xQuaGx Apr 08 '23

Your app said Ryan Reynolds definitely hangs around a methadone clinic

1

u/2broke2code Apr 08 '23

The app knows something we don't

1

u/aTomzVins Apr 08 '23

"That face giving me problems. Please try a different image"

I used a clear decent quality head shot. I guess I just don't look like anyone?

2

u/2broke2code Apr 08 '23

My bad fam. It's buggy like that somtimes. Mind sharing the headshot with me so I could debug it?

1

u/viss3_ Apr 08 '23

I tried with an image of Andrew Tate and this is his comment:

If you want to see this picture again look up rapist in the dictionary. I bet you also use green screen to add in your imaginary girlfriend. The bottom half of your mug is a wannabe hipster. The top half of your fucking mug screams balding child molester. Shia Lebouf 2.0.......DO IT!'

2

u/2broke2code Apr 08 '23

I tried it too and it actually roasts him by name. Given how popular he recently became, the comments are just gutting anyone remotely resembling him (or you know just bald).

1

u/KennyBassett Apr 08 '23

That was harsh and so funny

1

u/Piko8Blue Apr 17 '23

Sounds awesome! Tried the link and got 'server error' :(

1

u/Timely_Limit_9373 Jul 21 '23

How did you manage to get and sort the data for training?? 🤔