Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import shutil
|
| 4 |
+
from rvc_python.infer import RVCInference
|
| 5 |
+
|
| 6 |
+
# ایجاد پوشه برای ذخیره فایلهای موقت
|
| 7 |
+
os.makedirs("temp_models", exist_ok=True)
|
| 8 |
+
|
| 9 |
+
def rvc_process(audio_path, model_file, index_file, pitch_change, f0_method):
|
| 10 |
+
if not audio_path:
|
| 11 |
+
return None, "⚠️ لطفاً ابتدا یک فایل صوتی ضبط یا آپلود کنید."
|
| 12 |
+
|
| 13 |
+
if not model_file:
|
| 14 |
+
return None, "⚠️ لطفاً فایل مدل (.pth) را آپلود کنید."
|
| 15 |
+
|
| 16 |
+
try:
|
| 17 |
+
# تعیین مسیر فایل مدل آپلود شده
|
| 18 |
+
# در Gradio جدید، فایل آپلود شده یک آبجکت است که مسیر آن در .name قرار دارد
|
| 19 |
+
model_path = model_file.name
|
| 20 |
+
|
| 21 |
+
# بررسی وجود ایندکس
|
| 22 |
+
index_path = None
|
| 23 |
+
if index_file:
|
| 24 |
+
index_path = index_file.name
|
| 25 |
+
|
| 26 |
+
print(f"Processing: Model={model_path}, Audio={audio_path}")
|
| 27 |
+
|
| 28 |
+
# بارگذاری RVC
|
| 29 |
+
# نکته مهم: در فضای رایگان device="cpu" است. اگر GPU خریدید به "cuda" تغییر دهید.
|
| 30 |
+
rvc = RVCInference(device="cpu")
|
| 31 |
+
|
| 32 |
+
# لود کردن مدل
|
| 33 |
+
rvc.load_model(model_path)
|
| 34 |
+
|
| 35 |
+
output_path = "output.wav"
|
| 36 |
+
|
| 37 |
+
# اجرای تبدیل صدا
|
| 38 |
+
rvc.infer_file(
|
| 39 |
+
input_path=audio_path,
|
| 40 |
+
output_path=output_path,
|
| 41 |
+
f0_up_key=int(pitch_change),
|
| 42 |
+
index_path=index_path,
|
| 43 |
+
f0_method=f0_method,
|
| 44 |
+
index_rate=0.75 if index_path else 0,
|
| 45 |
+
protect=0.33
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
return output_path, "✅ تبدیل با موفقیت انجام شد!"
|
| 49 |
+
|
| 50 |
+
except Exception as e:
|
| 51 |
+
return None, f"❌ خطا: {str(e)}"
|
| 52 |
+
|
| 53 |
+
# رابط کاربری
|
| 54 |
+
with gr.Interface(
|
| 55 |
+
fn=rvc_process,
|
| 56 |
+
inputs=[
|
| 57 |
+
gr.Audio(type="filepath", label="1. صدای ورودی (ضبط یا آپلود)"),
|
| 58 |
+
gr.File(label="2. فایل مدل (.pth)", file_count="single", file_types=[".pth"]),
|
| 59 |
+
gr.File(label="3. فایل ایندکس (.index) - اختیاری", file_count="single", file_types=[".index"]),
|
| 60 |
+
gr.Slider(minimum=-12, maximum=12, step=1, value=0, label="تغییر گام (Pitch)"),
|
| 61 |
+
gr.Dropdown(choices=["rmvpe", "pm"], value="rmvpe", label="الگوریتم (rmvpe کندتر اما باکیفیتتر)")
|
| 62 |
+
],
|
| 63 |
+
outputs=[
|
| 64 |
+
gr.Audio(label="خروجی نهایی"),
|
| 65 |
+
gr.Textbox(label="وضعیت")
|
| 66 |
+
],
|
| 67 |
+
title="RVC Web Inference",
|
| 68 |
+
description="تبدیل صدا با آپلود مستقیم فایل مدل (.pth). به دلیل استفاده از CPU در نسخه رایگان، پردازش ممکن است کمی طول بکشد."
|
| 69 |
+
) as demo:
|
| 70 |
+
demo.launch()
|