Spaces:
Build error
Build error
File size: 1,111 Bytes
b67a571 | 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 | import gradio as gr
import matplotlib.pyplot as plt
from wordcloud import WordCloud
import tempfile
import os
def generate_wordcloud(text, file):
if file is not None:
text = file.decode('utf-8')
elif not text:
return None
wordcloud = WordCloud(width=1600, height=800, background_color='white',
scale=2, min_font_size=10).generate(text)
plt.figure(figsize=(20, 10), dpi=300)
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis('off')
with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as tmp:
plt.savefig(tmp.name, format='png', dpi=300, bbox_inches='tight')
plt.close()
return tmp.name
iface = gr.Interface(
fn=generate_wordcloud,
inputs=[
gr.Textbox(label="Enter text"),
gr.File(label="Or upload a text file", type="binary")
],
outputs=gr.Image(type="filepath", label="Generated Word Cloud"),
title="Word Cloud Generator - Metehan Ayhan",
description="Enter text or upload a .txt file to generate a high-quality word cloud."
)
iface.launch() |