|
import gradio as gr |
|
from wordcloud import WordCloud |
|
import matplotlib.pyplot as plt |
|
from PIL import Image |
|
import io |
|
|
|
def generate_wordcloud(text): |
|
|
|
wordcloud = WordCloud(width=800, height=800, background_color='white', min_font_size=10).generate(text) |
|
|
|
|
|
plt.figure(figsize=(8, 8), facecolor=None) |
|
plt.imshow(wordcloud) |
|
plt.axis("off") |
|
plt.tight_layout(pad=0) |
|
|
|
buf = io.BytesIO() |
|
plt.savefig(buf, format='png') |
|
plt.close() |
|
buf.seek(0) |
|
image = Image.open(buf) |
|
|
|
return image |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface = gr.Interface( |
|
fn=generate_wordcloud, |
|
inputs=gr.Textbox(placeholder="Paste your text here", label="Your Text"), |
|
outputs=gr.Image(type="pil"), |
|
title="Word Cloud Generator", |
|
description="Enter your text in the textbox and generate a word cloud." |
|
) |
|
|
|
interface.launch() |
|
|