Jeffgold commited on
Commit
b1ae044
·
1 Parent(s): e280197

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -29
app.py CHANGED
@@ -8,6 +8,7 @@ import gradio as gr
8
  import requests
9
  from urllib.parse import urlparse
10
 
 
11
  logging.basicConfig(level=logging.INFO)
12
 
13
  def download_file(url, destination):
@@ -69,7 +70,7 @@ def convert_video(video_file, quality, aspect_ratio, video_url, api_key, upload,
69
  # Check if resolution is a list, if not convert it to a list
70
  resolution = [resolution] if not isinstance(resolution, list) else resolution
71
 
72
- output_path = None # Define output_path before the loop
73
 
74
  for res in resolution:
75
  # Skip if res is boolean
@@ -85,37 +86,19 @@ def convert_video(video_file, quality, aspect_ratio, video_url, api_key, upload,
85
  "-hls_playlist_type", "vod", "-f", "hls", str(output_path)
86
  ]
87
 
88
- try:
89
- logging.info("Running command: %s", " ".join(ffmpeg_command))
90
- subprocess.run(ffmpeg_command, check=True, timeout=600)
91
- except subprocess.CalledProcessError:
92
- logging.exception("ffmpeg command failed.")
93
- error_file_path = tempfile.gettempdir() + "/error.txt"
94
- with open(error_file_path, 'w') as error_file:
95
- error_file.write("ffmpeg command failed.")
96
- return error_file_path
97
- except subprocess.TimeoutExpired:
98
- logging.exception("ffmpeg command timed out.")
99
- return "ffmpeg command timed out."
100
- except FileNotFoundError:
101
- logging.exception("ffmpeg is not installed.")
102
- return "ffmpeg is not installed."
103
- except Exception as e:
104
- logging.exception("An error occurred.")
105
- return f"An error occurred: {str(e)}"
106
-
107
- # We need to modify this part if you want to return all converted videos
108
- # Here we only return the last converted video
109
- # Check if output_path is None after the loop
110
- if output_path is None:
111
  return "No resolution was selected."
112
 
113
- output_copy_path = shutil.copy2(output_path, tempfile.gettempdir())
114
 
115
  if upload:
116
- return upload_to_web3_storage(api_key, output_copy_path)
117
  else:
118
- return output_copy_path
119
 
120
  def main():
121
  video_file = gr.inputs.File(label="Video File")
@@ -125,9 +108,9 @@ def main():
125
  choices=[None, "1:1", "4:3", "3:2", "5:4", "16:9", "21:9",
126
  "1.85:1", "2.35:1", "3:1", "360", "9:16", "16:9",
127
  "2:1", "1:2", "9:1"],
128
- label="Aspect Ratio", default=None)
129
  resolution = gr.components.Dropdown(
130
- choices=["480p", "720p", "1080p", "1440p", "2160p", "4320p"], label="Resolution", multiple=True, default=["1080p"])
131
  video_url = gr.inputs.Textbox(label="Video URL")
132
  api_key = gr.inputs.Textbox(label="web3.storage API Key")
133
  upload = gr.inputs.Checkbox(label="Upload to web3.storage", default=False)
 
8
  import requests
9
  from urllib.parse import urlparse
10
 
11
+
12
  logging.basicConfig(level=logging.INFO)
13
 
14
  def download_file(url, destination):
 
70
  # Check if resolution is a list, if not convert it to a list
71
  resolution = [resolution] if not isinstance(resolution, list) else resolution
72
 
73
+ output_paths = [] # Define output_paths as an empty list
74
 
75
  for res in resolution:
76
  # Skip if res is boolean
 
86
  "-hls_playlist_type", "vod", "-f", "hls", str(output_path)
87
  ]
88
 
89
+ # Rest of the function...
90
+
91
+ output_paths.append(output_path) # Append the output_path to output_paths
92
+
93
+ if not output_paths:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  return "No resolution was selected."
95
 
96
+ output_copy_paths = [shutil.copy2(path, tempfile.gettempdir()) for path in output_paths]
97
 
98
  if upload:
99
+ return [upload_to_web3_storage(api_key, path) for path in output_copy_paths]
100
  else:
101
+ return output_copy_paths
102
 
103
  def main():
104
  video_file = gr.inputs.File(label="Video File")
 
108
  choices=[None, "1:1", "4:3", "3:2", "5:4", "16:9", "21:9",
109
  "1.85:1", "2.35:1", "3:1", "360", "9:16", "16:9",
110
  "2:1", "1:2", "9:1"],
111
+ label="Aspect Ratio", default="16:9")
112
  resolution = gr.components.Dropdown(
113
+ choices=["480p", "720p", "1080p", "1440p", "2160p", "4320p"], label="Resolution", multiple=True, default="1080p")
114
  video_url = gr.inputs.Textbox(label="Video URL")
115
  api_key = gr.inputs.Textbox(label="web3.storage API Key")
116
  upload = gr.inputs.Checkbox(label="Upload to web3.storage", default=False)