fffiloni commited on
Commit
62e5071
1 Parent(s): dcda854

fix typo + add IDs to generated files

Browse files
Files changed (1) hide show
  1. app.py +13 -11
app.py CHANGED
@@ -70,11 +70,12 @@ def add_silence_to_wav(wav_file_path, duration_s=1):
70
  def check_mp3(file_path):
71
 
72
  if is_mp3(file_path):
73
- wav_file_path = os.path.splitext(file_path)[0] + '.wav'
 
74
  converted_audio = convert_mp3_to_wav(file_path, wav_file_path)
75
  print(f"File converted to {wav_file_path}")
76
 
77
- return converted_audio
78
  else:
79
  print("The file is not an MP3 file.")
80
 
@@ -112,17 +113,17 @@ def generate_portrait(prompt_image):
112
  except:
113
  raise gr.Error(f"ByteDance/SDXL-Lightning space's api might not be ready, please wait, or upload an image instead.")
114
 
115
- try:
116
- result = client.predict(
117
- prompt = prompt_image,
118
- ckpt = "4-Step",
119
- api_name = "/generate_image"
120
- )
121
- print(result)
122
 
123
  # convert to png if necessary
124
  input_file = result
125
- output_file = "converted_to_png_portrait.png"
 
126
  ready_png = check_and_convert_webp_to_png(input_file, output_file)
127
  print(f"PORTRAIT PNG FILE: {ready_png}")
128
 
@@ -201,7 +202,8 @@ def generate_talking_portrait(portrait, voice, progress=gr.Progress(track_tqdm=T
201
  if is_shared_ui :
202
  # Trim audio to AUDIO_MAX_DURATION for better shared experience with community
203
  input_file = voice
204
- trimmed_output_file = "trimmed_audio.wav"
 
205
  trimmed_output_file = trim_audio(input_file, trimmed_output_file, AUDIO_MAX_DURATION)
206
  voice = trimmed_output_file
207
 
 
70
  def check_mp3(file_path):
71
 
72
  if is_mp3(file_path):
73
+ unique_id = uuid.uuid4()
74
+ wav_file_path = f"{os.path.splitext(file_path)[0]}-{unique_id}.wav"
75
  converted_audio = convert_mp3_to_wav(file_path, wav_file_path)
76
  print(f"File converted to {wav_file_path}")
77
 
78
+ return converted_audio, gr.update(value=converted_audio, visible=True)
79
  else:
80
  print("The file is not an MP3 file.")
81
 
 
113
  except:
114
  raise gr.Error(f"ByteDance/SDXL-Lightning space's api might not be ready, please wait, or upload an image instead.")
115
 
116
+ result = client.predict(
117
+ prompt = prompt_image,
118
+ ckpt = "4-Step",
119
+ api_name = "/generate_image"
120
+ )
121
+ print(result)
 
122
 
123
  # convert to png if necessary
124
  input_file = result
125
+ unique_id = uuid.uuid4()
126
+ output_file = f"converted_to_png_portrait-{unique_id}.png"
127
  ready_png = check_and_convert_webp_to_png(input_file, output_file)
128
  print(f"PORTRAIT PNG FILE: {ready_png}")
129
 
 
202
  if is_shared_ui :
203
  # Trim audio to AUDIO_MAX_DURATION for better shared experience with community
204
  input_file = voice
205
+ unique_id = uuid.uuid4()
206
+ trimmed_output_file = f"-{unique_id}.wav"
207
  trimmed_output_file = trim_audio(input_file, trimmed_output_file, AUDIO_MAX_DURATION)
208
  voice = trimmed_output_file
209