gnosticdev commited on
Commit
955b525
·
verified ·
1 Parent(s): 2740481

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -4
app.py CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
2
  from tts_module import get_voices, text_to_speech # Usamos el tts_module.py actualizado
3
  from pexels_api import search_pexels
4
  from moviepy.editor import AudioFileClip, VideoFileClip, CompositeAudioClip, concatenate_audioclips
5
-
6
  import asyncio
7
  import os
8
  import requests
@@ -27,6 +27,15 @@ except ImportError:
27
  except ImportError:
28
  raise ImportError("Error crítico: No se pudo instalar moviepy.editor. Verifica las dependencias.")
29
 
 
 
 
 
 
 
 
 
 
30
  # Ajustar música de fondo
31
  def adjust_background_music(video_duration, music_file):
32
  music = AudioFileClip(music_file)
@@ -39,14 +48,36 @@ def adjust_background_music(video_duration, music_file):
39
  music = music.volumex(0.2)
40
  return music
41
 
42
- # Combinar audio, video y música
43
  def combine_audio_video(audio_file, video_clip, music_clip=None):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  audio_clip = AudioFileClip(audio_file)
45
  final_clip = video_clip.set_audio(audio_clip)
 
 
46
  if music_clip:
47
  final_clip = final_clip.set_audio(CompositeAudioClip([audio_clip, music_clip]))
 
 
48
  output_path = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4").name
49
- final_clip.write_videofile(output_path, codec="libx264", audio_codec="aac")
50
  return output_path
51
 
52
  # Función principal
@@ -57,7 +88,7 @@ def process_input(text, txt_file, mp3_file, prompt, selected_voice, rate, pitch)
57
  elif txt_file is not None:
58
  final_text = txt_file.decode("utf-8")
59
  elif prompt.strip():
60
- final_text = "Generated text from prompt"
61
  else:
62
  return "No input provided", None
63
 
 
2
  from tts_module import get_voices, text_to_speech # Usamos el tts_module.py actualizado
3
  from pexels_api import search_pexels
4
  from moviepy.editor import AudioFileClip, VideoFileClip, CompositeAudioClip, concatenate_audioclips
5
+ from transformers import pipeline # Para generar texto con GPT-2
6
  import asyncio
7
  import os
8
  import requests
 
27
  except ImportError:
28
  raise ImportError("Error crítico: No se pudo instalar moviepy.editor. Verifica las dependencias.")
29
 
30
+ # Generar texto a partir de un prompt usando GPT-2
31
+ text_generator = pipeline("text-generation", model="gpt2")
32
+
33
+ def generate_text_from_prompt(prompt):
34
+ if not prompt.strip():
35
+ return "Please provide a valid prompt."
36
+ generated_text = text_generator(prompt, max_length=500, do_sample=True)[0]["generated_text"]
37
+ return generated_text
38
+
39
  # Ajustar música de fondo
40
  def adjust_background_music(video_duration, music_file):
41
  music = AudioFileClip(music_file)
 
48
  music = music.volumex(0.2)
49
  return music
50
 
51
+ # Combinar audio, video y música con ajuste a 16:9
52
  def combine_audio_video(audio_file, video_clip, music_clip=None):
53
+ # Ajustar el video a una proporción de 16:9 (1920x1080)
54
+ target_width = 1920
55
+ target_height = 1080
56
+
57
+ current_width, current_height = video_clip.size
58
+ aspect_ratio = current_width / current_height
59
+
60
+ if aspect_ratio > (target_width / target_height): # Si es más ancho, recortar los lados
61
+ new_width = int(current_height * (target_width / target_height))
62
+ video_clip = video_clip.crop(x1=(current_width - new_width) / 2, y1=0, x2=(current_width + new_width) / 2, y2=current_height)
63
+ else: # Si es más alto, recortar arriba y abajo
64
+ new_height = int(current_width * (target_height / target_width))
65
+ video_clip = video_clip.crop(x1=0, y1=(current_height - new_height) / 2, x2=current_width, y2=(current_height + new_height) / 2)
66
+
67
+ # Redimensionar el video al tamaño objetivo (1920x1080)
68
+ video_clip = video_clip.resize((target_width, target_height))
69
+
70
+ # Agregar audio al video
71
  audio_clip = AudioFileClip(audio_file)
72
  final_clip = video_clip.set_audio(audio_clip)
73
+
74
+ # Añadir música de fondo si aplica
75
  if music_clip:
76
  final_clip = final_clip.set_audio(CompositeAudioClip([audio_clip, music_clip]))
77
+
78
+ # Exportar el video final
79
  output_path = tempfile.NamedTemporaryFile(delete=False, suffix=".mp4").name
80
+ final_clip.write_videofile(output_path, codec="libx264", audio_codec="aac", fps=24)
81
  return output_path
82
 
83
  # Función principal
 
88
  elif txt_file is not None:
89
  final_text = txt_file.decode("utf-8")
90
  elif prompt.strip():
91
+ final_text = generate_text_from_prompt(prompt) # Generar texto desde el prompt
92
  else:
93
  return "No input provided", None
94