jaimin commited on
Commit
bff2a00
1 Parent(s): 08cb28a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -40
app.py CHANGED
@@ -17,47 +17,49 @@ import matplotlib.pyplot as plt
17
 
18
 
19
  def opendomain(text,wikipedia_language="en"):
20
- question_words = STOPWORDS.union(set(['likes','play','.',',','like',"don't",'?','use','choose','important','better','?']))
21
- lower_text = text.lower()
22
- lower_text = word_tokenize(lower_text)
23
- new_text = [i for i in lower_text if i not in question_words]
24
- new_txt = "".join(new_text)
25
- if wikipedia_language:
26
- wikipedia.set_lang(wikipedia_language)
27
-
28
- et_page = wikipedia.page(new_txt.replace(" ", ""))
29
- title = et_page.title
30
- content = et_page.content
31
- page_url = et_page.url
32
- linked_pages = et_page.links
33
-
34
- text = content
35
- print(type(text))
36
- wordcloud = WordCloud(font_path="HelveticaWorld-Regular.ttf").generate(text)
37
-
38
- plt.imshow(wordcloud, interpolation='bilinear')
39
- plt.axis("off")
40
-
41
-
42
- final_out = re.sub(r'\=.+\=', '', text)
43
- result = list(filter(lambda x: x != '', final_out.split('\n\n')))
44
-
45
- answer = []
46
- for i in range(6):
47
- if len(result[i]) > 500:
48
- summary_point=result[i].split(".")[0]
49
- answer.append(summary_point)
50
- l = []
51
- for i in range(len(answer)):
52
- l.append("".join(answer[i]))
53
- gen_output = []
54
- for i in range(len(l)):
55
- gen_output.append(l[i] + ".")
56
-
57
- listToStr = ' '.join([str(elem) for elem in gen_output])
58
- listToStr = listToStr.replace("\n", "")
59
- return listToStr
 
60
 
61
 
62
  iface = gr.Interface(fn=opendomain, inputs=[gr.inputs.Textbox(lines=5)], outputs="text")
63
  iface.launch()
 
17
 
18
 
19
  def opendomain(text,wikipedia_language="en"):
20
+ try:
21
+ question_words = STOPWORDS.union(set(['likes','play','.',',','like',"don't",'?','use','choose','important','better','?']))
22
+ lower_text = text.lower()
23
+ lower_text = word_tokenize(lower_text)
24
+ new_text = [i for i in lower_text if i not in question_words]
25
+ new_txt = "".join(new_text)
26
+ if wikipedia_language:
27
+ wikipedia.set_lang(wikipedia_language)
28
+
29
+ et_page = wikipedia.page(new_txt.replace(" ", ""))
30
+ title = et_page.title
31
+ content = et_page.content
32
+ page_url = et_page.url
33
+ linked_pages = et_page.links
34
+
35
+ text = content
36
+ wordcloud = WordCloud(font_path="HelveticaWorld-Regular.ttf").generate(text)
37
+
38
+ plt.imshow(wordcloud, interpolation='bilinear')
39
+ plt.axis("off")
40
+
41
+
42
+ final_out = re.sub(r'\=.+\=', '', text)
43
+ result = list(filter(lambda x: x != '', final_out.split('\n\n')))
44
+ answer = []
45
+ for i in range(6):
46
+ if len(result[i]) > 500:
47
+ summary_point=result[i].split(".")[0:3]
48
+ answer.append(summary_point)
49
+
50
+ final = ""
51
+ for value in answer:
52
+ joint_value = ".".join(value)
53
+ if final == "":
54
+ final += joint_value
55
+ else:
56
+ final = f"{final}.\n\n{joint_value}"
57
+
58
+ return final
59
+ except:
60
+ return "Please write correct wikipedia article name OR question"
61
 
62
 
63
  iface = gr.Interface(fn=opendomain, inputs=[gr.inputs.Textbox(lines=5)], outputs="text")
64
  iface.launch()
65
+