Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,29 +3,38 @@ from pydub import AudioSegment
|
|
| 3 |
from pydub.effects import normalize, compress_dynamic_range
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
def
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
# واجهة بسيطة لاستقبال الملفات من n8n
|
| 26 |
demo = gr.Interface(
|
| 27 |
-
fn=
|
| 28 |
-
inputs=[gr.
|
| 29 |
-
outputs=gr.
|
| 30 |
)
|
|
|
|
| 31 |
demo.launch()
|
|
|
|
| 3 |
from pydub.effects import normalize, compress_dynamic_range
|
| 4 |
import os
|
| 5 |
|
| 6 |
+
def process_audio(vocal_file, music_file):
|
| 7 |
+
try:
|
| 8 |
+
if vocal_file is None or music_file is None:
|
| 9 |
+
return "الرجاء رفع الملفين أولاً (صوتك + الموسيقى)"
|
| 10 |
+
|
| 11 |
+
# تحميل الملفات
|
| 12 |
+
vocals = AudioSegment.from_file(vocal_file.name)
|
| 13 |
+
music = AudioSegment.from_file(music_file.name)
|
| 14 |
+
|
| 15 |
+
# المعالجة الاحترافية
|
| 16 |
+
vocals = normalize(vocals)
|
| 17 |
+
vocals = compress_dynamic_range(vocals, threshold=-20.0, ratio=4.0)
|
| 18 |
+
|
| 19 |
+
if len(music) < len(vocals):
|
| 20 |
+
music = music * ((len(vocals) // len(music)) + 1)
|
| 21 |
+
|
| 22 |
+
music = music[:len(vocals) + 2000] - 10
|
| 23 |
+
final_mix = music.overlay(vocals, position=0)
|
| 24 |
+
final_mix = normalize(final_mix).fade_out(2000)
|
| 25 |
+
|
| 26 |
+
output_path = "final_master.mp3"
|
| 27 |
+
final_mix.export(output_path, format="mp3", bitrate="320k")
|
| 28 |
+
return output_path
|
| 29 |
+
|
| 30 |
+
except Exception as e:
|
| 31 |
+
# هذا السطر سيظهر لك الخطأ الحقيقي في واجهة Hugging Face
|
| 32 |
+
return f"حدث خطأ تقني: {str(e)}"
|
| 33 |
|
|
|
|
| 34 |
demo = gr.Interface(
|
| 35 |
+
fn=process_audio,
|
| 36 |
+
inputs=[gr.File(label="ارفع صوتك هنا"), gr.File(label="ارفع الموسيقى هنا")],
|
| 37 |
+
outputs=gr.File(label="تحميل الأغنية النهائية")
|
| 38 |
)
|
| 39 |
+
|
| 40 |
demo.launch()
|