Spaces:
Runtime error
Runtime error
日本語表示に変更
Browse files
app.py
CHANGED
@@ -1,15 +1,23 @@
|
|
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 |
|
8 |
t = Tokenizer()
|
9 |
|
10 |
tokens = t.tokenize(text)
|
11 |
|
12 |
-
wc = WordCloud(
|
|
|
|
|
|
|
|
|
|
|
13 |
nouns = [token.base_form for token in tokens if token.part_of_speech.startswith('名詞')]
|
14 |
nouns = (" ").join(nouns)
|
15 |
wc.generate(nouns)
|
@@ -18,7 +26,11 @@ def generate_cloud(text):
|
|
18 |
|
19 |
gr.Interface(
|
20 |
fn=generate_cloud,
|
21 |
-
inputs=[
|
|
|
|
|
|
|
|
|
22 |
outputs=gr.Image(type="pil"),
|
23 |
-
title="
|
24 |
).launch()
|
|
|
1 |
from janome.tokenizer import Tokenizer
|
2 |
from wordcloud import WordCloud
|
3 |
import gradio as gr
|
|
|
4 |
|
5 |
+
def generate_cloud(text, width, height):
|
6 |
+
|
7 |
+
# default setting
|
8 |
+
width = width if width is not None else 1024
|
9 |
+
height = height if height is not None else 768
|
10 |
|
11 |
t = Tokenizer()
|
12 |
|
13 |
tokens = t.tokenize(text)
|
14 |
|
15 |
+
wc = WordCloud(
|
16 |
+
width=int(width),
|
17 |
+
height=int(height),
|
18 |
+
regexp="[\w']+",
|
19 |
+
font_path="./ipaexm00401/ipaexm.ttf")
|
20 |
+
|
21 |
nouns = [token.base_form for token in tokens if token.part_of_speech.startswith('名詞')]
|
22 |
nouns = (" ").join(nouns)
|
23 |
wc.generate(nouns)
|
|
|
26 |
|
27 |
gr.Interface(
|
28 |
fn=generate_cloud,
|
29 |
+
inputs=[
|
30 |
+
gr.Textbox(label="入力テキスト"),
|
31 |
+
gr.Number(label="横幅(デフォルト値:1024)"),
|
32 |
+
gr.Number(label="高さ(デフォルト値:768)")
|
33 |
+
],
|
34 |
outputs=gr.Image(type="pil"),
|
35 |
+
title="☁️にほんご わーどくらうど☁"
|
36 |
).launch()
|