Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -72,6 +72,25 @@ def compare_pitch(original_audio, processed_audio, sr=16000):
|
|
| 72 |
else:
|
| 73 |
print("Could not extract pitch from one of the signals.")
|
| 74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
| 76 |
pipeline = AuffusionPipeline.from_pretrained("auffusion/auffusion")
|
| 77 |
prompt = prompt
|
|
@@ -120,6 +139,8 @@ def infer_img2img(prompt, audio_path, desired_strength, progress=gr.Progress(tra
|
|
| 120 |
else:
|
| 121 |
print(f"✅ Spectrogram looks normal (Mean: {spec_mean_before}). No boost needed.")
|
| 122 |
|
|
|
|
|
|
|
| 123 |
# Normalize the spectrogram
|
| 124 |
norm_spec = normalize_spectrogram(spec)
|
| 125 |
|
|
|
|
| 72 |
else:
|
| 73 |
print("Could not extract pitch from one of the signals.")
|
| 74 |
|
| 75 |
+
def adjust_spectrogram_mean(spec, target_mean=-5.0):
|
| 76 |
+
# Calculate the current mean of the spectrogram
|
| 77 |
+
current_mean = spec.mean().item()
|
| 78 |
+
|
| 79 |
+
# If the current mean is below the target mean, shift the values up
|
| 80 |
+
if current_mean < target_mean:
|
| 81 |
+
shift_value = target_mean - current_mean
|
| 82 |
+
print(f"Current mean: {current_mean}. Shifting by: {shift_value}")
|
| 83 |
+
|
| 84 |
+
# Shift the entire spectrogram by the calculated shift value
|
| 85 |
+
adjusted_spec = spec + shift_value
|
| 86 |
+
|
| 87 |
+
# Ensure that the adjusted values are still valid (in the expected range)
|
| 88 |
+
adjusted_spec = torch.clamp(adjusted_spec, min=0.0) # Optional: prevent negative values if needed
|
| 89 |
+
return adjusted_spec
|
| 90 |
+
else:
|
| 91 |
+
print(f"Current mean: {current_mean}. No adjustment needed.")
|
| 92 |
+
return spec
|
| 93 |
+
|
| 94 |
def infer(prompt, progress=gr.Progress(track_tqdm=True)):
|
| 95 |
pipeline = AuffusionPipeline.from_pretrained("auffusion/auffusion")
|
| 96 |
prompt = prompt
|
|
|
|
| 139 |
else:
|
| 140 |
print(f"✅ Spectrogram looks normal (Mean: {spec_mean_before}). No boost needed.")
|
| 141 |
|
| 142 |
+
spec = adjust_spectrogram_mean(spec, target_mean=-5.0)
|
| 143 |
+
|
| 144 |
# Normalize the spectrogram
|
| 145 |
norm_spec = normalize_spectrogram(spec)
|
| 146 |
|