Spaces:
Running
on
T4
Running
on
T4
Update app.py
Browse files
app.py
CHANGED
@@ -41,7 +41,7 @@ def style_transfer(prompt, negative_prompt, audio_input):
|
|
41 |
spec = spectro_from_wav(audio_input)
|
42 |
print(spec)
|
43 |
# Open the image
|
44 |
-
im =
|
45 |
|
46 |
new_spectro = pipe2(prompt=prompt, image=im, strength=0.5, guidance_scale=7).images
|
47 |
wav = wav_bytes_from_spectrogram_image(new_spectro[0])
|
@@ -49,6 +49,32 @@ def style_transfer(prompt, negative_prompt, audio_input):
|
|
49 |
f.write(wav[0].getbuffer())
|
50 |
return new_spectro, 'output.wav', gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
title = """
|
53 |
<div style="text-align: center; max-width: 500px; margin: 0 auto;">
|
54 |
<div
|
|
|
41 |
spec = spectro_from_wav(audio_input)
|
42 |
print(spec)
|
43 |
# Open the image
|
44 |
+
im = image_from_spectrogram(spectrogram)
|
45 |
|
46 |
new_spectro = pipe2(prompt=prompt, image=im, strength=0.5, guidance_scale=7).images
|
47 |
wav = wav_bytes_from_spectrogram_image(new_spectro[0])
|
|
|
49 |
f.write(wav[0].getbuffer())
|
50 |
return new_spectro, 'output.wav', gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
51 |
|
52 |
+
def image_from_spectrogram(
|
53 |
+
spectrogram: np.ndarray, max_volume: float = 50, power_for_image: float = 0.25
|
54 |
+
) -> Image.Image:
|
55 |
+
"""
|
56 |
+
Compute a spectrogram image from a spectrogram magnitude array.
|
57 |
+
"""
|
58 |
+
# Apply the power curve
|
59 |
+
data = np.power(spectrogram, power_for_image)
|
60 |
+
|
61 |
+
# Rescale to 0-255
|
62 |
+
data = data * 255 / max_volume
|
63 |
+
|
64 |
+
# Invert
|
65 |
+
data = 255 - data
|
66 |
+
|
67 |
+
# Convert to a PIL image
|
68 |
+
image = Image.fromarray(data.astype(np.uint8))
|
69 |
+
|
70 |
+
# Flip Y
|
71 |
+
image = image.transpose(Image.FLIP_TOP_BOTTOM)
|
72 |
+
|
73 |
+
# Convert to RGB
|
74 |
+
image = image.convert("RGB")
|
75 |
+
|
76 |
+
return image
|
77 |
+
|
78 |
title = """
|
79 |
<div style="text-align: center; max-width: 500px; margin: 0 auto;">
|
80 |
<div
|