Spaces:
Paused
Paused
Update app2.py
Browse files
app2.py
CHANGED
|
@@ -36,8 +36,13 @@ def download_audio(url, file_format, duration_sec):
|
|
| 36 |
|
| 37 |
# Load audio and trim to duration
|
| 38 |
audio = AudioSegment.from_file(original_file)
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
# Determine output file path based on desired format
|
| 43 |
base_name = os.path.splitext(original_file)[0]
|
|
@@ -71,7 +76,7 @@ def download_audio(url, file_format, duration_sec):
|
|
| 71 |
raise gr.Error(f"Error downloading audio: {str(e)}")
|
| 72 |
|
| 73 |
# Create Gradio interface
|
| 74 |
-
with gr.Blocks(title="Audio Downloader"
|
| 75 |
gr.Markdown("# 🎵 YouTube & SoundCloud Audio Downloader")
|
| 76 |
gr.Markdown("Download audio from YouTube or SoundCloud and convert to your preferred format")
|
| 77 |
|
|
@@ -92,7 +97,7 @@ with gr.Blocks(title="Audio Downloader", theme=gr.themes.Soft()) as iface:
|
|
| 92 |
|
| 93 |
with gr.Column(scale=3):
|
| 94 |
duration_slider = gr.Slider(
|
| 95 |
-
minimum=
|
| 96 |
maximum=600, # Increased to 10 minutes
|
| 97 |
value=60,
|
| 98 |
step=5,
|
|
@@ -125,7 +130,7 @@ with gr.Blocks(title="Audio Downloader", theme=gr.themes.Soft()) as iface:
|
|
| 125 |
### How to use:
|
| 126 |
1. Paste a YouTube or SoundCloud URL
|
| 127 |
2. Choose your desired output format
|
| 128 |
-
3. Set the maximum duration (or
|
| 129 |
4. Click "Download Audio"
|
| 130 |
|
| 131 |
### Supported formats:
|
|
@@ -138,6 +143,7 @@ with gr.Blocks(title="Audio Downloader", theme=gr.themes.Soft()) as iface:
|
|
| 138 |
- Downloads are saved to a 'downloads' folder
|
| 139 |
- Some tracks may have download restrictions
|
| 140 |
- Very long videos may take time to process
|
|
|
|
| 141 |
""")
|
| 142 |
|
| 143 |
download_button.click(
|
|
@@ -150,8 +156,10 @@ with gr.Blocks(title="Audio Downloader", theme=gr.themes.Soft()) as iface:
|
|
| 150 |
# Launch the interface
|
| 151 |
if __name__ == "__main__":
|
| 152 |
iface.launch(
|
|
|
|
| 153 |
show_error=True,
|
| 154 |
share=False, # Set to True to create a public link
|
| 155 |
server_name="0.0.0.0" if os.getenv("GRADIO_SHARE") else "127.0.0.1",
|
| 156 |
-
server_port=7860
|
|
|
|
| 157 |
)
|
|
|
|
| 36 |
|
| 37 |
# Load audio and trim to duration
|
| 38 |
audio = AudioSegment.from_file(original_file)
|
| 39 |
+
|
| 40 |
+
# Handle duration parameter
|
| 41 |
+
if duration_sec > 0:
|
| 42 |
+
duration_ms = min(len(audio), int(duration_sec * 1000))
|
| 43 |
+
trimmed_audio = audio[:duration_ms]
|
| 44 |
+
else:
|
| 45 |
+
trimmed_audio = audio # Full track if duration is 0
|
| 46 |
|
| 47 |
# Determine output file path based on desired format
|
| 48 |
base_name = os.path.splitext(original_file)[0]
|
|
|
|
| 76 |
raise gr.Error(f"Error downloading audio: {str(e)}")
|
| 77 |
|
| 78 |
# Create Gradio interface
|
| 79 |
+
with gr.Blocks(title="Audio Downloader") as iface:
|
| 80 |
gr.Markdown("# 🎵 YouTube & SoundCloud Audio Downloader")
|
| 81 |
gr.Markdown("Download audio from YouTube or SoundCloud and convert to your preferred format")
|
| 82 |
|
|
|
|
| 97 |
|
| 98 |
with gr.Column(scale=3):
|
| 99 |
duration_slider = gr.Slider(
|
| 100 |
+
minimum=0,
|
| 101 |
maximum=600, # Increased to 10 minutes
|
| 102 |
value=60,
|
| 103 |
step=5,
|
|
|
|
| 130 |
### How to use:
|
| 131 |
1. Paste a YouTube or SoundCloud URL
|
| 132 |
2. Choose your desired output format
|
| 133 |
+
3. Set the maximum duration (or set to 0 for full track)
|
| 134 |
4. Click "Download Audio"
|
| 135 |
|
| 136 |
### Supported formats:
|
|
|
|
| 143 |
- Downloads are saved to a 'downloads' folder
|
| 144 |
- Some tracks may have download restrictions
|
| 145 |
- Very long videos may take time to process
|
| 146 |
+
- Minimum duration is now 0 (for full tracks)
|
| 147 |
""")
|
| 148 |
|
| 149 |
download_button.click(
|
|
|
|
| 156 |
# Launch the interface
|
| 157 |
if __name__ == "__main__":
|
| 158 |
iface.launch(
|
| 159 |
+
theme=gr.themes.Soft(),
|
| 160 |
show_error=True,
|
| 161 |
share=False, # Set to True to create a public link
|
| 162 |
server_name="0.0.0.0" if os.getenv("GRADIO_SHARE") else "127.0.0.1",
|
| 163 |
+
server_port=7860,
|
| 164 |
+
ssr_mode=False # Disable SSR to avoid the warning
|
| 165 |
)
|