gnosticdev commited on
Commit
ffdf9f7
·
verified ·
1 Parent(s): b1f5cba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -6
app.py CHANGED
@@ -210,38 +210,57 @@ def combine_audio_video(audio_file, video_clip, music_clip=None):
210
 
211
  def process_input(text, txt_file, mp3_file, selected_voice, rate, pitch, keywords):
212
  try:
 
213
  if text.strip():
214
  final_text = text
215
  elif txt_file is not None:
216
  final_text = txt_file.decode("utf-8")
217
  else:
218
- return "No input provided"
 
219
 
 
220
  voices = asyncio.run(get_voices())
221
  if selected_voice not in voices:
222
- return f"La voz '{selected_voice}' no es válida. Por favor, seleccione una de las siguientes voces: {', '.join(voices.keys())}"
223
 
 
224
  try:
225
  audio_file = asyncio.run(text_to_speech(final_text, selected_voice, rate, pitch))
226
  except Exception as e:
227
- return f"Error generando audio: {e}"
 
228
 
 
229
  try:
230
  video_clip = concatenate_pexels_videos(keywords, num_videos_per_keyword=1)
231
  except Exception as e:
232
- return f"Error concatenando videos: {e}"
 
233
 
 
234
  if mp3_file is not None:
235
  music_clip = adjust_background_music(video_clip.duration, mp3_file.name)
236
  else:
237
  music_clip = None
238
 
 
239
  final_video_path = combine_audio_video(audio_file, video_clip, music_clip)
 
 
 
 
240
  upload_to_google_drive(final_video_path)
241
- return final_video_path
 
 
 
 
 
242
 
243
  except Exception as e:
244
- return f"Error durante el procesamiento: {e}"
 
245
 
246
  def upload_to_google_drive(file_path):
247
  try:
@@ -277,6 +296,8 @@ with gr.Blocks() as demo:
277
  output_video = gr.File(label="Download Generated Video")
278
 
279
  btn = gr.Button("Generate Video")
 
 
280
  btn.click(
281
  process_input,
282
  inputs=[text_input, txt_file_input, mp3_file_input, voice_dropdown, rate_slider, pitch_slider, keyword_input],
 
210
 
211
  def process_input(text, txt_file, mp3_file, selected_voice, rate, pitch, keywords):
212
  try:
213
+ # Validar entrada de texto
214
  if text.strip():
215
  final_text = text
216
  elif txt_file is not None:
217
  final_text = txt_file.decode("utf-8")
218
  else:
219
+ # Retornar None en lugar de string de error
220
+ return None
221
 
222
+ # Validar voces
223
  voices = asyncio.run(get_voices())
224
  if selected_voice not in voices:
225
+ return None
226
 
227
+ # Generar audio
228
  try:
229
  audio_file = asyncio.run(text_to_speech(final_text, selected_voice, rate, pitch))
230
  except Exception as e:
231
+ print(f"Error generando audio: {e}")
232
+ return None
233
 
234
+ # Procesar videos
235
  try:
236
  video_clip = concatenate_pexels_videos(keywords, num_videos_per_keyword=1)
237
  except Exception as e:
238
+ print(f"Error concatenando videos: {e}")
239
+ return None
240
 
241
+ # Procesar música de fondo si existe
242
  if mp3_file is not None:
243
  music_clip = adjust_background_music(video_clip.duration, mp3_file.name)
244
  else:
245
  music_clip = None
246
 
247
+ # Combinar audio y video
248
  final_video_path = combine_audio_video(audio_file, video_clip, music_clip)
249
+ if final_video_path is None:
250
+ return None
251
+
252
+ # Subir a Google Drive
253
  upload_to_google_drive(final_video_path)
254
+
255
+ # Verificar que el archivo existe antes de retornarlo
256
+ if os.path.exists(final_video_path):
257
+ return final_video_path
258
+ else:
259
+ return None
260
 
261
  except Exception as e:
262
+ print(f"Error en process_input: {e}")
263
+ return None
264
 
265
  def upload_to_google_drive(file_path):
266
  try:
 
296
  output_video = gr.File(label="Download Generated Video")
297
 
298
  btn = gr.Button("Generate Video")
299
+ def show_error():
300
+ return gr.Warning("Hubo un error procesando el video. Por favor, verifica los parámetros e intenta de nuevo.")
301
  btn.click(
302
  process_input,
303
  inputs=[text_input, txt_file_input, mp3_file_input, voice_dropdown, rate_slider, pitch_slider, keyword_input],