Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -17,47 +17,49 @@ import matplotlib.pyplot as plt
|
|
17 |
|
18 |
|
19 |
def opendomain(text,wikipedia_language="en"):
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
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 |
+
|