File size: 1,019 Bytes
e6a9813 34b89a0 9712abb 34b89a0 e6a9813 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import gradio as gr
from wordcloud import WordCloud
import matplotlib.pyplot as plt
from PIL import Image
import io
def generate_wordcloud(text):
# Create a word cloud
wordcloud = WordCloud(width=800, height=800, background_color='white', min_font_size=10).generate(text)
# Convert word cloud to an image using BytesIO to handle image in memory
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
# Create a Gradio interface
# interface = gr.Interface(fn=generate_wordcloud,
# inputs="text",
# outputs="image")
interface = gr.Interface(
fn=generate_wordcloud,
inputs=gr.input.Textbox(placeholder="Paste your text here", label="Your Text"), # Updated to use Textbox with placeholder
outputs="image"
)
interface.launch()
|