Spaces:
Runtime error
Runtime error
Pranjal Pruthi
commited on
Commit
·
659fb2b
1
Parent(s):
d4ddfdb
Add application files and dependencies
Browse files
app.py
CHANGED
|
@@ -9,6 +9,8 @@ import streamlit_antd_components as sac
|
|
| 9 |
import select
|
| 10 |
import uuid
|
| 11 |
import shutil
|
|
|
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
def check_dependencies():
|
|
@@ -50,6 +52,9 @@ def run_command_with_progress(command, status_placeholder, progress_bar, tool_na
|
|
| 50 |
output_lines = []
|
| 51 |
error_lines = []
|
| 52 |
|
|
|
|
|
|
|
|
|
|
| 53 |
while True:
|
| 54 |
reads = [process.stdout.fileno(), process.stderr.fileno()]
|
| 55 |
ret = select.select(reads, [], [], 0.1)
|
|
@@ -71,6 +76,24 @@ def run_command_with_progress(command, status_placeholder, progress_bar, tool_na
|
|
| 71 |
read = process.stderr.readline()
|
| 72 |
if read:
|
| 73 |
error_lines.append(read.strip())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
if process.poll() is not None:
|
| 76 |
break
|
|
@@ -85,6 +108,7 @@ def run_command_with_progress(command, status_placeholder, progress_bar, tool_na
|
|
| 85 |
return return_code
|
| 86 |
|
| 87 |
|
|
|
|
| 88 |
def process_video(url):
|
| 89 |
# Generate a unique identifier for this processing session
|
| 90 |
session_id = str(uuid.uuid4())
|
|
|
|
| 9 |
import select
|
| 10 |
import uuid
|
| 11 |
import shutil
|
| 12 |
+
import re
|
| 13 |
+
import time
|
| 14 |
|
| 15 |
|
| 16 |
def check_dependencies():
|
|
|
|
| 52 |
output_lines = []
|
| 53 |
error_lines = []
|
| 54 |
|
| 55 |
+
start_time = time.time()
|
| 56 |
+
duration = None
|
| 57 |
+
|
| 58 |
while True:
|
| 59 |
reads = [process.stdout.fileno(), process.stderr.fileno()]
|
| 60 |
ret = select.select(reads, [], [], 0.1)
|
|
|
|
| 76 |
read = process.stderr.readline()
|
| 77 |
if read:
|
| 78 |
error_lines.append(read.strip())
|
| 79 |
+
|
| 80 |
+
# Parse ffmpeg output
|
| 81 |
+
if tool_name == "ffmpeg":
|
| 82 |
+
duration_match = re.search(r'Duration: (\d{2}):(\d{2}):(\d{2}\.\d{2})', read)
|
| 83 |
+
if duration_match:
|
| 84 |
+
hours, minutes, seconds = map(float, duration_match.groups())
|
| 85 |
+
duration = hours * 3600 + minutes * 60 + seconds
|
| 86 |
+
|
| 87 |
+
time_match = re.search(r'time=(\d{2}):(\d{2}):(\d{2}\.\d{2})', read)
|
| 88 |
+
if time_match and duration:
|
| 89 |
+
hours, minutes, seconds = map(float, time_match.groups())
|
| 90 |
+
current_time = hours * 3600 + minutes * 60 + seconds
|
| 91 |
+
progress = (current_time / duration) * 100
|
| 92 |
+
elapsed_time = time.time() - start_time
|
| 93 |
+
eta = (elapsed_time / progress) * (100 - progress) if progress > 0 else 0
|
| 94 |
+
|
| 95 |
+
status_placeholder.text(f"{tool_name}: {progress:.2f}% complete, ETA: {eta:.2f} seconds")
|
| 96 |
+
progress_bar.progress(progress / 100)
|
| 97 |
|
| 98 |
if process.poll() is not None:
|
| 99 |
break
|
|
|
|
| 108 |
return return_code
|
| 109 |
|
| 110 |
|
| 111 |
+
|
| 112 |
def process_video(url):
|
| 113 |
# Generate a unique identifier for this processing session
|
| 114 |
session_id = str(uuid.uuid4())
|