Ejemplo n.º 1
0
    def get_styles(self):
        if self.styles:
            return self.styles
        style_path = os.path.join(self.file_path, "word/styles.xml")
        with open(style_path, encoding="UTF-8") as f:
            styles = f.read()

        styles = BeautifulSoup(styles, "xml")
        self.styles = Styles(styles)
        return self.styles
Ejemplo n.º 2
0
    def _write_styles_file(self):
        # Write the style xml file.
        xf_formats = self.workbook.xf_formats
        palette = self.workbook.palette
        font_count = self.workbook.font_count
        num_format_count = self.workbook.num_format_count
        border_count = self.workbook.border_count
        fill_count = self.workbook.fill_count
        custom_colors = self.workbook.custom_colors
        dxf_formats = self.workbook.dxf_formats

        styles = Styles()
        styles._set_style_properties([
            xf_formats,
            palette,
            font_count,
            num_format_count,
            border_count,
            fill_count,
            custom_colors,
            dxf_formats])

        styles._set_xml_writer(self._filename('xl/styles.xml'))
        styles._assemble_xml_file()
Ejemplo n.º 3
0
 def add_output_box(self):
     text = tk.Text(self, Styles('text'))
     text.grid(row=3, column=0, sticky='WS')
     return text
Ejemplo n.º 4
0
 def add_search_term(self):
     label = tk.Label(self, Styles('label', {'text': 'Search Term'}))
     label.grid(row=0, column=2, sticky='W')
     entry_search_term = tk.Entry(self, Styles('entry'))
     entry_search_term.grid(row=1, column=2)
     return entry_search_term
Ejemplo n.º 5
0
 def add_web_address(self):
     label = tk.Label(self, Styles('label', {'text': 'Web Address'}))
     label.grid(row=0, column=0, sticky='W')
     entry_web_address = tk.Entry(self, Styles('entry'))
     entry_web_address.grid(row=1, column=0)
     return entry_web_address
Ejemplo n.º 6
0
    def __init__(self, root, data, devices):
        """Method initiates GUI and all it's main components"""
        super().__init__(root)
        self.root = root
        self.root.geometry('500x400')
        self.styles = Styles()

        # make GUI
        self.main_frame = Frame(self.root, height=400, width=500)
        self.main_frame.pack_propagate(0)
        self.main_frame.pack()
        self.left_frame = Frame(self.main_frame,
                                relief='groove',
                                bd=3,
                                height=400,
                                width=100)
        self.right_frame = Frame(self.main_frame,
                                 relief='groove',
                                 bd=3,
                                 height=400,
                                 width=500)
        self.right_top_frame = Frame(self.right_frame,
                                     relief='groove',
                                     bd=1,
                                     height=200,
                                     width=350)
        self.right_bottom_frame = Frame(self.right_frame,
                                        relief='groove',
                                        bd=1,
                                        height=200,
                                        width=350)
        self.left_frame.pack(anchor='n', side=LEFT, fill='x')
        self.right_frame.pack(anchor='n', side=RIGHT)
        self.right_top_frame.pack()
        self.right_bottom_frame.pack()
        self.button_add_device = Button(self.left_frame,
                                        text='Add Device',
                                        relief='groove',
                                        command=self.add_device).pack(
                                            side=TOP, expand=True, fill='x')
        # data export
        self.data = data
        self.start_recording_button = Button(
            self.right_bottom_frame,
            text='Start Recording',
            relief='groove',
            command=self.start_recording).pack(side=LEFT)
        self.stop_recording_button = Button(
            self.right_bottom_frame,
            text='Stop Recording',
            relief='groove',
            command=self.stop_recording).pack()

        # IoT devices - menu
        self.devices = devices
        self.iot_dev_name_var = StringVar()
        self.iot_dev_name_var.set(
            self.devices.list_of_devices[0].serial_number)
        self.iot_dev_name_var.trace(
            'w', lambda *pargs: self.callback_iot_dev_name_var())
        self.radio_buttons_init()
        # other objects
        self.ani = None
        self.main_frame.pack_propagate(0)
        self.root.resizable(0, 0)
Ejemplo n.º 7
0
    def recompute_and_populate():
        """
      - load pickled vectorizer
      - transform docs
      - compute cosine similarity for all vector pairs
      - data is retrieved at rev_rollup_ct = 1 (beer level)
    """

        vec_pkl = "src/vocab/review_vectorizer.p"
        was_pkl, vec = load_vec(vec_pkl)

        # load data for styles with feature sets
        # overridden until full feature table is populated

        styles = Styles()
        top_sy = [159, 84, 157, 56, 58, 9, 128, 97, 116, 140]
        print 'Comparing the top %s styles: %s' % (len(top_sy), ', '.join(
            str(s) for s in top_sy))
        X = styles.beer_reviews_rollup(top_sy,
                                       limit=0,
                                       rev_rollup_ct=1,
                                       shuffle=False)

        if was_pkl:
            print "Loaded pickled vectorizer."
            print "Feature count: %s" % len(vec.get_feature_names())
            print "Transforming reviews"

            trans_pool = Pool(min(10, len(top_sy)))
            res_t = trans_pool.map(__asyncable_transform,
                                   [(vec, sy, X[X['style_id'] == sy])
                                    for sy in top_sy])

            # as style keyed dict
            res_t = {r[0]: {'beer_ids': r[1], 'X_t': r[2]} for r in res_t}

        else:
            # exit program
            return 0

        print 'Truncating similarity table'
        bs = BeerSimilarity()
        #    bs.remove_all()

        dim1 = sum(v['X_t'].shape[0] for k, v in res_t.iteritems())
        dim2 = sum(len(v['X_t'].data) for k, v in res_t.iteritems())
        print 'Computing similarities and saving to db %s' % dim1
        print 'Nonzero elements %s' % dim2

        # set style RU
        # will account for symmetry in the database
        #    ru_sids = [ (top_sy[i], top_sy[j]) for i in xrange(len(top_sy)) for j in xrange(i,len(top_sy)) ]
        ru_sids = [(top_sy[i], top_sy[i]) for i in xrange(len(top_sy))]
        pool_inp = []
        for ruc in ru_sids:
            X_t_ref = res_t[ruc[0]]['X_t']
            b_id_ref = res_t[ruc[0]]['beer_ids']

            X_t_comp = res_t[ruc[1]]['X_t']
            b_id_comp = res_t[ruc[1]]['beer_ids']

            pool_inp.append((bs, b_id_ref, X_t_ref, b_id_comp, X_t_comp, 100))

        p = Pool(min(10, len(top_sy)))
        b_id_res = p.map(__asyncable_similarity, pool_inp)

        for res in b_id_res:
            if res[1] is not None:
                print '%s %s' % (', '.join(str(r) for r in res[0]), res[1])
Ejemplo n.º 8
0
# Description:
# Modified to support streaming out with webcams, and not just raw JPEGs.
# Most of the code credits to Miguel Grinberg, except that I made a small tweak. Thanks!
# Credits: http://blog.miguelgrinberg.com/post/video-streaming-with-flask
#
# Usage:
# 1. Install Python dependencies: cv2, flask. (wish that pip install works like a charm)
# 2. Run "python main.py".
# 3. Navigate the browser to the local webpage.
from flask import Flask, render_template, Response, request
from camera import VideoCamera
from styles import Styles
import json

app = Flask(__name__)
styles = Styles()


def generate_video(camera):
    while True:
        frame = camera.get_frame()
        yield (b'--frame\r\n'
               b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')


def init_styles():
    styles.set_eyebrows({"r": 0, "g": 0, "b": 255, "opacity": 128})
    styles.set_eyeliner({"r": 0, "g": 255, "b": 0, "opacity": 110})
    styles.set_lips({"r": 255, "g": 0, "b": 0, "opacity": 128})