-
Notifications
You must be signed in to change notification settings - Fork 1
/
cloud.py
28 lines (22 loc) · 891 Bytes
/
cloud.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from wordcloud import WordCloud, STOPWORDS, ImageColorGenerator
import wikipedia
import matplotlib.pyplot as py
import streamlit as st
def create_cloud(content):
#mask = np.array(Image.open("search1.png"))
cloud = WordCloud(mode="RGBA" , background_color="rgba(255, 255, 255, 0)", max_words = 300, stopwords = STOPWORDS, height=800, width=1600)
cloud.generate(content)
#image_colors = ImageColorGenerator(mask)
#cloud = cloud.recolor(color_func=image_colors)
return cloud
def get_content(phrase):
try:
page = wikipedia.page(phrase, auto_suggest=False)
except wikipedia.exceptions.DisambiguationError as e:
page = wikipedia.page(e.options[0])
return page.content, page.url
@st.cache_data(show_spinner=False)
def get_cloud(phrase):
content, url = get_content(phrase)
cloud = create_cloud(content)
return cloud, url