howe commited on
Commit
56c0fff
·
1 Parent(s): d5bb448
Files changed (2) hide show
  1. pages/audio2video_single.py +31 -0
  2. requirements.txt +1 -0
pages/audio2video_single.py CHANGED
@@ -2,6 +2,7 @@ import os
2
  from typing import List, Optional
3
 
4
  import gradio as gr
 
5
 
6
  from pages.base_page import BasePage
7
  from utils.ossutils import upload_to_oss
@@ -50,6 +51,7 @@ class Audio2VideoSinglePage(BasePage):
50
  sources=["upload"],
51
  type="filepath",
52
  )
 
53
 
54
  return [
55
  prompt,
@@ -57,6 +59,21 @@ class Audio2VideoSinglePage(BasePage):
57
  audio_input,
58
  ]
59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  def _build_payload(
61
  self,
62
  prompt: str,
@@ -70,6 +87,20 @@ class Audio2VideoSinglePage(BasePage):
70
  if not audio_path:
71
  raise ValueError("Please upload an audio file.")
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  # Upload image to OSS
74
  if isinstance(image_path, str) and image_path.startswith("http"):
75
  image_url = image_path
 
2
  from typing import List, Optional
3
 
4
  import gradio as gr
5
+ from mutagen import File
6
 
7
  from pages.base_page import BasePage
8
  from utils.ossutils import upload_to_oss
 
51
  sources=["upload"],
52
  type="filepath",
53
  )
54
+ audio_input.change(fn=self.check_audio_duration, inputs=audio_input, outputs=None)
55
 
56
  return [
57
  prompt,
 
59
  audio_input,
60
  ]
61
 
62
+ def check_audio_duration(self, audio_path: str):
63
+ if not audio_path:
64
+ return
65
+
66
+ try:
67
+ audio = File(audio_path)
68
+ if audio is not None and audio.info is not None:
69
+ duration = audio.info.length
70
+ if duration > 30:
71
+ gr.Warning(
72
+ "Space only supports audio up to 30s. To experience longer duration, please use the SkyReels API (https://platform.skyreels.ai/ )"
73
+ )
74
+ except Exception as e:
75
+ print(f"Error checking duration: {e}")
76
+
77
  def _build_payload(
78
  self,
79
  prompt: str,
 
87
  if not audio_path:
88
  raise ValueError("Please upload an audio file.")
89
 
90
+ # Check audio duration
91
+ try:
92
+ audio = File(audio_path)
93
+ if audio is not None and audio.info is not None:
94
+ duration = audio.info.length
95
+ if duration > 30:
96
+ raise gr.Error(
97
+ "Space only supports audio up to 30s. To experience longer duration, please use the SkyReels API (https://platform.skyreels.ai/ )"
98
+ )
99
+ except Exception as e:
100
+ if isinstance(e, gr.Error):
101
+ raise e
102
+ print(f"Error checking duration: {e}")
103
+
104
  # Upload image to OSS
105
  if isinstance(image_path, str) and image_path.startswith("http"):
106
  image_url = image_path
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  oss2
2
  retry
3
  gradio==6.4.0
 
 
1
  oss2
2
  retry
3
  gradio==6.4.0
4
+ mutagen