akhaliq HF Staff commited on
Commit
acfc1da
·
1 Parent(s): 080fa02

Robustly handle audio_ref dict or object in generate_audio endpoint

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -198,7 +198,14 @@ def generate_audio(
198
  raise gr.Error("Prompt is empty.")
199
 
200
  t0 = time.time()
201
- ref_path = audio_ref.path if audio_ref and audio_ref.path and os.path.exists(audio_ref.path) else None
 
 
 
 
 
 
 
202
 
203
  output = tempfile.mktemp(suffix=".wav", prefix="dramabox_")
204
  tts.generate_to_file(
 
198
  raise gr.Error("Prompt is empty.")
199
 
200
  t0 = time.time()
201
+ ref_path = None
202
+ if audio_ref:
203
+ if isinstance(audio_ref, dict):
204
+ ref_path = audio_ref.get("path")
205
+ elif hasattr(audio_ref, "path"):
206
+ ref_path = audio_ref.path
207
+ if ref_path and not os.path.exists(ref_path):
208
+ ref_path = None
209
 
210
  output = tempfile.mktemp(suffix=".wav", prefix="dramabox_")
211
  tts.generate_to_file(