Files changed (1) hide show
  1. app.py +39 -28
app.py CHANGED
@@ -28,18 +28,29 @@ def predict(prompt, negative_prompt, audio_input, duration):
28
  # return style_transfer(prompt, negative_prompt, audio_input)
29
 
30
  def classic(prompt, negative_prompt, duration):
31
- pipe.safety_checker = dummy_checker
32
- spec = pipe(prompt, negative_prompt=negative_prompt, height=512, width=512).images[0]
 
 
 
 
33
  print(spec)
34
  wav = wav_bytes_from_spectrogram_image(spec)
35
  with open("output.wav", "wb") as f:
36
  f.write(wav[0].getbuffer())
37
  return spec, 'output.wav', gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
38
 
39
- def style_transfer(prompt, negative_prompt, audio_input):
 
 
 
 
 
 
 
40
  # spec = spectro_from_wav(audio_input)
41
  # Open the image
42
- im = Image.open('rootfart-1.jpg')
43
  # im = Image.open(spec)
44
 
45
 
@@ -47,37 +58,37 @@ def style_transfer(prompt, negative_prompt, audio_input):
47
  # im = image_from_spectrogram(im, 1)
48
 
49
 
50
- new_spectro = pipe2(prompt=prompt, image=im, strength=0.5, guidance_scale=7).images
51
- wav = wav_bytes_from_spectrogram_image(new_spectro[0])
52
- with open("output.wav", "wb") as f:
53
- f.write(wav[0].getbuffer())
54
- return new_spectro[0], 'output.wav', gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
55
 
56
- def image_from_spectrogram(
57
- spectrogram: np.ndarray, max_volume: float = 50, power_for_image: float = 0.25
58
- ) -> Image.Image:
59
- """
60
- Compute a spectrogram image from a spectrogram magnitude array.
61
- """
62
- # Apply the power curve
63
- data = np.power(spectrogram, power_for_image)
64
 
65
- # Rescale to 0-255
66
- data = data * 255 / max_volume
67
 
68
- # Invert
69
- data = 255 - data
70
 
71
- # Convert to a PIL image
72
- image = Image.fromarray(data.astype(np.uint8))
73
 
74
- # Flip Y
75
- image = image.transpose(Image.FLIP_TOP_BOTTOM)
76
 
77
- # Convert to RGB
78
- image = image.convert("RGB")
79
 
80
- return image
81
 
82
  title = """
83
  <div style="text-align: center; max-width: 500px; margin: 0 auto;">
 
28
  # return style_transfer(prompt, negative_prompt, audio_input)
29
 
30
  def classic(prompt, negative_prompt, duration):
31
+ pipe2.safety_checker = dummy_checker
32
+ url = "https://huggingface.co/spaces/gfartenstein/text2fart/resolve/main/rootfart-1.jpg"
33
+ response = requests.get(url)
34
+ im = Image.open(BytesIO(response.content)).convert("RGB")
35
+ # spec = pipe(prompt, negative_prompt=negative_prompt, height=512, width=512).images[0]
36
+ spec = pipe2(prompt=prompt, negative_prompt=negative_prompt, image=im, strength=0.5, guidance_scale=7).images
37
  print(spec)
38
  wav = wav_bytes_from_spectrogram_image(spec)
39
  with open("output.wav", "wb") as f:
40
  f.write(wav[0].getbuffer())
41
  return spec, 'output.wav', gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
42
 
43
+ # def style_transfer(prompt, negative_prompt, audio_input):
44
+ # pipe.safety_checker = dummy_checker
45
+ # url = "https://huggingface.co/spaces/gfartenstein/text2fart/resolve/main/rootfart-1.jpg"
46
+ # response = requests.get(url)
47
+ # init_image = Image.open(BytesIO(response.content)).convert("RGB")
48
+ # images = pipe(prompt=prompt, image=init_image, strength=0.75, guidance_scale=7.5).images
49
+
50
+
51
  # spec = spectro_from_wav(audio_input)
52
  # Open the image
53
+ # im = Image.open('rootfart-1.jpg')
54
  # im = Image.open(spec)
55
 
56
 
 
58
  # im = image_from_spectrogram(im, 1)
59
 
60
 
61
+ # new_spectro = pipe2(prompt=prompt, image=im, strength=0.5, guidance_scale=7).images
62
+ # wav = wav_bytes_from_spectrogram_image(new_spectro[0])
63
+ # with open("output.wav", "wb") as f:
64
+ # f.write(wav[0].getbuffer())
65
+ # return new_spectro[0], 'output.wav', gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
66
 
67
+ # def image_from_spectrogram(
68
+ # spectrogram: np.ndarray, max_volume: float = 50, power_for_image: float = 0.25
69
+ # ) -> Image.Image:
70
+ # """
71
+ # Compute a spectrogram image from a spectrogram magnitude array.
72
+ # """
73
+ # # Apply the power curve
74
+ # data = np.power(spectrogram, power_for_image)
75
 
76
+ # # Rescale to 0-255
77
+ # data = data * 255 / max_volume
78
 
79
+ # # Invert
80
+ # data = 255 - data
81
 
82
+ # # Convert to a PIL image
83
+ # image = Image.fromarray(data.astype(np.uint8))
84
 
85
+ # # Flip Y
86
+ # image = image.transpose(Image.FLIP_TOP_BOTTOM)
87
 
88
+ # # Convert to RGB
89
+ # image = image.convert("RGB")
90
 
91
+ # return image
92
 
93
  title = """
94
  <div style="text-align: center; max-width: 500px; margin: 0 auto;">