Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -12,45 +12,47 @@ model = AutoModelForQuestionAnswering.from_pretrained(model_name)
|
|
12 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
13 |
|
14 |
def bullete(text,wikipedia_language="en"):
|
15 |
-
question_words = STOPWORDS.union(set(['likes','play','.',',','like',"don't",'?','use','choose','important','better','?']))
|
16 |
-
lower_text = text.lower()
|
17 |
-
lower_text = word_tokenize(lower_text)
|
18 |
-
new_text = [i for i in lower_text if i not in question_words]
|
19 |
-
new_txt = "".join(new_text)
|
20 |
-
if wikipedia_language:
|
21 |
-
wikipedia.set_lang(wikipedia_language)
|
22 |
-
|
23 |
-
et_page = wikipedia.page(new_txt.replace(" ", ""))
|
24 |
-
title = et_page.title
|
25 |
-
content = et_page.content
|
26 |
-
page_url = et_page.url
|
27 |
-
linked_pages = et_page.links
|
28 |
-
|
29 |
-
text1 = content
|
30 |
-
final_out = re.sub(r'\=.+\=', '', text1)
|
31 |
-
result = list(filter(lambda x: x != '', final_out.split('\n\n')))
|
32 |
-
|
33 |
-
answer = []
|
34 |
try:
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
|
|
|
|
54 |
interface = gr.Interface(fn=bullete,
|
55 |
inputs="text",
|
56 |
outputs="text",
|
12 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
13 |
|
14 |
def bullete(text,wikipedia_language="en"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
try:
|
16 |
+
question_words = STOPWORDS.union(set(['likes','play','.',',','like',"don't",'?','use','choose','important','better','?']))
|
17 |
+
lower_text = text.lower()
|
18 |
+
lower_text = word_tokenize(lower_text)
|
19 |
+
new_text = [i for i in lower_text if i not in question_words]
|
20 |
+
new_txt = "".join(new_text)
|
21 |
+
if wikipedia_language:
|
22 |
+
wikipedia.set_lang(wikipedia_language)
|
23 |
+
|
24 |
+
et_page = wikipedia.page(new_txt.replace(" ", ""))
|
25 |
+
title = et_page.title
|
26 |
+
content = et_page.content
|
27 |
+
page_url = et_page.url
|
28 |
+
linked_pages = et_page.links
|
29 |
+
|
30 |
+
text1 = content
|
31 |
+
final_out = re.sub(r'\=.+\=', '', text1)
|
32 |
+
result = list(filter(lambda x: x != '', final_out.split('\n\n')))
|
33 |
+
|
34 |
+
answer = []
|
35 |
+
try:
|
36 |
+
for i in range(len(result[0].split('.'))):
|
37 |
+
nlp = pipeline('question-answering', model=model_name, tokenizer=model_name)
|
38 |
+
QA_input = {
|
39 |
+
'question': text,
|
40 |
+
'context': result[0].split('.')[i]
|
41 |
+
}
|
42 |
+
res = nlp(QA_input)
|
43 |
+
print(QA_input)
|
44 |
+
values = list(res.values())[3]
|
45 |
+
answer.append(values)
|
46 |
+
except:
|
47 |
+
gen_output = []
|
48 |
+
for i in range(len(answer)):
|
49 |
+
gen_output.append("* " + answer[i] + ".")
|
50 |
+
paraphrase = "\n".join(gen_output)
|
51 |
+
final_answer = paraphrase.replace(" ", " ")
|
52 |
+
return final_answer
|
53 |
|
54 |
+
except:
|
55 |
+
return "Please write correct wikipedia article name OR question"
|
56 |
interface = gr.Interface(fn=bullete,
|
57 |
inputs="text",
|
58 |
outputs="text",
|