metehanayhan commited on
Commit
4d341d8
·
verified ·
1 Parent(s): f4ead0a

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +36 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import matplotlib.pyplot as plt
3
+ from wordcloud import WordCloud
4
+ import tempfile
5
+ import os
6
+
7
+ def generate_wordcloud(text, file):
8
+ if file is not None:
9
+ text = file.decode('utf-8')
10
+ elif not text:
11
+ return None
12
+
13
+ wordcloud = WordCloud(width=1600, height=800, background_color='white',
14
+ scale=2, min_font_size=10).generate(text)
15
+
16
+ plt.figure(figsize=(20, 10), dpi=300)
17
+ plt.imshow(wordcloud, interpolation='bilinear')
18
+ plt.axis('off')
19
+
20
+ with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as tmp:
21
+ plt.savefig(tmp.name, format='png', dpi=300, bbox_inches='tight')
22
+ plt.close()
23
+ return tmp.name
24
+
25
+ iface = gr.Interface(
26
+ fn=generate_wordcloud,
27
+ inputs=[
28
+ gr.Textbox(label="Enter text"),
29
+ gr.File(label="Or upload a text file", type="binary")
30
+ ],
31
+ outputs=gr.Image(type="filepath", label="Generated Word Cloud"),
32
+ title="Word Cloud Generator - Metehan Ayhan",
33
+ description="Enter text or upload a .txt file to generate a high-quality word cloud."
34
+ )
35
+
36
+ iface.launch(server_port=7861)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ matplotlib
3
+ wordcloud