Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import yt_dlp
|
|
4 |
from pydub import AudioSegment
|
5 |
import re
|
6 |
|
|
|
7 |
if not os.path.exists("downloads"):
|
8 |
os.makedirs("downloads")
|
9 |
|
@@ -43,8 +44,9 @@ def process_youtube_or_audio(url, recorded_audio):
|
|
43 |
ringtone_filename_m4r = f"downloads/{song_name}.m4r"
|
44 |
if not os.path.exists(ringtone_filename_m4r):
|
45 |
ringtone_audio = AudioSegment.from_file(mp3_filename)
|
46 |
-
|
47 |
-
ringtone_audio
|
|
|
48 |
|
49 |
return mp3_filename, ringtone_filename_m4r
|
50 |
|
@@ -52,10 +54,10 @@ def process_youtube_or_audio(url, recorded_audio):
|
|
52 |
print(f"Error: {e}")
|
53 |
return None, None
|
54 |
|
55 |
-
# Gradio UI
|
56 |
with gr.Blocks(css="""
|
57 |
body { font-family: Arial, sans-serif; text-align: center; }
|
58 |
-
.light-btn { background-color: #f0f0f0; color: #333; border: 2px solid #ccc; }
|
59 |
.light-btn:hover { background-color: #e0e0e0; }
|
60 |
""") as interface:
|
61 |
gr.HTML("""
|
@@ -74,7 +76,7 @@ with gr.Blocks(css="""
|
|
74 |
audio_record = gr.Audio(sources=["microphone"], type="filepath")
|
75 |
|
76 |
with gr.Row():
|
77 |
-
process_button = gr.Button("🎵 Create Ringtones",
|
78 |
|
79 |
with gr.Row():
|
80 |
with gr.Column(scale=1, min_width=250):
|
@@ -89,3 +91,4 @@ with gr.Blocks(css="""
|
|
89 |
|
90 |
interface.launch(share=True)
|
91 |
|
|
|
|
4 |
from pydub import AudioSegment
|
5 |
import re
|
6 |
|
7 |
+
# Create downloads directory safely
|
8 |
if not os.path.exists("downloads"):
|
9 |
os.makedirs("downloads")
|
10 |
|
|
|
44 |
ringtone_filename_m4r = f"downloads/{song_name}.m4r"
|
45 |
if not os.path.exists(ringtone_filename_m4r):
|
46 |
ringtone_audio = AudioSegment.from_file(mp3_filename)
|
47 |
+
# Trimming to 20 seconds (20000 milliseconds)
|
48 |
+
ringtone_audio = ringtone_audio[:20000] # 20 seconds
|
49 |
+
ringtone_audio.export(ringtone_filename_m4r, format="aac") # Export as AAC for M4R
|
50 |
|
51 |
return mp3_filename, ringtone_filename_m4r
|
52 |
|
|
|
54 |
print(f"Error: {e}")
|
55 |
return None, None
|
56 |
|
57 |
+
# Gradio UI with Improved Layout
|
58 |
with gr.Blocks(css="""
|
59 |
body { font-family: Arial, sans-serif; text-align: center; }
|
60 |
+
.light-btn { background-color: #f0f0f0; color: #333; border: 2px solid #ccc; padding: 10px 20px; font-size: 16px; cursor: pointer; }
|
61 |
.light-btn:hover { background-color: #e0e0e0; }
|
62 |
""") as interface:
|
63 |
gr.HTML("""
|
|
|
76 |
audio_record = gr.Audio(sources=["microphone"], type="filepath")
|
77 |
|
78 |
with gr.Row():
|
79 |
+
process_button = gr.Button("🎵 Create Ringtones", elem_classes="light-btn")
|
80 |
|
81 |
with gr.Row():
|
82 |
with gr.Column(scale=1, min_width=250):
|
|
|
91 |
|
92 |
interface.launch(share=True)
|
93 |
|
94 |
+
|