Spaces:
Runtime error
Runtime error
from janome.tokenizer import Tokenizer | |
from wordcloud import WordCloud | |
import gradio as gr | |
from PIL import Image | |
def generate_cloud(text): | |
t = Tokenizer() | |
tokens = t.tokenize(text) | |
wc = WordCloud(width=480, height=320, regexp="[\w']+", font_path="./ipaexm00401/ipaexm.ttf") | |
nouns = [token.base_form for token in tokens if token.part_of_speech.startswith('εθ©')] | |
nouns = (" ").join(nouns) | |
wc.generate(nouns) | |
wc.to_file("./wordcloud.png") | |
image = Image.open("./wordcloud.png") | |
return image | |
gr.Interface( | |
fn=generate_cloud, | |
inputs="text", | |
outputs=gr.Image(type="pil"), | |
title="WordCloud Demonstration" | |
).launch() |