Jeffgold commited on
Commit
15d3f13
·
1 Parent(s): 694d859

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -50,7 +50,7 @@ def upload_to_web3_storage(api_key, path):
50
  cid = storage.put_file(f)
51
  return f"https://dweb.link/ipfs/{cid}"
52
 
53
- def convert_video(video_file, quality, aspect_ratio, video_url, api_key, web3_upload):
54
  """Converts a video to HLS format, adjusting the quality and aspect ratio as necessary."""
55
  with tempfile.TemporaryDirectory() as temp_dir:
56
  temp_dir = Path(temp_dir)
@@ -84,12 +84,10 @@ def convert_video(video_file, quality, aspect_ratio, video_url, api_key, web3_up
84
  # TemporaryDirectory context manager exits.
85
  output_copy_path = shutil.copy2(output_path, tempfile.gettempdir())
86
 
87
- # If the user wants to upload to web3, do that and return the URL.
88
- # Otherwise, just return the local path.
89
- if web3_upload:
90
- return upload_to_web3_storage(api_key, output_copy_path)
91
- else:
92
- return output_copy_path
93
 
94
  def main():
95
  video_file = gr.inputs.File(label="Video File", type="file")
@@ -102,9 +100,13 @@ def main():
102
  label="Aspect Ratio", default=None)
103
  video_url = gr.inputs.Textbox(label="Video URL")
104
  api_key = gr.inputs.Textbox(label="web3.storage API Key")
105
- web3_upload = gr.inputs.Checkbox(label="Upload to web3.storage")
106
 
107
- gr.Interface(convert_video, inputs=[video_file, quality, aspect_ratio, video_url, api_key, web3_upload], outputs='text').launch()
 
 
 
 
108
 
109
  if __name__ == "__main__":
110
  main()
 
50
  cid = storage.put_file(f)
51
  return f"https://dweb.link/ipfs/{cid}"
52
 
53
+ def convert_video(video_file, quality, aspect_ratio, video_url, api_key, upload):
54
  """Converts a video to HLS format, adjusting the quality and aspect ratio as necessary."""
55
  with tempfile.TemporaryDirectory() as temp_dir:
56
  temp_dir = Path(temp_dir)
 
84
  # TemporaryDirectory context manager exits.
85
  output_copy_path = shutil.copy2(output_path, tempfile.gettempdir())
86
 
87
+ if upload:
88
+ return upload_to_web3_storage(api_key, output_copy_path)
89
+ else:
90
+ return output_copy_path
 
 
91
 
92
  def main():
93
  video_file = gr.inputs.File(label="Video File", type="file")
 
100
  label="Aspect Ratio", default=None)
101
  video_url = gr.inputs.Textbox(label="Video URL")
102
  api_key = gr.inputs.Textbox(label="web3.storage API Key")
103
+ upload = gr.inputs.Checkbox(label="Upload to web3.storage", default=False)
104
 
105
+ gr.Interface(
106
+ convert_video,
107
+ inputs=[video_file, quality, aspect_ratio, video_url, api_key, upload],
108
+ outputs='text'
109
+ ).launch()
110
 
111
  if __name__ == "__main__":
112
  main()