Spaces:
Runtime error
Runtime error
Create new file
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import wikipedia
|
| 2 |
+
|
| 3 |
+
def wikipediaScrap(article_name, wikipedia_language = "en"):
|
| 4 |
+
if wikipedia_language:
|
| 5 |
+
wikipedia.set_lang(wikipedia_language)
|
| 6 |
+
|
| 7 |
+
et_page = wikipedia.page(article_name)
|
| 8 |
+
title = et_page.title
|
| 9 |
+
content = et_page.content
|
| 10 |
+
page_url = et_page.url
|
| 11 |
+
linked_pages = et_page.links
|
| 12 |
+
|
| 13 |
+
text = content
|
| 14 |
+
|
| 15 |
+
# Create and generate a word cloud image:
|
| 16 |
+
#wordcloud = WordCloud(font_path="HelveticaWorld-Regular.ttf").generate(text)
|
| 17 |
+
|
| 18 |
+
# Display the generated image:
|
| 19 |
+
#plt.imshow(wordcloud, interpolation='bilinear')
|
| 20 |
+
#plt.axis("off")
|
| 21 |
+
return title, content, page_url, "\n". join(linked_pages)
|
| 22 |
+
|
| 23 |
+
def answer(text):
|
| 24 |
+
title,content,page_url,link = wikipediaScrap(text)
|
| 25 |
+
result = list(filter(lambda x : x != '', content.split('\n\n')))
|
| 26 |
+
answer = []
|
| 27 |
+
for i in range(2):
|
| 28 |
+
if len(result[i]) > 100:
|
| 29 |
+
r = requests.post(
|
| 30 |
+
url="https://hf.space/embed/jaimin/article-qa-summarizer/+/api/predict",
|
| 31 |
+
json={"data": [result[i]]},
|
| 32 |
+
)
|
| 33 |
+
response = r.json()
|
| 34 |
+
answer.append(response['data'][0])
|
| 35 |
+
return answer
|
| 36 |
+
|
| 37 |
+
iface = gr.Interface(fn=answer, inputs=[gr.inputs.Textbox(lines=5)],outputs="text")
|
| 38 |
+
#iface1 = gr.Interface(fn=get_paraphrases_pytorchlight, inputs=[gr.inputs.Textbox(lines=5)],outputs="text")
|
| 39 |
+
iface.launch()
|