Jeffgold commited on
Commit
95bc252
·
1 Parent(s): d10be9a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -59,7 +59,7 @@ def upload_to_web3_storage(api_key, path):
59
  logging.exception("An error occurred while uploading to web3.storage.")
60
  return f"An error occurred while uploading to web3.storage: {response.json()}"
61
 
62
- def convert_video(video_file, quality, aspect_ratio, video_url, api_key, upload):
63
  """Converts a video to HLS format, adjusting the quality and aspect ratio as necessary."""
64
  with tempfile.TemporaryDirectory() as temp_dir:
65
  temp_dir = Path(temp_dir)
@@ -67,6 +67,10 @@ def convert_video(video_file, quality, aspect_ratio, video_url, api_key, upload)
67
  output_path = get_output_path(input_path, temp_dir)
68
  aspect_ratio = get_aspect_ratio(input_path, aspect_ratio)
69
 
 
 
 
 
70
  ffmpeg_command = [
71
  "ffmpeg", "-i", str(input_path), "-c:v", "libx264", "-crf", str(quality),
72
  "-vf", f"scale=-1:720,setsar={aspect_ratio}", "-hls_time", "6",
@@ -104,24 +108,25 @@ def convert_video(video_file, quality, aspect_ratio, video_url, api_key, upload)
104
  def main():
105
  video_file = gr.inputs.File(label="Video File")
106
  quality = gr.inputs.Dropdown(
107
- choices=["18", "23", "28", "32"], label="Quality", default="23")
108
  aspect_ratio = gr.inputs.Dropdown(
109
  choices=[None, "1:1", "4:3", "3:2", "5:4", "16:9", "21:9",
110
  "1.85:1", "2.35:1", "3:1", "360", "9:16", "16:9",
111
  "2:1", "1:2", "9:1"],
112
  label="Aspect Ratio", default=None)
 
 
113
  video_url = gr.inputs.Textbox(label="Video URL")
114
  api_key = gr.inputs.Textbox(label="web3.storage API Key")
115
  upload = gr.inputs.Checkbox(label="Upload to web3.storage", default=False)
116
 
117
  gr.Interface(
118
  convert_video,
119
- inputs=[video_file, quality, aspect_ratio, video_url, api_key, upload],
120
  outputs=gr.outputs.File(label="Download File"),
121
- live=True,
 
122
  ).launch()
123
 
124
-
125
-
126
  if __name__ == "__main__":
127
  main()
 
59
  logging.exception("An error occurred while uploading to web3.storage.")
60
  return f"An error occurred while uploading to web3.storage: {response.json()}"
61
 
62
+ def convert_video(video_file, quality, aspect_ratio, resolution, video_url, api_key, upload):
63
  """Converts a video to HLS format, adjusting the quality and aspect ratio as necessary."""
64
  with tempfile.TemporaryDirectory() as temp_dir:
65
  temp_dir = Path(temp_dir)
 
67
  output_path = get_output_path(input_path, temp_dir)
68
  aspect_ratio = get_aspect_ratio(input_path, aspect_ratio)
69
 
70
+ # Set default values if quality or aspect_ratio are None
71
+ quality = "27" if quality is None else quality
72
+ aspect_ratio = "1:1" if aspect_ratio is None else aspect_ratio
73
+
74
  ffmpeg_command = [
75
  "ffmpeg", "-i", str(input_path), "-c:v", "libx264", "-crf", str(quality),
76
  "-vf", f"scale=-1:720,setsar={aspect_ratio}", "-hls_time", "6",
 
108
  def main():
109
  video_file = gr.inputs.File(label="Video File")
110
  quality = gr.inputs.Dropdown(
111
+ choices=["18", "23", "27", "28", "32"], label="Quality", default="27")
112
  aspect_ratio = gr.inputs.Dropdown(
113
  choices=[None, "1:1", "4:3", "3:2", "5:4", "16:9", "21:9",
114
  "1.85:1", "2.35:1", "3:1", "360", "9:16", "16:9",
115
  "2:1", "1:2", "9:1"],
116
  label="Aspect Ratio", default=None)
117
+ resolution = gr.inputs.Dropdown(
118
+ choices=["Max", "Min"], label="Resolution", default="Max")
119
  video_url = gr.inputs.Textbox(label="Video URL")
120
  api_key = gr.inputs.Textbox(label="web3.storage API Key")
121
  upload = gr.inputs.Checkbox(label="Upload to web3.storage", default=False)
122
 
123
  gr.Interface(
124
  convert_video,
125
+ inputs=[video_file, quality, aspect_ratio, resolution, video_url, api_key, upload],
126
  outputs=gr.outputs.File(label="Download File"),
127
+ allow_flagging=False,
128
+ live=False,
129
  ).launch()
130
 
 
 
131
  if __name__ == "__main__":
132
  main()