Jeffgold commited on
Commit
74c86d6
·
1 Parent(s): d8d77f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -5
app.py CHANGED
@@ -1,7 +1,36 @@
1
  import gradio as gr
 
 
2
 
3
- # Create a space.
4
- space = gr.create_space("my-space")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  # Upload the video file to the space.
7
  space.upload_file("/path/to/NEARHUBanimation.mp4")
@@ -9,9 +38,9 @@ space.upload_file("/path/to/NEARHUBanimation.mp4")
9
  # Transcode the video file.
10
  space.run_script("transcode_video.py")
11
 
12
- # Launch a gradio interface that allows you to play the transcoded video file.
13
- demo = gr.Interface(transcode_video,
14
- gr.components.Video(),
15
  "playable_video",
16
  examples=video_files,
17
  cache_examples=True)
 
1
  import gradio as gr
2
+ from gradio.components import Video
3
+ import os
4
 
5
+ from ffmpeg.input import Input
6
+
7
+ def transcode_video(video_path):
8
+ """Transcodes a video file to m3u8 using ffmpeg.
9
+ Args:
10
+ video_path: The path to the video file to transcode.
11
+ Returns:
12
+ The path to the transcoded file.
13
+ """
14
+
15
+ # Create a folder to save the transcoded video file to.
16
+ output_dir = os.path.dirname(video_path)
17
+ if not os.path.exists(output_dir):
18
+ os.makedirs(output_dir)
19
+
20
+ # Transcode the video file.
21
+ output_file = os.path.join(output_dir, f"{video_path.split('/')[-1]}.m3u8" )
22
+ Input(video_path).output(output_file, format="hls").run()
23
+
24
+ # Return the path to the transcoded file.
25
+ return output_file
26
+
27
+
28
+ video_files = [
29
+ "/path/to/NEARHUBanimation.mp4",
30
+ ]
31
+
32
+ # Create a huggingface space.
33
+ space = hfs.create_space("my-space")
34
 
35
  # Upload the video file to the space.
36
  space.upload_file("/path/to/NEARHUBanimation.mp4")
 
38
  # Transcode the video file.
39
  space.run_script("transcode_video.py")
40
 
41
+ # Launch a huggingface interface that allows you to play the transcoded video file.
42
+ demo = hfs.Interface(transcode_video,
43
+ hfs.components.Video(),
44
  "playable_video",
45
  examples=video_files,
46
  cache_examples=True)