Jeffgold commited on
Commit
f34662a
·
1 Parent(s): 68299e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -10
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
- standard_resolutions = [4320, 2160, 1440, 1080, 720, 480, 360, 240, 144] # 8K, 4K, 2K, Full HD, HD, SD in pixels
57
-
58
- with tempfile.TemporaryDirectory() as temp_dir:
59
- temp_dir = Path(temp_dir)
60
- input_path = get_input_path(video_file, video_url, temp_dir)
61
 
62
- aspect_ratio = get_aspect_ratio(input_path, aspect_ratio)
63
-
64
- video = VideoFileClip(str(input_path))
65
- original_height = video.size[1]
66
 
67
- output_paths = [] # Define output_paths as an empty list
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