Learn practical skills, build real-world projects, and advance your career
Created 4 years ago
import wordcloud
import numpy as np
from matplotlib import pyplot as plt
from IPython.display import display
import fileupload
import io
import sys
def _upload():
_upload_widget=fileupload.fileuploadWidget()
def _cb(change):
global file_contents
decoded=io.StringIO(change['owner'].data.decode('utf-8'))
filename= change['owner'].filename
print('uploaded ',' ({:.2f} KB)'.format(
filename, len(decoded.read()) /2**10))
file_contents= decoded.getvalue()
_upload_widget.observe(_cb, names='data')
display(_upload_widget)
_upload()
def calculate_frequencies(file_contents):
punctuation='''!()-[]{};:""\,<>./?@#$%^&*_-'''
uninteresting_words= ["the", "a","to","if","is","it","of","we","ours","what","did","do","by","such","this","any","yes","so","out","tall","let","talk","kit","tail","few","each","no","can","nor","here","did","hers"]
cloud = wordcloud.WorldCloud()
cloud.generate_from_frequencies()
return cloud.to_array()
myimage = calculate_frequencies(file_contents)
plt.inshow(myimage, interpolation='nearest')
plt.axis('off')
plt.show()
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-8-34492357ada4> in <module>
28 return cloud.to_array()
29
---> 30 myimage = calculate_frequencies(file_contents)
31 plt.inshow(myimage, interpolation='nearest')
32 plt.axis('off')
NameError: name 'file_contents' is not defined