- Contents in this wiki are for entertainment purposes only
File:Stars souls wordcloud.png
Jump to navigation
Jump to search
Stars_souls_wordcloud.png (790 × 405 pixels, file size: 289 KB, MIME type: image/png)
Text used
Python code: WordCloudCLI.py
- Generated by perplexity.ai
# wordCloudCLI v.2
# Copyright (C) 20204 XenoEngineer@groupKOS.com all rights reserved.
import sys
import os
from wordcloud import WordCloud
import matplotlib.pyplot as plt
def generate_wordcloud(input_file, output_file):
"""
Generate a word cloud from the text in the input file and save it as a PNG image.
:param input_file: Path to the input text file
:param output_file: Path to save the output PNG image
"""
# Read the contents of the input file
try:
with open(input_file, 'r', encoding='utf-8') as file:
text = file.read()
except FileNotFoundError:
print(f"Error: The file '{input_file}' was not found.")
sys.exit(1)
except IOError:
print(f"Error: Unable to read the file '{input_file}'.")
sys.exit(1)
# Generate the word cloud
# We're using some custom parameters here to enhance the visual appeal
wordcloud = WordCloud(width=800, height=400,
background_color='white',
max_words=200,
contour_width=3,
contour_color='steelblue').generate(text)
# Create a matplotlib figure
plt.figure(figsize=(10, 5))
# Display the generated image
plt.imshow(wordcloud, interpolation='bilinear')
# Remove the axis
plt.axis('off')
# Save the image
plt.savefig(output_file, bbox_inches='tight', pad_inches=0.1)
print(f"Word cloud saved as '{output_file}'")
def main():
"""
Main function to handle command-line arguments and call the word cloud generator.
"""
# Check if the correct number of command-line arguments is provided
if len(sys.argv) != 2:
print("Usage: python wordCloudCLI.py <input_filename>")
sys.exit(1)
# Get the input filename from command-line argument
input_file = sys.argv[1]
# Generate the output filename by changing the extension to .png
output_file = os.path.splitext(input_file)[0] + '_wordcloud.png'
# Generate the word cloud
generate_wordcloud(input_file, output_file)
if __name__ == "__main__":
main()
File history
Click on a date/time to view the file as it appeared at that time.
| Date/Time | Thumbnail | Dimensions | User | Comment | |
|---|---|---|---|---|---|
| current | 15:36, 25 October 2024 | 790 × 405 (289 KB) | XenoEngineer (talk | contribs) | Category:python Category:word cloud Category:wordCloudCLI Category:app ==WordCloudCLI.py== ;Generated by perplexity.ai <pre style="margin-left:3em; font:normal 14px terminal;"># wordCloudCLI v.2 # Copyright (C) 20204 XenoEngineer@groupKOS.com all rights reserved. import sys import os from wordcloud import WordCloud import matplotlib.pyplot as plt def generate_wordcloud(input_file, output_file): """ Generate a word cloud from the text in the input file and save it as... |
You cannot overwrite this file.
File usage
The following page uses this file:
