Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -12,7 +12,9 @@ import json
|
|
12 |
import time
|
13 |
import requests
|
14 |
import random
|
15 |
-
from
|
|
|
|
|
16 |
from io import BytesIO
|
17 |
|
18 |
# Crear el archivo de credenciales de servicio desde los secretos
|
@@ -171,6 +173,38 @@ def combine_audio_video(audio_file, video_clip, music_clip=None):
|
|
171 |
final_clip.close()
|
172 |
return None
|
173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
def process_input(text, txt_file, mp3_file, selected_voice, rate, pitch, keywords):
|
175 |
"""Procesa la entrada del usuario y genera el video final."""
|
176 |
try:
|
@@ -197,14 +231,13 @@ def process_input(text, txt_file, mp3_file, selected_voice, rate, pitch, keyword
|
|
197 |
final_video_path = combine_audio_video(audio_file, video_clip, music_clip)
|
198 |
if not final_video_path:
|
199 |
raise ValueError("Failed to combine audio and video")
|
200 |
-
# Subimos a Google Drive
|
201 |
-
|
202 |
-
if
|
203 |
-
print(f"Video subido a Google Drive
|
|
|
204 |
else:
|
205 |
-
|
206 |
-
|
207 |
-
return final_video_path
|
208 |
except Exception as e:
|
209 |
print(f"Error durante el procesamiento: {e}")
|
210 |
return None
|
@@ -228,13 +261,13 @@ with gr.Blocks() as demo:
|
|
228 |
rate_slider = gr.Slider(minimum=-50, maximum=50, value=0, label="Speech Rate Adjustment (%)", step=1)
|
229 |
pitch_slider = gr.Slider(minimum=-20, maximum=20, value=0, label="Pitch Adjustment (Hz)", step=1)
|
230 |
with gr.Column():
|
231 |
-
|
232 |
|
233 |
btn = gr.Button("Generate Video")
|
234 |
btn.click(
|
235 |
process_input,
|
236 |
inputs=[text_input, txt_file_input, mp3_file_input, voice_dropdown, rate_slider, pitch_slider, keyword_input],
|
237 |
-
outputs=
|
238 |
)
|
239 |
|
240 |
# Leer el puerto asignado por Hugging Face
|
|
|
12 |
import time
|
13 |
import requests
|
14 |
import random
|
15 |
+
from googleapiclient.discovery import build
|
16 |
+
from google.oauth2 import service_account
|
17 |
+
from googleapiclient.http import MediaFileUpload
|
18 |
from io import BytesIO
|
19 |
|
20 |
# Crear el archivo de credenciales de servicio desde los secretos
|
|
|
173 |
final_clip.close()
|
174 |
return None
|
175 |
|
176 |
+
def upload_to_google_drive(file_path, folder_id):
|
177 |
+
"""Sube un archivo a Google Drive y devuelve el enlace p煤blico."""
|
178 |
+
try:
|
179 |
+
# Autenticaci贸n
|
180 |
+
creds = service_account.Credentials.from_service_account_file(
|
181 |
+
'service-account.json', scopes=['https://www.googleapis.com/auth/drive']
|
182 |
+
)
|
183 |
+
service = build('drive', 'v3', credentials=creds)
|
184 |
+
|
185 |
+
# Subir el archivo
|
186 |
+
file_metadata = {
|
187 |
+
'name': os.path.basename(file_path),
|
188 |
+
'parents': [folder_id]
|
189 |
+
}
|
190 |
+
media = MediaFileUpload(file_path, resumable=True)
|
191 |
+
file = service.files().create(body=file_metadata, media_body=media, fields='id').execute()
|
192 |
+
|
193 |
+
# Hacer el archivo p煤blico
|
194 |
+
permission = {
|
195 |
+
'type': 'anyone',
|
196 |
+
'role': 'reader'
|
197 |
+
}
|
198 |
+
service.permissions().create(fileId=file['id'], body=permission).execute()
|
199 |
+
|
200 |
+
# Generar el enlace de descarga
|
201 |
+
file_id = file['id']
|
202 |
+
download_link = f"https://drive.google.com/uc?export=download&id={file_id}"
|
203 |
+
return download_link
|
204 |
+
except Exception as e:
|
205 |
+
print(f"Error subiendo a Google Drive: {e}")
|
206 |
+
return None
|
207 |
+
|
208 |
def process_input(text, txt_file, mp3_file, selected_voice, rate, pitch, keywords):
|
209 |
"""Procesa la entrada del usuario y genera el video final."""
|
210 |
try:
|
|
|
231 |
final_video_path = combine_audio_video(audio_file, video_clip, music_clip)
|
232 |
if not final_video_path:
|
233 |
raise ValueError("Failed to combine audio and video")
|
234 |
+
# Subimos a Google Drive y obtenemos el enlace
|
235 |
+
download_link = upload_to_google_drive(final_video_path, folder_id=FOLDER_ID)
|
236 |
+
if download_link:
|
237 |
+
print(f"Video subido a Google Drive. Enlace de descarga: {download_link}")
|
238 |
+
return f"[Descargar video]({download_link})"
|
239 |
else:
|
240 |
+
raise ValueError("Error subiendo el video a Google Drive")
|
|
|
|
|
241 |
except Exception as e:
|
242 |
print(f"Error durante el procesamiento: {e}")
|
243 |
return None
|
|
|
261 |
rate_slider = gr.Slider(minimum=-50, maximum=50, value=0, label="Speech Rate Adjustment (%)", step=1)
|
262 |
pitch_slider = gr.Slider(minimum=-20, maximum=20, value=0, label="Pitch Adjustment (Hz)", step=1)
|
263 |
with gr.Column():
|
264 |
+
output_link = gr.Markdown("") # Mostrar el enlace de descarga
|
265 |
|
266 |
btn = gr.Button("Generate Video")
|
267 |
btn.click(
|
268 |
process_input,
|
269 |
inputs=[text_input, txt_file_input, mp3_file_input, voice_dropdown, rate_slider, pitch_slider, keyword_input],
|
270 |
+
outputs=output_link
|
271 |
)
|
272 |
|
273 |
# Leer el puerto asignado por Hugging Face
|