Example #1
0
 def sidethreadbrowse(self):   
     import threading
     import fileupload
     from ipywidgets import widgets
     from IPython.display import display
     
     ## Begin initialisation of buttons
     uploader = fileupload.FileUploadWidget()
     uploader.observe(self._handle_upload, names='data')
     display(uploader)
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()
Example #3
0
def _upload():

    _upload_widget = fileupload.FileUploadWidget()

    def _cb(change):
        decoded = io.StringIO(change['owner'].data.decode('utf-8'))
        filename = change['owner'].filename
        print('Uploaded `{}` ({:.2f} kB)'.format(filename,
                                                 len(decoded.read()) / 2**10))

    _upload_widget.observe(_cb, names='data')
    display(_upload_widget)
Example #4
0
def upload():

    text_file = 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()

    text_file.observe(cb, names='data')
    display(text_file)
Example #5
0
def _upload():
    """ For accept the file in form of text and convert it into the string object """
    _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)
Example #6
0
def _upload():
    """TO Get the file from user"""
    _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)
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):
# Here is a list of punctuations and uninteresting words you can use to process your text
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
uninteresting_words = ["the", "a", "to", "if", "is", "it", "of", "and", "or", "an", "as", "i", "me", "my", \
"we", "our", "ours", "you", "your", "yours", "he", "she", "him", "his", "her", "hers", "its", "they", "them", \
"their", "what", "which", "who", "whom", "this", "that", "am", "are", "was", "were", "be", "been", "being", \
"have", "has", "had", "do", "does", "did", "but", "at", "by", "with", "from", "here", "when", "where", "how", \
"all", "any", "both", "each", "few", "more", "some", "such", "no", "nor", "too", "very", "can", "will", "just"]


diction = {}
low = file_contents.lower()
no_punct = ""
for word in low:
if word not in punctuations:
no_punct = no_punct + word
lis = no_punct.split()
for words in lis:
if words not in uninteresting_words:
if words in diction:
diction[words] += 1
else:
diction[words] = 0


#wordcloud
cloud = wordcloud.WordCloud()
cloud.generate_from_frequencies(diction)
return cloud.to_array()

# Display your wordcloud image
myimage = calculate_frequencies(file_contents)
plt.imshow(myimage, interpolation = 'nearest')
plt.axis('off')
plt.show()
Example #8
0
def _upload():
    import io
    _upload_widget = fileupload.FileUploadWidget()

    def _cb(change):
        decoded = io.StringIO(change['owner'].data.decode('utf-8'))
        filename = change['owner'].filename
        print('Uploaded `{}` ({:.2f} kB)'.format(filename,
                                                 len(decoded.read()) / 2**10))
        output = decoded.getvalue()
        filename_out = 'star_data.txt'
        f1 = open(filename_out, 'w')
        f1.write(output)
        f1.close()

    _upload_widget.observe(_cb, names='data')
    display(_upload_widget)
def file_uploader(upload_dir='examples/uploaded',
                  button_label='Upload .CSV file'):
    _upload_widget = fileupload.FileUploadWidget(label=button_label)
    if not os.path.exists(upload_dir):
        os.makedirs(upload_dir)

    def _cb(change):
        decoded = io.StringIO(change['owner'].data.decode('utf-8'))
        filename = change['owner'].filename
        fpath = os.path.join(upload_dir, filename)
        print('Uploaded `{}` ({:.2f} kB)'.format(fpath,
                                                 len(decoded.read()) / 2**10))
        with io.open(fpath, 'w') as fd:
            fd.write(decoded.getvalue())
            decoded.close()

    _upload_widget.observe(_cb, names='data')
    display(_upload_widget)
Example #10
0
import io
import os
import re
from IPython.display import display
import fileupload

upload_widget = fileupload.FileUploadWidget()

finput = None

def set_input(n):
    global finput
    finput = n

def upload():

    def _cb(change):
        global finput
        filename = change['owner'].filename
        data = change['owner'].data
        fd = os.open(filename,os.O_CREAT|os.O_WRONLY)
        os.write(fd,data)
        os.close(fd)
        finput.value = filename

    upload_widget.observe(_cb, names='data')
    display(upload_widget)

upload()

Example #11
0
    def _addInputJupyter(self, name, input, reset=False):
        """Add an input requirement for Jupyter.

           Parameters
           ----------

           name : str
               The name of the input.

           input : :class:`Requirement <BioSimSpace.Gateway._requirement.Requirement>`
               The input requirement object.

           reset : bool
               Whether to reset the widget data.
        """

        # Create a widget button to indicate whether the requirement value
        # has been set.
        button = _widgets.Button(
            tooltip="The input requirement is unset.",
            button_style="warning",
            icon="fa-exclamation-triangle",
            layout=_widgets.Layout(flex="1 1 auto", width="auto"),
            disabled=False,
        )

        # Add a Jupyter widget for each of the supported requirement types.

        # Boolean.
        if type(input) is _Boolean:
            # Create a Jupyter toggle button.
            widget = _widgets.ToggleButton(value=False,
                                           description=name,
                                           tooltip=input.getHelp(),
                                           button_style="",
                                           icon="check",
                                           disabled=False)

            # Add the 'set' indicator button to the widget.
            widget._button = button

            # Flag that the widget is unset.
            widget._is_set = False

            # Get the default value.
            default = input.getDefault()

            if default is not None:
                widget.value = default
                widget._is_set = True
                widget._button.tooltip = "The input requirement is set."
                widget._button.button_style = "success"
                widget._button.icon = "fa-check"

            # Store the requirement name.
            widget._name = name

            # Bind the callback function.
            widget.observe(_on_value_change, names="value")

            # Store the widget.
            self._widgets[name] = widget

        # Integer.
        elif type(input) is _Integer:
            # Get the list of allowed values.
            allowed = input.getAllowedValues()

            # Get the default value.
            default = input.getDefault()

            if allowed is not None:
                # Set the default.
                if default is None:
                    default = allowed[0]

                # Create a dropdown for the list of allowed values.
                widget = _widgets.Dropdown(options=allowed,
                                           value=default,
                                           description=name,
                                           tooltip=input.getHelp(),
                                           disabled=False)

            else:
                # Get the range of the input.
                _min = input.getMin()
                _max = input.getMax()

                # Whether the integer is unbounded.
                is_unbounded = True

                if _min is not None:
                    # Set the default.
                    if default is None:
                        default = _min

                    # Bounded integer.
                    if _max is not None:
                        step = int((_max - _min) / 100)
                        # Create an int slider widget.
                        widget = _widgets.IntSlider(value=default,
                                                    min=_min,
                                                    max=_max,
                                                    step=step,
                                                    description=name,
                                                    tooltip=input.getHelp(),
                                                    continuous_update=False,
                                                    orientation="horizontal",
                                                    readout=True,
                                                    readout_format="d",
                                                    disabled=False)

                        # Flag that the integer is bounded.
                        is_unbounded = False

                # Unbounded integer.
                if is_unbounded:
                    # Create an integer widget.
                    widget = _widgets.IntText(value=default,
                                              description=name,
                                              tooltip=input.getHelp(),
                                              disabled=False)

            # Add the 'set' indicator button to the widget.
            widget._button = button

            # Flag that the widget is unset.
            widget._is_set = False

            # Add an attribute to flag whether the widget value has
            # been set by the user.
            if input.getDefault() is not None:
                widget._is_set = True
                widget._button.tooltip = "The input requirement is set."
                widget._button.button_style = "success"
                widget._button.icon = "fa-check"

            # Store the requirement name.
            widget._name = name

            # Bind the callback function.
            widget.observe(_on_value_change, names="value")

            # Store the widget.
            self._widgets[name] = widget

        # Float types (including those with units).
        elif type(input) in _float_types:
            # Get the list of allowed values.
            allowed = input.getAllowedValues()

            # Get the default value.
            default = input.getDefault()

            # Get the magnitude of types with units.
            if isinstance(default, _Type.Type):
                default = default.magnitude()

            if allowed is not None:
                # Set the default.
                if default is None:
                    default = allowed[0]

                    # Get the magnitude of types with units.
                    if isinstance(default, _Type.Type):
                        default = default.magnitude()

                # Create a dropdown for the list of allowed values.
                widget = _widgets.Dropdown(options=allowed,
                                           value=default,
                                           description=name,
                                           tooltip=input.getHelp(),
                                           disabled=False)

            else:
                # Get the range of the input.
                _min = input.getMin()
                _max = input.getMax()

                # Get the magnitude of types with units.
                if isinstance(_min, _Type.Type):
                    _min = _min.magnitude()
                if isinstance(_max, _Type.Type):
                    _max = _max.magnitude()

                # Whether the float is unbounded.
                is_unbounded = True

                if _min is not None:
                    # Set the default.
                    if default is None:
                        default = _min

                    # Bounded float.
                    if _max is not None:
                        step = (_max - _min) / 100
                        # Create a float slider widget.
                        widget = _widgets.FloatSlider(value=default,
                                                      min=_min,
                                                      max=_max,
                                                      step=step,
                                                      description=name,
                                                      tooltip=input.getHelp(),
                                                      continuous_update=False,
                                                      orientation="horizontal",
                                                      readout=True,
                                                      readout_format=".1f",
                                                      disabled=False)

                        # Flag that the float is bounded.
                        is_unbounded = False

                # Unbounded float.
                if is_unbounded:
                    # Create a float widget.
                    widget = _widgets.FloatText(value=default,
                                                description=name,
                                                tooltip=input.getHelp(),
                                                disabled=False)

            # Add the 'set' indicator button to the widget.
            widget._button = button

            # Flag that the widget is unset.
            widget._is_set = False

            # Add an attribute to flag whether the widget value has
            # been set by the user.
            if input.getDefault() is not None:
                widget._is_set = True
                widget._button.tooltip = "The input requirement is set."
                widget._button.button_style = "success"
                widget._button.icon = "fa-check"

            # Store the requirement name.
            widget._name = name

            # Bind the callback function.
            widget.observe(_on_value_change, names="value")

            # Store the widget.
            self._widgets[name] = widget

        # String.
        elif type(input) is _String:
            # Get the list of allowed values.
            allowed = input.getAllowedValues()

            # Get the default value.
            default = input.getDefault()

            if allowed is not None:
                # Set the default.
                if default is None:
                    default = allowed[0]

                # Create a dropdown for the list of allowed values.
                widget = _widgets.Dropdown(options=allowed,
                                           value=default,
                                           description=name,
                                           tooltip=input.getHelp(),
                                           disabled=False)

            else:
                if default is None:
                    # Create a text widget without a default.
                    widget = _widgets.Text(placeholder="Type something",
                                           description=name,
                                           tooltip=input.getHelp(),
                                           disabled=False)
                else:
                    # Create a text widget.
                    widget = _widgets.Text(value=default,
                                           placeholder="Type something",
                                           description=name,
                                           tooltip=input.getHelp(),
                                           disabled=False)

            # Add the 'set' indicator button to the widget.
            widget._button = button

            # Flag that the widget is unset.
            widget._is_set = False

            # Add an attribute to flag whether the widget value has
            # been set by the user.
            if input.getDefault() is not None:
                widget._is_set = True
                widget._button.tooltip = "The input requirement is set."
                widget._button.button_style = "success"
                widget._button.icon = "fa-check"

            # Store the requirement name.
            widget._name = name

            # Bind the callback function.
            widget.observe(_on_value_change, names="value")

            # Store the widget.
            self._widgets[name] = widget

        # File.
        elif type(input) is _File:
            # Create a fileupload widget.
            widget = _fileupload.FileUploadWidget()

            # Add the 'set' indicator button to the widget.
            widget._button = button

            # Flag that the widget is unset.
            widget._is_set = False

            # Flag that this is just a single file upload.
            widget._is_multi = False

            # Set the value to None.
            widget.value = None

            # Store the requirement name.
            widget._name = name

            # Bind the callback function.
            widget.observe(_on_file_upload, names="data")

            # Store the widget.
            self._widgets[name] = widget

        # File set.
        elif type(input) is _FileSet:
            # Create a fileupload widget.
            widget = _fileupload.FileUploadWidget()

            # Add the 'set' indicator button to the widget.
            widget._button = button

            # Flag that the widget is unset.
            widget._is_set = False

            # Flag that this is is a set of files.
            widget._is_multi = True

            # Set the value to None.
            widget.value = None

            # Store a reference to the node.
            widget._node = self

            # Store the requirement name.
            widget._name = name

            # Store the requirement.
            widget._input = input

            # Bind the callback function.
            widget.observe(_on_file_upload, names="data")

            # This is a new widget.
            if not name in self._widgets or reset:
                self._widgets[name] = [widget]
            else:
                self._widgets[name].append(widget)

        # Unsupported input.
        else:
            raise ValueError("Unsupported requirement type '%s'" % type(input))
Example #12
0
def _upload():
  _upload_widget = fileupload.FileUploadWidget()