Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os, json, tempfile, shutil, subprocess
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
def run(cmd):
|
| 6 |
+
r = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
| 7 |
+
if r.returncode != 0:
|
| 8 |
+
raise RuntimeError(r.stderr)
|
| 9 |
+
return r.stdout
|
| 10 |
+
|
| 11 |
+
def ffprobe_duration(path):
|
| 12 |
+
info = run(["ffprobe","-v","error","-print_format","json","-show_format","-show_streams", path])
|
| 13 |
+
meta = json.loads(info)
|
| 14 |
+
if "format" in meta and "duration" in meta["format"]:
|
| 15 |
+
return float(meta["format"]["duration"])
|
| 16 |
+
dur = 0.0
|
| 17 |
+
for s in meta.get("streams", []):
|
| 18 |
+
if "duration" in s:
|
| 19 |
+
dur = max(dur, float(s["duration"]))
|
| 20 |
+
if dur <= 0:
|
| 21 |
+
raise ValueError("Could not determine duration")
|
| 22 |
+
return dur
|
| 23 |
+
|
| 24 |
+
def has_audio(path):
|
| 25 |
+
info = run(["ffprobe","-v","error","-print_format","json","-show_streams", path])
|
| 26 |
+
meta = json.loads(info)
|
| 27 |
+
return any(s.get("codec_type")=="audio" for s in meta.get("streams", []))
|
| 28 |
+
|
| 29 |
+
def split_and
|