File size: 2,155 Bytes
142281f | 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | """Records the backup demo video (same scenario as the live demo) from the local Gradio app.
Usage: python app.py & then python record_demo.py -> demo_secours.mp4
"""
import shutil
import subprocess
from pathlib import Path
from playwright.sync_api import sync_playwright
URL = "http://127.0.0.1:7860/"
OUT = Path("demo_secours.mp4")
def analyse(page, pause=3500):
page.evaluate("window.scrollTo({top: 0, behavior: 'smooth'})")
page.wait_for_timeout(1200)
page.locator('button:has-text("Analyser")').click()
page.get_by_text("Score d'anomalie").first.wait_for(timeout=60000)
page.wait_for_timeout(pause)
def example(page, row, page_no=None):
if page_no:
page.locator(f'button:text-is("{page_no}")').first.click()
page.wait_for_timeout(800)
page.locator("tbody tr").nth(row).click()
page.wait_for_timeout(1500)
with sync_playwright() as p:
browser = p.chromium.launch()
ctx = browser.new_context(viewport={"width": 1440, "height": 900},
record_video_dir="video_tmp", record_video_size={"width": 1440, "height": 900})
page = ctx.new_page()
page.goto(URL)
page.get_by_text("Analyser").first.wait_for()
page.wait_for_timeout(2500)
example(page, 0) # bottle, broken_large (easy)
analyse(page, 9000)
example(page, 1) # capsule, crack
analyse(page, 9000)
example(page, 3) # hazelnut, crack
analyse(page, 9000)
example(page, 0, page_no="2") # pill, good (normal part)
analyse(page, 9000)
example(page, 1) # screw, good (hard: just below the threshold)
analyse(page, 9000)
example(page, 2) # tile, crack (model without center-crop)
analyse(page, 9000)
video = page.video.path()
ctx.close()
browser.close()
subprocess.run(["ffmpeg", "-y", "-loglevel", "error", "-i", video, "-c:v", "libx264", "-pix_fmt", "yuv420p",
"-crf", "28", "-movflags", "+faststart", str(OUT)], check=True)
shutil.rmtree("video_tmp", ignore_errors=True)
print("wrote", OUT, OUT.stat().st_size // 1024, "KB")
|