sabirbagwan commited on
Commit
d06cae4
·
1 Parent(s): 82a9530

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +47 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from wordcloud import WordCloud
3
+ import matplotlib.pyplot as plt
4
+
5
+ # Streamlit app title and description
6
+ st.title("Word Cloud Generator")
7
+ st.write("Enter your words below and generate a word cloud!")
8
+
9
+ # User input
10
+ words = st.text_input("Enter your words (comma-separated)", "")
11
+
12
+ # Background color selection
13
+ background_color = st.selectbox("Select Background Color", ("dark", "light"))
14
+
15
+ # Generate word cloud
16
+ if st.button("Generate Word Cloud"):
17
+ # Split words by comma and remove leading/trailing whitespaces
18
+ word_list = [word.strip() for word in words.split(",")]
19
+
20
+ # Concatenate all words into a single string
21
+ text = " ".join(word_list)
22
+
23
+ # Set background color
24
+ if background_color == "dark":
25
+ bg_color = "black"
26
+ else:
27
+ bg_color = "white"
28
+
29
+ # Generate word cloud
30
+ wordcloud = WordCloud(width=800, height=400, background_color=bg_color).generate(text)
31
+
32
+ # Display word cloud using Matplotlib
33
+ plt.figure(figsize=(10, 5))
34
+ plt.imshow(wordcloud, interpolation="bilinear")
35
+ plt.axis("off")
36
+ st.pyplot(plt)
37
+
38
+ # Save word cloud image
39
+ if st.button("Save Image"):
40
+ image_filename = "word_cloud.png"
41
+ wordcloud.to_file(image_filename)
42
+ st.write(f"Word cloud image saved as {image_filename}!")
43
+
44
+ # Instructions for user
45
+ st.write("Enter words separated by commas and click 'Generate Word Cloud' to visualize the word cloud.")
46
+ st.write("Select the background color and click 'Generate Word Cloud' to change the background color.")
47
+ st.write("Click 'Save Image' to save the generated word cloud as an image file.")
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ streamlit