Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -8,24 +8,38 @@ from nltk.tokenize import word_tokenize
|
|
8 |
from nltk.tokenize import sent_tokenize
|
9 |
import re
|
10 |
nltk.download('punkt')
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
|
13 |
-
def opendomain(text):
|
14 |
question_words = STOPWORDS.union(set(['likes','play','.',',','like',"don't",'?','use','choose','important','better','?']))
|
15 |
lower_text = text.lower()
|
16 |
lower_text = word_tokenize(lower_text)
|
17 |
new_text = [i for i in lower_text if i not in question_words]
|
18 |
new_txt = "".join(new_text)
|
|
|
|
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
text1 = response["data"]
|
26 |
-
final_out = text1[0]
|
27 |
-
final_out=re.sub(r'\=.+\=', '', final_out)
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
result = list(filter(lambda x: x != '', final_out.split('\n\n')))
|
30 |
|
31 |
answer = []
|
@@ -43,10 +57,7 @@ def opendomain(text):
|
|
43 |
listToStr = ' '.join([str(elem) for elem in gen_output])
|
44 |
listToStr = listToStr.replace("\n", "")
|
45 |
return listToStr
|
46 |
-
#return final_answer
|
47 |
|
48 |
|
49 |
iface = gr.Interface(fn=opendomain, inputs=[gr.inputs.Textbox(lines=5)], outputs="text")
|
50 |
iface.launch()
|
51 |
-
|
52 |
-
|
8 |
from nltk.tokenize import sent_tokenize
|
9 |
import re
|
10 |
nltk.download('punkt')
|
11 |
+
import numpy as np
|
12 |
+
import pandas as pd
|
13 |
+
from os import path
|
14 |
+
from PIL import Image
|
15 |
+
from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator
|
16 |
+
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 = []
|
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()
|
|
|
|