예제 #1
0
    def add_video(self, value, width=None):
        if isinstance(value, str):
            filename = value.replace('/', '_')
            os.system(f'cp {value} {self.html.video_dir}/{filename}')
            vd_abs_path = f'{self.html.video_dir}/{filename}'
            vd_rel_path = f'videos/{filename}'
            if width is None: width = 400

        elif isinstance(value, Video):
            assert len(value) > 0, 'Empty video!'
            vd_dir = self.html.video_dir
            vd_id = self.start_vd_id + self.num_videos
            vd_path = f'{vd_id:06d}.mp4'
            vd_abs_path = f'{vd_dir}/{vd_path}'
            vd_rel_path = f'videos/{vd_path}'

            if width is None: 
                width = value[0].shape[1]

            save_video(vd_abs_path, value, fps=20, verbose=False)
            self.num_videos += 1

        # os.system(f'ffmpeg -y -loglevel error -i {vd_abs_path} -pix_fmt rgb24 {vd_abs_path.replace(".mp4", ".gif")}')
        # img(src=vd_rel_path.replace('.mp4', '.gif'), style=f"width:{width}px")

        video(src=vd_rel_path, width=f'{width}px', height='auto', 
              controls='true', autoplay='true', loop='true', muted='true', playsinline='true')
예제 #2
0
def html_grid(grid, transpose=False):
    if transpose:
        grid = list(map(list, zip(*grid)))
    with dtags.table().add(dtags.tbody()):
        for row_idx, row in enumerate(grid):
            with dtags.tr():
                for cell_idx, cell in enumerate(row):
                    cell_type = cell["type"]
                    if cell_type == "txt":
                        if "text" not in cell:
                            raise ValueError(
                                "Expected grid cell of type 'txt'"
                                " to have field 'text'"
                            )
                        dtags.td().add(dtags.p(cell["text"]))
                    elif cell_type == "video":
                        if "path" not in cell:
                            raise ValueError(
                                "Expected grid cell of type 'video'"
                                " to have field 'path'"
                            )
                        video_path = cell["path"]
                        if str(video_path).lower().endswith("webm"):
                            vid_type = "video/webm"
                        if str(video_path).lower().endswith("mp4"):
                            vid_type = "video/mp4"
                        with dtags.td():
                            dtags.video(controls=True, autoplay=False).add(
                                dtags.source(src=video_path, type=vid_type)
                            )
예제 #3
0
파일: html.py 프로젝트: zigchang/retiming
    def add_videos(self, vids, txts, links, width=400):
        """add images to the HTML file

        Parameters:
            ims (str list)   -- a list of image paths
            txts (str list)  -- a list of image names shown on the website
            links (str list) --  a list of hyperref links; when you click an image, it will redirect you to a new page
        """
        self.t = table(border=1,
                       style="table-layout: fixed;")  # Insert a table
        self.doc.add(self.t)
        with self.t:
            with tr():
                for vid, txt, link in zip(vids, txts, links):
                    with td(style="word-wrap: break-word;",
                            halign="center",
                            valign="top"):
                        with p():
                            with a(href=os.path.join('videos', link)):
                                with video(style="width:%dpx" % width,
                                           controls=True):
                                    source(src=os.path.join('videos', vid),
                                           type="video/mp4")
                            br()
                            p(txt)
예제 #4
0
    def add_videos(self, vids, txts, links, width=400, hidden_tag="hidden"):
        """add images to the HTML file

        Parameters:
            vids (str list)   -- a list of image paths
            txts (str list)  -- a list of image names shown on the website
            links (str list) --  a list of hyperref links; when you click an image,
            it will redirect you to a new page
        """
        self.t = table(border=1, style="table-layout: fixed;")  # Insert a table
        self.doc.add(self.t)
        colors = ["red", "blue", "gold", "salman"]
        with self.t:
            with tr():
                for vid, txt, link in zip(vids, txts, links):
                    td_style = "word-wrap: break-word; width:{}px".format(width)
                    with td(style=td_style, halign="center", valign="top"):
                        with p():
                            vid_path = str(vid)
                            if vid_path == hidden_tag:
                                p_style = "font-weight: bold; width:{}px;"
                                p_style = p_style.format(width * 3)
                                p("hidden video", style=p_style)
                            else:
                                with a(href=str(link)):
                                    with video():
                                        attr(controls="controls")
                                        source(src=vid_path, type="video/mp4")
                            br()
                            rows = txt.split("<br>")
                            for idx, row in enumerate(rows):
                                color = colors[idx % len(colors)]
                                bold_tag = "<b>"
                                if not row.startswith(bold_tag):
                                    s_style = "color:{};".format(color)
                                else:
                                    s_style = "color:black; font-weight: bold;"
                                    row = row[len(bold_tag):]
                                span(row, style=s_style)
예제 #5
0
            tags.h2("Video-to-speech", id="video-to-speech", cls="mt-3")
            raw("<p>We show results for the <em>seen</em> scenario, in which we consider videos from four speakers encountered at training. "
                "We have randomly selected 12 video samples and show the synthesized audio for our baseline method (denoted by B in the paper) and for the work of <a href='https://www.isca-speech.org/archive/Interspeech_2019/pdfs/1445.pdf'>Vougioukas et al. (Interspeech, 2019)</a> (denoted by V2S GAN). "
                "The videos are cropped around the lips, corresponding to the input to our network. "
                "These results correspond to section 4.1 in our paper.</p>")

            data1 = load_results_1()
            for row in partition_all(6, data1):
                with tags.div(cls="row mt-2 align-items-end"):
                    for col in row:
                        with tags.div(cls="col-2 text-center"):
                            with tags.div():
                                tags.span(col["speaker"], cls="text-muted")
                                tags.code(col["sample-id"], cls="ml-1")
                            tags.span(col["text"], cls="font-italic")
                            with tags.video(controls=True,
                                            cls="embed-responsive"):
                                tags.source(src=col["video-path"],
                                            type="video/webm")
                            tags.span("Ours")
                            with tags.audio(controls=True,
                                            cls="embed-responsive"):
                                tags.source(src=col["audio-path-ours"],
                                            type="audio/wav")
                            tags.span("V2S GAN")
                            with tags.audio(controls=True,
                                            cls="embed-responsive"):
                                tags.source(src=col["audio-path-theirs"],
                                            type="audio/wav")

            tags.h2("Speaker control", id="speaker-control", cls="mt-3")
예제 #6
0
def make_region_html(region, args):
    """Write region-specific HTML page."""

    latest = max(
        m.frame.index.max()
        for m in region.metrics["covid"].values()
        if m.emphasis >= 0
    )

    doc = dominate.document(title=f"{region.name} COVID-19 ({latest.date()})")
    doc_url = urls.region_page(region)

    def doc_link(url):
        return urls.link(doc_url, url)

    with doc.head:
        style.add_head_style(doc_url)

    with doc.body:
        tags.attr(id="map_key_target", tabindex="-1")
        with tags.h1():

            def write_breadcrumbs(r):
                if r is not None:
                    write_breadcrumbs(r.parent)
                    tags.a(r.short_name, href=doc_link(urls.region_page(r)))
                    util.text(" » ")

            write_breadcrumbs(region.parent)
            util.text(region.name)

        with tags.div():
            pop = region.totals["population"]
            vax = region.totals.get("vaccinated", 0)
            pos = region.totals.get("positives", 0)
            dead = region.totals.get("deaths", 0)

            nobreak = lambda t: tags.span(t, cls="nobreak")
            nobreak(f"{pop:,.0f} pop; ")
            if vax:
                nobreak(f"{vax:,.0f} ({100 * vax / pop:.2g}%) vacc, ")
            nobreak(f"{pos:,.0f} ({100 * pos / pop:.2g}%) pos, ")
            nobreak(f"{dead:,.0f} ({100 * dead / pop:.2g}%) deaths ")
            nobreak(f"as of {latest.date()}")

        if urls.has_map(region):
            with tags.div(cls="graphic"):
                with tags.video(id="map", preload="auto"):
                    href = urls.link(doc_url, urls.map_video_maybe(region))
                    tags.source(type="video/webm", src=f"{href}#t=1000")

                with tags.div(cls="map_controls"):

                    def i(n):
                        return tags.i(cls=f"fas fa-{n}")

                    tags.button(i("pause"), " ", i("play"), " P", id="map_play")
                    tags.button(i("repeat"), " L", id="map_loop")
                    tags.button(i("backward"), " R", id="map_rewind")
                    tags.button(i("step-backward"), " [", id="map_prev")
                    tags.input_(type="range", id="map_slider")
                    tags.button(i("step-forward"), " ]", id="map_next")
                    tags.button(i("forward"), " F", id="map_forward")

        tags.img(cls="graphic", src=doc_link(urls.chart_image(region)))

        notables = [p for p in region.policy_changes if p.score]
        if notables:
            tags.h2(
                tags.span("Closing", cls="policy_close"),
                " and ",
                tags.span("Reopening", cls="policy_open"),
                " policy changes",
            )

            with tags.div(cls="policies"):
                last_date = None
                for p in notables:
                    date, s = str(p.date.date()), p.score
                    if date != last_date:
                        tags.div(date, cls=f"date")
                        last_date = date

                    tags.div(p.emoji, cls=f"emoji")

                    tags.div(
                        p.text,
                        cls="text"
                        + (" policy_close" if s < 0 else "")
                        + (" policy_open" if s > 0 else "")
                        + (" policy_major" if abs(s) >= 2 else ""),
                    )

        subs = [
            r
            for r in region.subregions.values()
            if r.matches_regex(args.region_regex)
        ]
        if subs:
            sub_pop = sum(s.totals["population"] for s in subs)
            if len(subs) >= 10 and sub_pop > 0.9 * region.totals["population"]:

                def pop(r):
                    return r.totals.get("population", 0)

                def pos(r):
                    m = r.metrics["covid"].get("COVID positives / day / 100Kp")
                    return m.frame.value.iloc[-1] * pop(r) if m else 0

                tags.h2("Top 5 by population")
                for s in list(sorted(subs, key=pop, reverse=True))[:5]:
                    make_subregion_html(doc_url, s)

                tags.h2("Top 5 by new positives")
                for s in list(sorted(subs, key=pos, reverse=True))[:5]:
                    make_subregion_html(doc_url, s)

                tags.h2(f'All {"divisions" if region.parent else "countries"}')
            else:
                tags.h2("Subdivisions")
            for s in sorted(subs, key=lambda r: r.name):
                make_subregion_html(doc_url, s)

        r = region
        credits = dict(c for p in r.policy_changes for c in p.credits.items())
        for ms in r.metrics.values():
            credits.update(c for m in ms.values() for c in m.credits.items())
        with tags.p("Sources: ", cls="credits"):
            for i, (url, text) in enumerate(credits.items()):
                util.text(", ") if i > 0 else None
                tags.a(text, href=url)

    with open(urls.file(args.site_dir, doc_url), "w") as doc_file:
        doc_file.write(doc.render())
예제 #7
0
파일: www_vgg.py 프로젝트: danoneata/xts
def create_page(data, samples):
    doc = dominate.document(title="Deep Lip Reading on the Grid data")

    with doc.head:
        T.meta(**{
            'content': 'text/html;charset=utf-8',
            'http-equiv': 'Content-Type'
        })
        T.meta(**{'content': 'utf-8', 'http-equiv': 'encoding'})
        T.link(rel='stylesheet', href='style.css')
        T.script(
            src="https://code.jquery.com/jquery-3.4.1.min.js",
            integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=",
            crossorigin="anonymous",
        )
        T.script(type='text/javascript', src='script.js')

    with doc:
        T.h3("Deep Lip Reading on the Grid data")

        T.p("""
            We run the pre-trained transformer model from VGG on word-level video snippets (shown as GIFs);
            these are taken from the Grid corpus (see also videos below).
            For each word-level snippet we provide the following information:
        """)

        with T.ul():
            T.li("the sample's name")
            T.li("the input to the visual frontend")
            T.li("the prediction")
            T.li("the groundtruth")

        T.p("""
            The GIFs are at 4 frames per second and can be animated by hovering over.
        """)

        for k, group in itertools.groupby(data,
                                          key=lambda t: t[0].split("_")[0]):

            # Show video
            sample, *_ = [s for s in samples if s.key == k]
            src = sample.video_path
            dst = os.path.join("www", "data-vgg", k + ".mp4")
            if not os.path.exists(dst):
                subprocess.run(["ffmpeg", "-i", src, dst])

            with T.video(controls="controls"):
                path = os.path.join("data-vgg", k + ".mp4")
                T.source(src=path, **{"type": "video/mp4"})
                T.br()

            # Show crops
            with T.div():
                for key, pred, gt in group:
                    with T.div(cls="sample"):
                        src = os.path.join("data-vgg", key + "_still.gif")
                        with T.div(cls="info"):
                            T.span(key)
                        T.img(src=src, width=100, height=100)
                        with T.div():
                            T.span(pred)
                        with T.div():
                            T.span(gt)

    path = os.path.join("www", "vgg.html")

    with open(path, "w") as f:
        f.write(doc.render())

    print(path)