Burcin commited on
Commit
7272581
·
1 Parent(s): bbd37cc

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -8,7 +8,6 @@ nltk.download('wordnet', quiet=True)
8
  from nltk.stem import WordNetLemmatizer
9
  from heapq import nlargest
10
  import warnings
11
- !python -m spacy download en_core_web_sm
12
 
13
 
14
  warnings.filterwarnings("ignore")
@@ -23,7 +22,7 @@ def get_wiki_summary(inp):
23
  nlp = spacy.load("en_core_web_sm")
24
 
25
  lemmatizer = WordNetLemmatizer()
26
- tokens = [lemmatizer.lemmatize(str(token).lower()) for token in nlp(text) if str(token) not in punctuation and str(token).lower() not in stopwords and len(token) >1]
27
  word_counts = {}
28
 
29
  for token in tokens:
@@ -36,19 +35,19 @@ def get_wiki_summary(inp):
36
 
37
  sentence_scores = {}
38
 
39
- for sentence in nlp(text).sents:
40
  sentence_scores[sentence] = 0
41
- for wrd in sentence:
42
  if lemmatizer.lemmatize(str(wrd).lower()) in word_counts.keys():
43
  sentence_scores[sentence] += word_counts[lemmatizer.lemmatize(str(wrd).lower())]
44
 
45
  summary_length = int(len(sentence_scores)*0.20)
46
  summary = str()
47
 
48
- for sentence in nlp(text).sents:
49
  for i in range(0,summary_length):
50
  if str(sentence).find(str(nlargest(summary_length, sentence_scores, key = sentence_scores.get)[i])) == 0:
51
- summary += str(sentence)
52
  summary += ' '
53
 
54
 
@@ -56,4 +55,5 @@ def get_wiki_summary(inp):
56
 
57
  return print(summary)
58
 
59
- gr.Interface(fn=get_wiki_summary, inputs=gr.inputs.Textbox(label="Requested Topic from Wikipedia"), outputs="text").launch(inline=False, share=True)
 
 
8
  from nltk.stem import WordNetLemmatizer
9
  from heapq import nlargest
10
  import warnings
 
11
 
12
 
13
  warnings.filterwarnings("ignore")
 
22
  nlp = spacy.load("en_core_web_sm")
23
 
24
  lemmatizer = WordNetLemmatizer()
25
+ tokens = [lemmatizer.lemmatize(str(token).lower()) for token in nltk.word_tokenize(text) if str(token) not in punctuation and str(token).lower() not in stopwords and len(token) >1]
26
  word_counts = {}
27
 
28
  for token in tokens:
 
35
 
36
  sentence_scores = {}
37
 
38
+ for sentence in nltk.sent_tokenize(text):
39
  sentence_scores[sentence] = 0
40
+ for wrd in nltk.word_tokenize(sentence):
41
  if lemmatizer.lemmatize(str(wrd).lower()) in word_counts.keys():
42
  sentence_scores[sentence] += word_counts[lemmatizer.lemmatize(str(wrd).lower())]
43
 
44
  summary_length = int(len(sentence_scores)*0.20)
45
  summary = str()
46
 
47
+ for sentence in nltk.sent_tokenize(text):
48
  for i in range(0,summary_length):
49
  if str(sentence).find(str(nlargest(summary_length, sentence_scores, key = sentence_scores.get)[i])) == 0:
50
+ summary += str(sentence).replace('\n','')
51
  summary += ' '
52
 
53
 
 
55
 
56
  return print(summary)
57
 
58
+ if __name__ == '__main__':
59
+ gr.Interface(fn=get_wiki_summary, inputs=gr.inputs.Textbox(label="Requested Topic from Wikipedia : "), outputs="text").launch(inline=False, share=True)