Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,25 +17,29 @@ 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 |
final_out = re.sub(r'\=.+\=', '', text)
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
def opendomain(text,wikipedia_language="en"):
|
| 20 |
+
try:
|
| 21 |
+
question_words = STOPWORDS.union(
|
| 22 |
+
set(['likes', 'play', '.', ',', 'like', "don't", '?', 'use', 'choose', 'important', 'better', '?']))
|
| 23 |
+
lower_text = text.lower()
|
| 24 |
+
lower_text = word_tokenize(lower_text)
|
| 25 |
+
new_text = [i for i in lower_text if i not in question_words]
|
| 26 |
+
new_txt = "".join(new_text)
|
| 27 |
+
if wikipedia_language:
|
| 28 |
+
wikipedia.set_lang(wikipedia_language)
|
| 29 |
|
| 30 |
+
et_page = wikipedia.page(new_txt.replace(" ", ""))
|
| 31 |
+
title = et_page.title
|
| 32 |
+
content = et_page.content
|
| 33 |
+
page_url = et_page.url
|
| 34 |
+
linked_pages = et_page.links
|
| 35 |
|
| 36 |
+
text = content
|
| 37 |
+
wordcloud = WordCloud(font_path="HelveticaWorld-Regular.ttf").generate(text)
|
| 38 |
|
| 39 |
+
plt.imshow(wordcloud, interpolation='bilinear')
|
| 40 |
+
plt.axis("off")
|
| 41 |
+
except:
|
| 42 |
+
return "Please write correct wikipedia article name OR question"
|
| 43 |
|
| 44 |
|
| 45 |
final_out = re.sub(r'\=.+\=', '', text)
|