szk1ck commited on
Commit
1ef5acd
1 Parent(s): 2935d4b

lfsの追加

Browse files
Files changed (2) hide show
  1. app.py +7 -7
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,19 +1,19 @@
 
1
  from wordcloud import WordCloud
2
  import gradio as gr
3
  from PIL import Image
4
 
5
  def generate_cloud(text):
 
6
 
7
- wc = WordCloud(width=480, height=320, regexp="[\w']+")
8
-
9
- text = (",").join(text)
10
 
11
- # テキストからワードクラウドを生成する。
12
- wc.generate(text)
13
- # ファイルに保存する。
 
14
  wc.to_file("./wordcloud.png")
15
  image = Image.open("./wordcloud.png")
16
-
17
  return image
18
 
19
 
 
1
+ from janome.tokenizer import Tokenizer
2
  from wordcloud import WordCloud
3
  import gradio as gr
4
  from PIL import Image
5
 
6
  def generate_cloud(text):
7
+ t = Tokenizer()
8
 
9
+ tokens = t.tokenize(text)
 
 
10
 
11
+ wc = WordCloud(width=480, height=320, regexp="[\w']+", font_path="./ipaexm00401/ipaexm.ttf")
12
+ nouns = [token.base_form for token in tokens if token.part_of_speech.startswith('名詞')]
13
+ nouns = (" ").join(nouns)
14
+ wc.generate(nouns)
15
  wc.to_file("./wordcloud.png")
16
  image = Image.open("./wordcloud.png")
 
17
  return image
18
 
19
 
requirements.txt CHANGED
@@ -22,6 +22,7 @@ httpcore==0.16.3
22
  httpx==0.23.3
23
  idna==3.4
24
  importlib-resources==5.10.2
 
25
  Jinja2==3.1.2
26
  jsonschema==4.17.3
27
  kiwisolver==1.4.4
 
22
  httpx==0.23.3
23
  idna==3.4
24
  importlib-resources==5.10.2
25
+ Janome==0.4.2
26
  Jinja2==3.1.2
27
  jsonschema==4.17.3
28
  kiwisolver==1.4.4