Vgjkmhf commited on
Commit
92f6db2
·
verified ·
1 Parent(s): 2d08bc4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -46
app.py CHANGED
@@ -7,11 +7,9 @@ import numpy as np
7
  import soundfile as sf
8
  import librosa
9
  import gradio as gr
10
- from scipy.signal import butter, lfilter, iirpeak
11
 
12
- # ==========================================
13
- # 1. تنظیمات
14
- # ==========================================
15
  try:
16
  import imageio_ffmpeg
17
  import static_ffmpeg
@@ -28,24 +26,19 @@ TEMP_DIR = "/tmp/rvc_studio"
28
  os.makedirs(TEMP_DIR, exist_ok=True)
29
  os.environ["TEMP"] = TEMP_DIR
30
 
31
- # ==========================================
32
- # 2. پردازش صدا
33
- # ==========================================
34
-
35
  def anti_muffle_filter(y, sr):
36
  try:
37
  b, a = iirpeak(600, Q=1.5, fs=sr, ftype='notch')
38
  return lfilter(b, a, y)
39
- except:
40
- return y
41
 
42
  def clarity_boost(y, sr):
43
  try:
44
  b, a = iirpeak(8000, Q=0.7, fs=sr, ftype='peak')
45
  boosted = lfilter(b, a, y)
46
  return (y * 0.7) + (boosted * 0.3)
47
- except:
48
- return y
49
 
50
  def preprocess_audio(input_path):
51
  try:
@@ -65,14 +58,11 @@ def postprocess_audio(input_path):
65
  y = librosa.util.normalize(y) * 0.95
66
  post_path = os.path.join(TEMP_DIR, "postprocessed.wav")
67
  sf.write(post_path, y, sr)
68
- return post_path, "✅ Postprocess Done (Clarity Boost)"
69
  except Exception as e:
70
  return input_path, f"⚠️ Postprocess Warning: {e}"
71
 
72
- # ==========================================
73
- # 3. پایپ‌لاین RVC
74
- # ==========================================
75
-
76
  def rvc_process_pipeline(
77
  audio_path, model_file, index_file, pitch_change, f0_method,
78
  index_rate, protect_val, filter_radius, resample_sr, envelope_mix, hop_length
@@ -94,10 +84,8 @@ def rvc_process_pipeline(
94
 
95
  if "pitch" in params: kwargs["pitch"] = int(pitch_change)
96
  elif "f0_up_key" in params: kwargs["f0_up_key"] = int(pitch_change)
97
-
98
  if "method" in params: kwargs["method"] = f0_method
99
  elif "f0_method" in params: kwargs["f0_method"] = f0_method
100
-
101
  if "index_path" in params and index_file: kwargs["index_path"] = index_file.name
102
  if "index_rate" in params: kwargs["index_rate"] = float(index_rate)
103
  if "protect" in params: kwargs["protect"] = float(protect_val)
@@ -108,14 +96,14 @@ def rvc_process_pipeline(
108
 
109
  print(f"Running: {kwargs}")
110
  rvc.infer_file(**kwargs)
111
- log2 = "✅ RVC Conversion Done"
112
 
113
  final_output, log3 = postprocess_audio(rvc_out_path)
114
 
115
- # اصلاح خطی که باعث ارور میشد
116
- full_log = str(log1) + "
117
- " + str(log2) + "
118
- " + str(log3)
119
  return final_output, full_log
120
 
121
  except Exception as e:
@@ -123,48 +111,36 @@ def rvc_process_pipeline(
123
  print(err)
124
  return None, err
125
 
126
- # ==========================================
127
- # 4. رابط کاربری
128
- # ==========================================
129
-
130
  with gr.Blocks(title="RVC Studio Pro", theme=gr.themes.Soft()) as demo:
131
  gr.Markdown("# 🎙️ RVC Studio Pro")
132
 
133
  with gr.Row():
134
  with gr.Column(scale=1):
135
- audio_in = gr.Audio(label="Input Audio", type="filepath")
136
  with gr.Row():
137
- model_in = gr.File(label="Model .pth", file_types=[".pth"])
138
- index_in = gr.File(label="Index .index", file_types=[".index"])
139
 
140
  pitch = gr.Slider(-24, 24, value=0, step=1, label="Pitch")
141
- method = gr.Dropdown(
142
- ["rmvpe", "harvest", "crepe", "pm"],
143
- value="harvest",
144
- label="Algorithm"
145
- )
146
- btn = gr.Button("✨ Start Process", variant="primary")
147
 
148
  with gr.Column(scale=1):
149
- audio_out = gr.Audio(label="Output Audio")
150
  status = gr.Textbox(label="Logs", lines=5)
151
 
152
- with gr.Accordion("Advanced Settings", open=True):
153
  with gr.Tab("Quality"):
154
  index_rate = gr.Slider(0, 1, value=0.3, label="Index Rate")
155
  protect = gr.Slider(0, 0.5, value=0.45, label="Protect")
156
  filter_radius = gr.Slider(0, 7, value=3, label="Filter Radius")
157
-
158
  with gr.Tab("Clarity"):
159
- envelope_mix = gr.Slider(0, 1, value=0.25, label="Volume Mix")
160
  hop_length = gr.Slider(32, 256, value=64, step=32, label="Hop Length")
161
  resample_sr = gr.Slider(0, 48000, value=40000, step=8000, label="Resample SR")
162
 
163
- btn.click(
164
- rvc_process_pipeline,
165
- inputs=[audio_in, model_in, index_in, pitch, method, index_rate, protect, filter_radius, resample_sr, envelope_mix, hop_length],
166
- outputs=[audio_out, status]
167
- )
168
 
169
  if __name__ == "__main__":
170
  demo.queue().launch(server_name="0.0.0.0", server_port=7860)
 
7
  import soundfile as sf
8
  import librosa
9
  import gradio as gr
10
+ from scipy.signal import iirpeak, lfilter
11
 
12
+ # 1. Setup
 
 
13
  try:
14
  import imageio_ffmpeg
15
  import static_ffmpeg
 
26
  os.makedirs(TEMP_DIR, exist_ok=True)
27
  os.environ["TEMP"] = TEMP_DIR
28
 
29
+ # 2. DSP Functions
 
 
 
30
  def anti_muffle_filter(y, sr):
31
  try:
32
  b, a = iirpeak(600, Q=1.5, fs=sr, ftype='notch')
33
  return lfilter(b, a, y)
34
+ except: return y
 
35
 
36
  def clarity_boost(y, sr):
37
  try:
38
  b, a = iirpeak(8000, Q=0.7, fs=sr, ftype='peak')
39
  boosted = lfilter(b, a, y)
40
  return (y * 0.7) + (boosted * 0.3)
41
+ except: return y
 
42
 
43
  def preprocess_audio(input_path):
44
  try:
 
58
  y = librosa.util.normalize(y) * 0.95
59
  post_path = os.path.join(TEMP_DIR, "postprocessed.wav")
60
  sf.write(post_path, y, sr)
61
+ return post_path, "✅ Postprocess Done"
62
  except Exception as e:
63
  return input_path, f"⚠️ Postprocess Warning: {e}"
64
 
65
+ # 3. Pipeline
 
 
 
66
  def rvc_process_pipeline(
67
  audio_path, model_file, index_file, pitch_change, f0_method,
68
  index_rate, protect_val, filter_radius, resample_sr, envelope_mix, hop_length
 
84
 
85
  if "pitch" in params: kwargs["pitch"] = int(pitch_change)
86
  elif "f0_up_key" in params: kwargs["f0_up_key"] = int(pitch_change)
 
87
  if "method" in params: kwargs["method"] = f0_method
88
  elif "f0_method" in params: kwargs["f0_method"] = f0_method
 
89
  if "index_path" in params and index_file: kwargs["index_path"] = index_file.name
90
  if "index_rate" in params: kwargs["index_rate"] = float(index_rate)
91
  if "protect" in params: kwargs["protect"] = float(protect_val)
 
96
 
97
  print(f"Running: {kwargs}")
98
  rvc.infer_file(**kwargs)
99
+ log2 = "✅ RVC Done"
100
 
101
  final_output, log3 = postprocess_audio(rvc_out_path)
102
 
103
+ # --- اصلاح خط مشکل‌دار ---
104
+ full_log = "
105
+ ".join([str(log1), str(log2), str(log3)])
106
+
107
  return final_output, full_log
108
 
109
  except Exception as e:
 
111
  print(err)
112
  return None, err
113
 
114
+ # 4. UI
 
 
 
115
  with gr.Blocks(title="RVC Studio Pro", theme=gr.themes.Soft()) as demo:
116
  gr.Markdown("# 🎙️ RVC Studio Pro")
117
 
118
  with gr.Row():
119
  with gr.Column(scale=1):
120
+ audio_in = gr.Audio(label="Input", type="filepath")
121
  with gr.Row():
122
+ model_in = gr.File(label="Model", file_types=[".pth"])
123
+ index_in = gr.File(label="Index", file_types=[".index"])
124
 
125
  pitch = gr.Slider(-24, 24, value=0, step=1, label="Pitch")
126
+ method = gr.Dropdown(["rmvpe", "harvest", "crepe", "pm"], value="harvest", label="Algo")
127
+ btn = gr.Button(" Start", variant="primary")
 
 
 
 
128
 
129
  with gr.Column(scale=1):
130
+ audio_out = gr.Audio(label="Output")
131
  status = gr.Textbox(label="Logs", lines=5)
132
 
133
+ with gr.Accordion("Settings", open=True):
134
  with gr.Tab("Quality"):
135
  index_rate = gr.Slider(0, 1, value=0.3, label="Index Rate")
136
  protect = gr.Slider(0, 0.5, value=0.45, label="Protect")
137
  filter_radius = gr.Slider(0, 7, value=3, label="Filter Radius")
 
138
  with gr.Tab("Clarity"):
139
+ envelope_mix = gr.Slider(0, 1, value=0.25, label="Vol Mix")
140
  hop_length = gr.Slider(32, 256, value=64, step=32, label="Hop Length")
141
  resample_sr = gr.Slider(0, 48000, value=40000, step=8000, label="Resample SR")
142
 
143
+ btn.click(rvc_process_pipeline, inputs=[audio_in, model_in, index_in, pitch, method, index_rate, protect, filter_radius, resample_sr, envelope_mix, hop_length], outputs=[audio_out, status])
 
 
 
 
144
 
145
  if __name__ == "__main__":
146
  demo.queue().launch(server_name="0.0.0.0", server_port=7860)