VasudevaK commited on
Commit
a0c7d15
·
1 Parent(s): d1c6a4d

changes to app

Browse files
Files changed (1) hide show
  1. app.py +17 -13
app.py CHANGED
@@ -1,13 +1,13 @@
 
 
 
 
1
  from sentence_transformers import SentenceTransformer
2
  from sklearn.metrics.pairwise import cosine_similarity
3
 
4
  import nltk
5
  nltk.download('all')
6
- from nltk.corpus import wordnet as wn
7
- import numpy as np
8
 
9
- import gradio as gr
10
- import pyjokes
11
 
12
  def similarity(input, joke):
13
  return cosine_similarity(input, joke)
@@ -21,7 +21,8 @@ def get_best(input):
21
  jokes_embedding = model.encode(jokes)
22
  input_embedding = model.encode(input)
23
  for idx, joke_embedding in enumerate(jokes_embedding):
24
- sim = similarity(joke_embedding.reshape(-1, 1), input_embedding.reshape(-1,1))
 
25
  if(np.sum(sim) > np.sum(max_similarity)):
26
  max_idx = idx
27
  max_similarity = sim
@@ -30,6 +31,7 @@ def get_best(input):
30
  else:
31
  return None
32
 
 
33
  def generate_list(input):
34
  result = []
35
  n = len(input)
@@ -46,17 +48,18 @@ def generate_list(input):
46
  def pattern(input):
47
  response = input
48
  for substr in generate_list(input):
49
- try :
50
- syn = wn.synsets(substr)[1].hypernyms()[0].hyponyms()[0].hyponyms()[0].lemmas()[0].name()
 
51
  except:
52
- continue
53
  if(syn != None):
54
  response = response.replace(substr, syn.upper())
55
 
56
  if(input == response):
57
- return None
58
- else :
59
- return response
60
 
61
 
62
  def GPT(input):
@@ -90,7 +93,8 @@ def generator(input=None):
90
  if(out2):
91
  response.append(out2)
92
 
93
- return response #[0] think of doing this
 
94
 
95
  iface = gr.Interface(fn=generator, inputs="text", outputs="text")
96
- iface.launch()
 
1
+ import pyjokes
2
+ import gradio as gr
3
+ import numpy as np
4
+ from nltk.corpus import wordnet as wn
5
  from sentence_transformers import SentenceTransformer
6
  from sklearn.metrics.pairwise import cosine_similarity
7
 
8
  import nltk
9
  nltk.download('all')
 
 
10
 
 
 
11
 
12
  def similarity(input, joke):
13
  return cosine_similarity(input, joke)
 
21
  jokes_embedding = model.encode(jokes)
22
  input_embedding = model.encode(input)
23
  for idx, joke_embedding in enumerate(jokes_embedding):
24
+ sim = similarity(joke_embedding.reshape(-1, 1),
25
+ input_embedding.reshape(-1, 1))
26
  if(np.sum(sim) > np.sum(max_similarity)):
27
  max_idx = idx
28
  max_similarity = sim
 
31
  else:
32
  return None
33
 
34
+
35
  def generate_list(input):
36
  result = []
37
  n = len(input)
 
48
  def pattern(input):
49
  response = input
50
  for substr in generate_list(input):
51
+ try:
52
+ syn = wn.synsets(substr)[1].hypernyms()[0].hyponyms()[
53
+ 0].hyponyms()[0].lemmas()[0].name()
54
  except:
55
+ continue
56
  if(syn != None):
57
  response = response.replace(substr, syn.upper())
58
 
59
  if(input == response):
60
+ return None
61
+ else:
62
+ return response
63
 
64
 
65
  def GPT(input):
 
93
  if(out2):
94
  response.append(out2)
95
 
96
+ return response[0] # think of doing this
97
+
98
 
99
  iface = gr.Interface(fn=generator, inputs="text", outputs="text")
100
+ iface.launch()