VasudevaK commited on
Commit
5397177
1 Parent(s): 3e11b23

tuned better

Browse files
Files changed (3) hide show
  1. app.py +39 -9
  2. corpus.txt +100 -0
  3. requirements.txt +0 -1
app.py CHANGED
@@ -7,6 +7,9 @@ from sklearn.metrics.pairwise import cosine_similarity
7
 
8
  import nltk
9
  nltk.download('all')
 
 
 
10
 
11
  # import fastai
12
 
@@ -29,7 +32,7 @@ def get_best(input):
29
  max_idx = idx
30
  max_similarity = sim
31
  if(np.sum(max_similarity) != -1):
32
- return jokes[max_idx]
33
  else:
34
  return None
35
 
@@ -64,19 +67,46 @@ def pattern(input):
64
  else:
65
  return response+'??😁🤣'
66
 
67
-
68
- def GPT(input):
69
- return None
70
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
 
72
  def generator(input=None):
73
  response = []
74
  if input:
75
 
76
- out1 = GPT(input)
77
  if(out1):
78
- for out in out1:
79
- response.append(out)
80
 
81
  out2 = pattern(input)
82
  if(out2):
@@ -87,7 +117,7 @@ def generator(input=None):
87
  response.append(out3)
88
 
89
  else:
90
- out1 = GPT("Hi, what's the matter")
91
  if(out1):
92
  for out in out1:
93
  response.append(out)
 
7
 
8
  import nltk
9
  nltk.download('all')
10
+ import string
11
+ from sklearn.feature_extraction.text import TfidfVectorizer
12
+ from sklearn.metrics.pairwise import cosine_similarity
13
 
14
  # import fastai
15
 
 
32
  max_idx = idx
33
  max_similarity = sim
34
  if(np.sum(max_similarity) != -1):
35
+ return jokes[max_idx]+'😁🤣'
36
  else:
37
  return None
38
 
 
67
  else:
68
  return response+'??😁🤣'
69
 
70
+ lemmer = nltk.stem.WordNetLemmatizer()
71
+ def LemTokens(tokens):
72
+ return [lemmer.lemmatize(token) for token in tokens]
73
+
74
+ remove_punct_dict= dict((ord(punct), None) for punct in string.punctuation)
75
+ def LemNormalize(text):
76
+ return LemTokens(nltk.word_tokenize(text.lower().translate(remove_punct_dict)))
77
+
78
+ def NLTK(input):
79
+ f = open('corpus.txt', errors='strict')
80
+ data = f.read()
81
+ data = data.lower()
82
+ nltk.download('punkt')
83
+ nltk.download('wordnet')
84
+ sent_tokens = nltk.sent_tokenize(data)
85
+ return bot(input, sent_tokens)
86
+
87
+ def bot(sent_tokens):
88
+ robo1_response = ''
89
+ TfidfVec = TfidfVectorizer(tokenizer = LemNormalize, stop_words='english')
90
+ tfidf = TfidfVec.fit_transform(sent_tokens)
91
+ vals = cosine_similarity(tfidf[-1], tfidf)
92
+ idx = vals.argsort()[0][-2]
93
+ flat = vals.flatten()
94
+ flat.sort()
95
+ req_tfidf = flat[-2]
96
+ if (req_tfidf == 0):
97
+ robo1_response= robo1_response+"I could not answer this right now but you can contact the head of our dept (PUSPHA RAJ)." # add the dept recommendation engine and contact details
98
+ return robo1_response
99
+ else:
100
+ robo1_response = robo1_response+sent_tokens[idx]
101
+ return robo1_response
102
 
103
  def generator(input=None):
104
  response = []
105
  if input:
106
 
107
+ out1 = NLTK(input)
108
  if(out1):
109
+ response.append(out)
 
110
 
111
  out2 = pattern(input)
112
  if(out2):
 
117
  response.append(out3)
118
 
119
  else:
120
+ out1 = NLTK("Hi, what's the matter")
121
  if(out1):
122
  for out in out1:
123
  response.append(out)
corpus.txt ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [me narrating a documentary about narrators] ""I can't hear what they're saying cuz I'm talking""
2
+ Telling my daughter garlic is good for you. Good immune system and keeps pests away. Ticks, mosquitos, vampires... men.
3
+ I've been going through a really rough period at work this week It's my own fault for swapping my tampax for sand paper.
4
+ If I could have dinner with anyone, dead or alive... ...I would choose alive. -B.J. Novak-
5
+ Two guys walk into a bar. The third guy ducks.
6
+ Why can't Barbie get pregnant? Because Ken comes in a different box. Heyooooooo
7
+ Why was the musician arrested? He got in treble.
8
+ Did you hear about the guy who blew his entire lottery winnings on a limousine? He had nothing left to chauffeur it.
9
+ What do you do if a bird shits on your car? Don't ask her out again.
10
+ He was a real gentlemen and always opened the fridge door for me
11
+ Telling my daugthers date that ""she has lice and its very contagious the closer you get to her."" *Correct way to parent.
12
+ What should you do before criticizing Pac-Man? WAKA WAKA WAKA mile in his shoes
13
+ What's the difference between an illegal Mexican and an autonomous robot...? Nothing... they were both made to steal American jobs.
14
+ What do you call a barbarian you can't see? an Invisigoth.
15
+ How do you spell Canda? C,eh,N,eh,D,eh
16
+ You ever notice that the most dangerous thing about marijuana is getting caught with it?
17
+ What did Arnold Schwarzenegger say at the abortion clinic? Hasta last vista, baby.
18
+ My wife is in a bad mood. I think her boyfriend forgot their anniversary. Way to go, dude. Now we all suffer...
19
+ My speech today will be like a mini-skirt. Long enough to cover the essentials but short enough to hold your attention!
20
+ Thanksgiving joke What does Miley Cyrus eat for Thanksgiving? Twerky! Just kidding... Drugs. She eats drugs. -Adam Zopf @adamzopf
21
+ Why do you never see elephants hiding in trees? 'Cause they are freaking good at it
22
+ How did the blonde die raking leaves? She fell out of the tree.
23
+ ""That guy is such a douche-bag! Is he single? Maybe I can fix him!"" women
24
+ My son just got a tattoo of a heart, a spade, a club, and a diamond, all without my permission. I guess I'll deal with him later.
25
+ What do you call a potato in space? Spudnik
26
+ How to get a cop's attention
27
+ What happens to a necrophiliac after death? Reserection
28
+ Why did the chicken hold a seance? To get to the other side.
29
+ Where do baby cows go to eat lunch? At the calf-eteria.
30
+ What's the difference between a painting and Jesus. You only require one nail to put up the painting.
31
+ Mom: ""Do you want this?"" Me: ""No."" Mom: ""Ok I'll give it to your brother."" Me: ""No I want it.""
32
+ How do you fit 4 gays on one barstool? Flip it over!
33
+ I am looking forward to 6pm Thanksgiving Day when Walmart opens its doors for its annual sale of trampled human corpses.
34
+ Yttrium-barium-copper oxide walks into a bar The bartender tells him, ""We don't serve superconductors here."" He leaves without resistance.
35
+ A guy pick up a woman Then he puts her down
36
+ Every night, I take all of the singles out of my wallet, spread them on the bed, and pretend I was pretty that day.
37
+ Which gospel contains Jesus' parable about the shades of numbers? Math hue.
38
+ Ibuprofen is my favorite headache medicine that also sounds like a reggae professor.
39
+ Ted Cruz getting elected.
40
+ Before I destroy a wasp's nest I like to capture a single wasp and tell it my entire diabolical plan.
41
+ What's Al-Qaeda's favorite American football team? The New York jets.
42
+ INTERVIEWER: Why do you want to work here? ME: *crumbs tumbling from my mouth* Oh, I don't. I was just walking by and saw you had donuts.
43
+ Coming on valentines day. Fifty shades of grey. There won't be a dry seat in the cinema.
44
+ Did you hear about the midget psychic who escaped from prison? He's a small medium at large.
45
+ Someone didnt click the button in /r/thebutton Yeah... Thats a good joke , he impossible!
46
+ What's the difference between a car tyre, and 365 condoms? One's a Goodyear, an the other's a great year.
47
+ Roses are red, Violets are blue. I have a gun. Get in the van.
48
+ I've struggled for years to be above the influence... But I've never been able to get that high
49
+ With Facebook, you can stay in touch with people you would otherwise never talk to, but that's only one of the many awful things about it
50
+ What's the difference between a blonde and a washer? When you dump your load in a washer, it doesn't follow you around for a week.
51
+ Have you ever heard of the movie ""Constipation""? No? Most likely because it never came out.
52
+ What's black, blue and doesn't look too well? Stevie Wonder
53
+ I saw a French rifle on eBay today It's never been fired but I heard it was dropped once.
54
+ What did the car said to the valet? I've been through a lot.
55
+ Bill Clinton must be the luckiest man in the world. All of the sex he has, with Hillary, you know it's hate sex.
56
+ yeah girl.. shake that thing where poop comes out of. it really turns me on when your poop factory shakes faster than usual
57
+ ""I can't stand when people say they hate both of the presidential candidates."" --Stephen Hawking
58
+ A Mexican fireman had twin boys He named them Jose and Hose B
59
+ I was drinking at the bar, so I took a bus home. That may not be a big deal to you, but I've never driven a bus before!
60
+ Donald Trump will ban the sale of shredded cheese He wants to make America grate again
61
+ Things have really turned around for me since I re-named my penis and testicles ""JD Power and Associates"".
62
+ My sex face is the same as my first pee in three hours face.
63
+ My cat just walked by me carrying a toy mouse I don't remember buying her. Women be shoppin!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
64
+ Why did the Xbox owner cross the road? To fuck your mom.
65
+ Sometimes you check the amount of subscribed people. When you do this, there are 4,111,093,0003.666 ""humorists"". 2/3rds of a person? Really?
66
+ I don't believe in Bigfoot; because he never believed in me. I'd scan the crowd at my ballet recitals, and always see that one empty seat.
67
+ What did the porn actress say when she opened the door? Make sure to come upstairs.
68
+ I don't judge people based on color, race, religion, sexuality, or gender...I base it on whether or not they're an asshole.
69
+ Why were the baker's hands brown? Because he kneaded a poo.
70
+ Not to get too technical, but chemistry says alcohol IS a solution. So I win.
71
+ I often think if I'd taken a different path in life, I could be lying on a slightly more comfortable sofa right now.
72
+ I'm terrible at telling jokes... I always punch up the fuck lines
73
+ What did the hillbilly say to his sister after she asked him to have sex with her? If you incest.
74
+ ""You know what, we need a huge spoon to take care of this"" -Guy who invented shovels
75
+ How to keep the flies off the bride at an Italian wedding Keep a bucket of shit next to her
76
+ What do grandparents smell like? ""Depends""
77
+ 7% of all hearing loss is a result of sitting in a restaurant next to a table full of women who just received dessert.
78
+ What do people from the 1930's and /r/news jokes have in common? They're both old.
79
+ I like my slaves like I like my coffee Fair Trade.
80
+ ME: I fell off a 50 ft tall ladder once GIRL: holy cow how did you survive ME: I fell off the bottom rung
81
+ What do you call a blind dinosaur? A do-think-he-saurus :) !! Lol What do you call a blind dinosaurs dog? A do-you-think-he-saurus-rex
82
+ I just bought a very tiny amphibian for a pet. It's my-newt!
83
+ This may be not be a mainstream opinion, but I don't believe you should cut down a Christmas tree unless you intend on eating it.
84
+ Jenna Jameson to Oprah, ""There's a little bit of Jenna Jameson in everyone."" I'm pretty sure she got that backwards.
85
+ Even after 20 years, Jared Fogle is still getting into smaller and smaller jeans.
86
+ I have a degree in men's studies. It's called ""world history"". #TRUMP 2016! YOU CAN'T STUMP THE TRUMP!
87
+ Why don't most fans like the first 39 episodes of DBZ? Its pretty gay, just Saiyan.
88
+ My ex-wife still misses me... But her aim is gettin better.
89
+ This doctor once told me eating a bagel was like eating 5 slices of bread and I was like ok, cool, I like bread
90
+ What do you call a three-humped camel? Pregnant (Told to me by one of the kids at work)
91
+ What did the two tampons say to each other? Nothing, they're both stuck-up cunts.
92
+ What do you call Jay-Z having a leg transplant? A hip-hop hip op.
93
+ What defies the law of gravity? Women. They heavier they are, the easier they are to pick up.
94
+ Everything has to be related in a woman: if the mouth shuts, the legs open.
95
+ Wanna hear a pun about long hair? Rapunzel.
96
+ ""I'm so pissed I could punch a ba-"" ""A what?"" Big Baby from Toy Story 3 hovers over me, sawed-off shotgun in hand. ""A bagel. I HATE carbs.""
97
+ What's the difference Donald Trump and my Vagina? One's a Cunt and the other has nice hair.
98
+ My doctor had to put me on a new medication that's supposed to help lower the amount of karate in my blood
99
+ [uses the restroom] Wife: make sure to put the toilet seat down Me: okay Me: [to toilet seat] you're worthless and nobody likes you
100
+ Q: What's the difference between a blonde and a supermarket trolley? A: The supermarket trolley has a mind of its own.
requirements.txt CHANGED
@@ -3,6 +3,5 @@ sklearn
3
  nltk==3.7
4
  gradio==3.2
5
  pyjokes==0.6.0
6
- fastai==2.7.9
7
  pandas==1.3.5
8
  numpy==1.21.6
 
3
  nltk==3.7
4
  gradio==3.2
5
  pyjokes==0.6.0
 
6
  pandas==1.3.5
7
  numpy==1.21.6