DGSpitzer commited on
Commit
e340317
1 Parent(s): 57f29f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -23,6 +23,7 @@ import moviepy.video.io.ImageSequenceClip
23
  from moviepy.editor import *
24
  import mutagen
25
  from mutagen.mp3 import MP3
 
26
 
27
  img_to_text = gr.Blocks.load(name="spaces/pharma/CLIP-Interrogator")
28
  text_to_music = gr.Interface.load("spaces/fffiloni/text-2-music")
@@ -97,9 +98,11 @@ def get_result(text_prompts, style_indx, musicAI_indx, duration):
97
  spec_image, music_output = get_music(interrogate_prompt + ", " + style_list_EN[style_indx], musicAI_indx, duration)
98
 
99
  video_merged = merge_video(music_output, image_output)
100
- return {spec_result:spec_image, imgfile_result:image_output, musicfile_result:music_output, video_result:video_merged, status_text:'Success', share_button:gr.update(visible=True), community_icon:gr.update(visible=True), loading_icon:gr.update(visible=True)}
101
 
102
  def get_music(prompt, musicAI_indx, duration):
 
 
103
  if musicAI_indx == 0:
104
  if duration == 5:
105
  width_duration=512
@@ -108,13 +111,12 @@ def get_music(prompt, musicAI_indx, duration):
108
  spec = pipe2(prompt, height=512, width=width_duration).images[0]
109
  print(spec)
110
  wav = wav_bytes_from_spectrogram_image(spec)
111
- with open("output.wav", "wb") as f:
112
  f.write(wav[0].getbuffer())
113
 
114
 
115
- #Convert to mp3
116
- mp3file_name = "audio.mp3"
117
- wavfile = AudioSegment.from_wav("output.wav")
118
  wavfile.export(mp3file_name, format="mp3")
119
  return spec, mp3file_name
120
  else:
@@ -128,7 +130,6 @@ def get_music(prompt, musicAI_indx, duration):
128
  """)
129
 
130
  url = result
131
- mp3file_name = "file.mp3"
132
 
133
  data = urllib.request.urlopen(url)
134
 
@@ -136,10 +137,10 @@ def get_music(prompt, musicAI_indx, duration):
136
  f.write(data.read())
137
  f.close()
138
 
139
- #wave_file="file.wav"
 
 
140
 
141
- #sound = AudioSegment.from_mp3(save_as)
142
- #sound.export(wave_file, format="wav")
143
  return None, mp3file_name
144
 
145
 
 
23
  from moviepy.editor import *
24
  import mutagen
25
  from mutagen.mp3 import MP3
26
+ from mutagen.wave import WAVE
27
 
28
  img_to_text = gr.Blocks.load(name="spaces/pharma/CLIP-Interrogator")
29
  text_to_music = gr.Interface.load("spaces/fffiloni/text-2-music")
 
98
  spec_image, music_output = get_music(interrogate_prompt + ", " + style_list_EN[style_indx], musicAI_indx, duration)
99
 
100
  video_merged = merge_video(music_output, image_output)
101
+ return {spec_result:spec_image, imgfile_result:image_output, musicfile_result:"audio.wav", video_result:video_merged, status_text:'Success', share_button:gr.update(visible=True), community_icon:gr.update(visible=True), loading_icon:gr.update(visible=True)}
102
 
103
  def get_music(prompt, musicAI_indx, duration):
104
+ mp3file_name = "audio.mp3"
105
+ wavfile_name = "audio.wav"
106
  if musicAI_indx == 0:
107
  if duration == 5:
108
  width_duration=512
 
111
  spec = pipe2(prompt, height=512, width=width_duration).images[0]
112
  print(spec)
113
  wav = wav_bytes_from_spectrogram_image(spec)
114
+ with open(wavfile_name, "wb") as f:
115
  f.write(wav[0].getbuffer())
116
 
117
 
118
+ #Convert to mp3, for video merging function
119
+ wavfile = AudioSegment.from_wav(wavfile_name)
 
120
  wavfile.export(mp3file_name, format="mp3")
121
  return spec, mp3file_name
122
  else:
 
130
  """)
131
 
132
  url = result
 
133
 
134
  data = urllib.request.urlopen(url)
135
 
 
137
  f.write(data.read())
138
  f.close()
139
 
140
+ #Convert to wav, for sharing function only supports wav file
141
+ mp3file = AudioSegment.from_mp3(mp3file_name)
142
+ mp3file.export(wavfile_name, format="wav")
143
 
 
 
144
  return None, mp3file_name
145
 
146