Spaces:
Sleeping
Sleeping
from wordcloud import WordCloud | |
import numpy as np | |
import gradio as gr | |
font_path = '猫啃网风雅宋.ttf' # 确保这个文件名与你上传的文件名匹配 | |
def generate_wordcloud(text): | |
wc = WordCloud(width=800, height=400, background_color='white', font_path=font_path) | |
wc.generate(text) | |
image = wc.to_image() | |
image = np.array(image) | |
return image | |
iface = gr.Interface( | |
fn=generate_wordcloud, | |
inputs=gr.Textbox(lines=5, placeholder="Enter your text here..."), | |
outputs="image", | |
title="Word Cloud Generator", | |
description="Enter text to generate a word cloud." | |
) | |
# 启动界面 | |
if __name__ == "__main__": | |
iface.launch() | |