Vgjkmhf commited on
Commit
5031d1a
·
verified ·
1 Parent(s): 3c44ab0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -21
app.py CHANGED
@@ -16,15 +16,15 @@ from datetime import datetime
16
  # ==========================================
17
  # 1. تنظیمات اولیه
18
  # ==========================================
19
- print(">>> در حال راه‌اندازی سیستم RVC Pro Max...")
20
 
21
  try:
22
  import imageio_ffmpeg
23
  import static_ffmpeg
24
  from rvc_python.infer import RVCInference
25
- print(" کتابخانه‌های RVC با موفقیت بارگذاری شدند.")
26
  except ImportError as e:
27
- print(f" خطای بحرانی در ایمپورت: {e}")
28
  sys.exit(1)
29
 
30
  # تنظیم مسیر FFmpeg
@@ -33,7 +33,7 @@ try:
33
  ffmpeg_exe = imageio_ffmpeg.get_ffmpeg_exe()
34
  os.environ["PATH"] += os.pathsep + os.path.dirname(ffmpeg_exe)
35
  except Exception as e:
36
- print(f"⚠️ هشدار FFmpeg: {e}")
37
 
38
  TEMP_DIR = "/tmp/rvc_temp"
39
  os.makedirs(TEMP_DIR, exist_ok=True)
@@ -56,10 +56,8 @@ def apply_clarity_eq(y, sr):
56
  y = signal.sosfilt(sos_hp, y)
57
 
58
  # 2. کاهش فرکانس‌های تودماغی (حدود 1000 هرتز)
59
- # فیلتر Band-stop ملایم
60
  sos_mid = signal.butter(2, [800, 1200], 'bandstop', fs=sr, output='sos')
61
  y_filtered = signal.sosfilt(sos_mid, y)
62
- # ترکیب 30 درصد فیلتر شده با 70 درصد اصلی
63
  y = (y * 0.7) + (y_filtered * 0.3)
64
 
65
  # 3. High Boost (شفافیت)
@@ -80,9 +78,9 @@ def preprocess_audio(input_path):
80
  y = librosa.util.normalize(y)
81
  processed_path = os.path.join(TEMP_DIR, "preprocessed.wav")
82
  sf.write(processed_path, y, sr)
83
- return processed_path, f" صدا پیش‌پردازش شد (SR: {sr}Hz)"
84
  except Exception as e:
85
- return input_path, f"⚠️ خطا در پیش‌پردازش: {e}"
86
 
87
  def post_process_audio(input_path, clarity_boost=True):
88
  try:
@@ -115,12 +113,12 @@ def rvc_process_pipeline(
115
  enable_clarity
116
  ):
117
  logs = []
118
- logs.append(log_message("🚀 شروع عملیات تبدیل..."))
119
 
120
  if not audio_path:
121
- return None, " فایل صوتی انتخاب نشده است."
122
  if not model_file:
123
- return None, " فایل مدل انتخاب نشده است."
124
 
125
  try:
126
  cleanup_temp()
@@ -132,7 +130,7 @@ def rvc_process_pipeline(
132
  logs.append(log_message(msg))
133
 
134
  # بارگذاری مدل
135
- logs.append(log_message(f"📂 مدل: {os.path.basename(model_path)}"))
136
  rvc = RVCInference(device="cpu")
137
  rvc.load_model(model_path)
138
 
@@ -153,7 +151,7 @@ def rvc_process_pipeline(
153
  "hop_length": int(hop_length)
154
  }
155
 
156
- # فیلتر کردن پارامترهای نامعتبر برای جلوگیری از خطای نسخه
157
  sig = inspect.signature(rvc.infer_file)
158
  valid_keys = sig.parameters.keys()
159
 
@@ -161,13 +159,12 @@ def rvc_process_pipeline(
161
  for k, v in kwargs.items():
162
  if k in valid_keys:
163
  final_kwargs[k] = v
164
- # نگاشت نام‌های قدیمی به جدید
165
  elif k == "pitch" and "f0_up_key" in valid_keys:
166
  final_kwargs["f0_up_key"] = v
167
  elif k == "method" and "f0_method" in valid_keys:
168
  final_kwargs["f0_method"] = v
169
 
170
- logs.append(log_message(f"⚙️ متد: {f0_method}"))
171
 
172
  start_time = time.time()
173
  rvc.infer_file(**final_kwargs)
@@ -175,19 +172,23 @@ def rvc_process_pipeline(
175
  # پس‌پردازش
176
  final_output = output_temp
177
  if enable_clarity and os.path.exists(output_temp):
178
- logs.append(log_message(" اعمال فیلتر شفاف‌سازی..."))
179
  final_output = post_process_audio(output_temp, clarity_boost=True)
180
 
181
  duration = time.time() - start_time
182
- logs.append(log_message(f"✅ تمام شد! ({duration:.2f}s)"))
 
 
 
 
 
 
183
 
184
- # اینجا خطایی که داشتید رفع شده است:
185
- log_text = "
186
- ".join(logs)
187
  return final_output, log_text
188
 
189
  except Exception as e:
190
- err_msg = f"❌ خطا: {traceback.format_exc()}"
 
191
  print(err_msg)
192
  return None, err_msg
193
 
 
16
  # ==========================================
17
  # 1. تنظیمات اولیه
18
  # ==========================================
19
+ print(">>> System Startup: RVC Pro Max...")
20
 
21
  try:
22
  import imageio_ffmpeg
23
  import static_ffmpeg
24
  from rvc_python.infer import RVCInference
25
+ print("Libraries loaded successfully.")
26
  except ImportError as e:
27
+ print(f"Import Error: {e}")
28
  sys.exit(1)
29
 
30
  # تنظیم مسیر FFmpeg
 
33
  ffmpeg_exe = imageio_ffmpeg.get_ffmpeg_exe()
34
  os.environ["PATH"] += os.pathsep + os.path.dirname(ffmpeg_exe)
35
  except Exception as e:
36
+ print(f"FFmpeg Warning: {e}")
37
 
38
  TEMP_DIR = "/tmp/rvc_temp"
39
  os.makedirs(TEMP_DIR, exist_ok=True)
 
56
  y = signal.sosfilt(sos_hp, y)
57
 
58
  # 2. کاهش فرکانس‌های تودماغی (حدود 1000 هرتز)
 
59
  sos_mid = signal.butter(2, [800, 1200], 'bandstop', fs=sr, output='sos')
60
  y_filtered = signal.sosfilt(sos_mid, y)
 
61
  y = (y * 0.7) + (y_filtered * 0.3)
62
 
63
  # 3. High Boost (شفافیت)
 
78
  y = librosa.util.normalize(y)
79
  processed_path = os.path.join(TEMP_DIR, "preprocessed.wav")
80
  sf.write(processed_path, y, sr)
81
+ return processed_path, f"Pre-process OK (SR: {sr}Hz)"
82
  except Exception as e:
83
+ return input_path, f"Pre-process Error: {e}"
84
 
85
  def post_process_audio(input_path, clarity_boost=True):
86
  try:
 
113
  enable_clarity
114
  ):
115
  logs = []
116
+ logs.append(log_message("Starting conversion..."))
117
 
118
  if not audio_path:
119
+ return None, "Error: No audio file."
120
  if not model_file:
121
+ return None, "Error: No model file."
122
 
123
  try:
124
  cleanup_temp()
 
130
  logs.append(log_message(msg))
131
 
132
  # بارگذاری مدل
133
+ logs.append(log_message(f"Model: {os.path.basename(model_path)}"))
134
  rvc = RVCInference(device="cpu")
135
  rvc.load_model(model_path)
136
 
 
151
  "hop_length": int(hop_length)
152
  }
153
 
154
+ # فیلتر کردن پارامترهای نامعتبر
155
  sig = inspect.signature(rvc.infer_file)
156
  valid_keys = sig.parameters.keys()
157
 
 
159
  for k, v in kwargs.items():
160
  if k in valid_keys:
161
  final_kwargs[k] = v
 
162
  elif k == "pitch" and "f0_up_key" in valid_keys:
163
  final_kwargs["f0_up_key"] = v
164
  elif k == "method" and "f0_method" in valid_keys:
165
  final_kwargs["f0_method"] = v
166
 
167
+ logs.append(log_message(f"Method: {f0_method}"))
168
 
169
  start_time = time.time()
170
  rvc.infer_file(**final_kwargs)
 
172
  # پس‌پردازش
173
  final_output = output_temp
174
  if enable_clarity and os.path.exists(output_temp):
175
+ logs.append(log_message("Applying clarity filter..."))
176
  final_output = post_process_audio(output_temp, clarity_boost=True)
177
 
178
  duration = time.time() - start_time
179
+ logs.append(log_message(f"Done! ({duration:.2f}s)"))
180
+
181
+ # === رفع خطای Syntax Error ===
182
+ # استفاده از chr(10) به جای "
183
+ " برای جلوگیری از شکستن خط در کپی
184
+ separator = chr(10)
185
+ log_text = separator.join(logs)
186
 
 
 
 
187
  return final_output, log_text
188
 
189
  except Exception as e:
190
+ separator = chr(10)
191
+ err_msg = f"Error: {traceback.format_exc()}"
192
  print(err_msg)
193
  return None, err_msg
194