Spaces:
Runtime error
Runtime error
import gradio as gr | |
import wikipedia | |
import numpy as np | |
import pandas as pd | |
from os import path | |
from PIL import Image | |
from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator | |
import matplotlib.pyplot as plt | |
def wikipediaScrap(article_name, wikipedia_language = "en"): | |
if wikipedia_language: | |
wikipedia.set_lang(wikipedia_language) | |
et_page = wikipedia.page(article_name) | |
title = et_page.title | |
content = et_page.content | |
page_url = et_page.url | |
linked_pages = et_page.links | |
text = content | |
# Create and generate a word cloud image: | |
wordcloud = WordCloud(font_path="HelveticaWorld-Regular.ttf").generate(text) | |
# Display the generated image: | |
plt.imshow(wordcloud, interpolation='bilinear') | |
plt.axis("off") | |
return title, content, page_url, "\n". join(linked_pages), plt | |
with gr.Blocks( css = "footer {visibility: hidden} #dsd_button {background: purple, color: white} {background: blue, color: white}" ) as demo: | |
with gr.Row(): | |
inp = gr.Textbox(placeholder="Enter the name of wikipedia article") | |
lan = gr.Textbox(placeholder="Enter the language code") | |
btn = gr.Button("Start Scraping", elem_id="dsd_button") | |
gr.Markdown("""### Wordcloud""") | |
with gr.Row(): | |
with gr.Column(): | |
title = gr.Textbox() | |
url = gr.Textbox() | |
with gr.Column(): | |
wordcloud = gr.Plot() | |
gr.Markdown("""### Content""") | |
with gr.Row(): | |
content = gr.Textbox() | |
gr.Markdown("""### Linked Articles""") | |
with gr.Row(): | |
linked = gr.Textbox() | |
with gr.Row(): | |
gr.Examples( | |
examples = [["Eiffel Tower", "en"], ["Eiffel tower", 'ur']], fn=wikipediaScrap, inputs=[inp, lan], outputs=[title, content, url, linked, wordcloud], cache_examples=True) | |
btn.click(fn=wikipediaScrap, inputs=[inp, lan], outputs=[title, content, url, linked, wordcloud]) | |
demo.launch() |