Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,26 @@ from moviepy.editor import VideoFileClip
|
|
7 |
import gradio as gr
|
8 |
import requests
|
9 |
from urllib.parse import urlparse
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
logging.basicConfig(level=logging.INFO)
|
12 |
|
@@ -53,18 +73,15 @@ def create_master_playlist(output_paths, temp_dir):
|
|
53 |
return master_playlist_path
|
54 |
|
55 |
def convert_video(video_file, quality, aspect_ratio, video_url):
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
input_path = get_input_path(video_file, video_url, temp_dir)
|
61 |
|
62 |
-
|
63 |
-
|
64 |
-
video = VideoFileClip(str(input_path))
|
65 |
-
original_height = video.size[1]
|
66 |
|
67 |
-
|
68 |
|
69 |
for res in standard_resolutions:
|
70 |
# Skip if resolution is higher than original
|
|
|
7 |
import gradio as gr
|
8 |
import requests
|
9 |
from urllib.parse import urlparse
|
10 |
+
import http.server
|
11 |
+
import socketserver
|
12 |
+
import threading
|
13 |
+
|
14 |
+
logging.basicConfig(level=logging.INFO)
|
15 |
+
|
16 |
+
PORT = 8000
|
17 |
+
temp_dir = Path(tempfile.mkdtemp()) # Create a temporary directory using mkdtemp() instead of TemporaryDirectory()
|
18 |
+
|
19 |
+
class Handler(http.server.SimpleHTTPRequestHandler):
|
20 |
+
def __init__(self, *args, **kwargs):
|
21 |
+
super().__init__(*args, directory=str(temp_dir), **kwargs)
|
22 |
+
|
23 |
+
def start_server():
|
24 |
+
with socketserver.TCPServer(("", PORT), Handler) as httpd:
|
25 |
+
print(f"Serving at port {PORT}")
|
26 |
+
httpd.serve_forever()
|
27 |
+
|
28 |
+
t = threading.Thread(target=start_server)
|
29 |
+
t.start()
|
30 |
|
31 |
logging.basicConfig(level=logging.INFO)
|
32 |
|
|
|
73 |
return master_playlist_path
|
74 |
|
75 |
def convert_video(video_file, quality, aspect_ratio, video_url):
|
76 |
+
# Use the already-created temp_dir instead of creating a new one
|
77 |
+
# temp_dir = Path(tempfile.mkdtemp())
|
78 |
+
input_path = get_input_path(video_file, video_url, temp_dir)
|
79 |
+
aspect_ratio = get_aspect_ratio(input_path, aspect_ratio)
|
|
|
80 |
|
81 |
+
video = VideoFileClip(str(input_path))
|
82 |
+
original_height = video.size[1]
|
|
|
|
|
83 |
|
84 |
+
output_paths = [] # Define output_paths as an empty list
|
85 |
|
86 |
for res in standard_resolutions:
|
87 |
# Skip if resolution is higher than original
|