-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreatethewordcloud.py
More file actions
executable file
·43 lines (38 loc) · 1.01 KB
/
createthewordcloud.py
File metadata and controls
executable file
·43 lines (38 loc) · 1.01 KB
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
38
39
40
41
42
43
#!/usr/bin/env python3
import matplotlib
import numpy as np
import matplotlib
import pandas
import wordcloud
from wordcloud import WordCloud
import os
import json
import pathlib
import PIL
from PIL import Image
import matplotlib.pyplot as plt
c = 0
tags = {}
for file in os.listdir("photos"):
f = os.path.join("photos", file)
h = pathlib.Path(os.path.join(f, "description.json"))
if os.path.isdir(f):
if h.exists():
j = open(h)
data = json.load(j)
list = data["tags"]
for word in list:
if word not in tags:
tags[word] = 1
else :
tags[word] = tags[word] + 1
#print()
#json_object = json.loads("input.json")
# print(json_object["tags"])
print(tags)
wc = WordCloud(background_color="white",width=1000,height=1000).generate_from_frequencies(tags)
#print(data)
plt.imshow(wc, interpolation='bilinear')
plt.axis("off")
plt.show()
wc.to_file('wordcloud.jpg')