Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import openai
|
| 3 |
+
from moviepy.editor import VideoFileClip
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# Configurar la clave de API de OpenAI (aseg煤rate de agregarla como variable de entorno)
|
| 7 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 8 |
+
|
| 9 |
+
# Funci贸n para extraer texto de audio o generar respuestas
|
| 10 |
+
def process_video(video):
|
| 11 |
+
# Cargar el video y extraer audio
|
| 12 |
+
clip = VideoFileClip(video)
|
| 13 |
+
audio_path = "audio_extracted.wav"
|
| 14 |
+
clip.audio.write_audiofile(audio_path)
|
| 15 |
+
|
| 16 |
+
# (Opcional) Proceso para convertir audio a texto (usa OpenAI Whisper o cualquier herramienta ASR)
|
| 17 |
+
# Aqu铆 suponemos que ya tienes texto extra铆do, pero puedes integrarlo con un modelo ASR.
|
| 18 |
+
transcription = "Este es un ejemplo de transcripci贸n extra铆da del audio."
|
| 19 |
+
|
| 20 |
+
# Generar respuesta usando ChatGPT
|
| 21 |
+
response = openai.ChatCompletion.create(
|
| 22 |
+
model="gpt-3.5-turbo",
|
| 23 |
+
messages=[{"role": "user", "content": transcription}],
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
return f"Texto procesado: {response['choices'][0]['message']['content']}"
|
| 27 |
+
|
| 28 |
+
# Crear la interfaz de Gradio
|
| 29 |
+
with gr.Blocks() as demo:
|
| 30 |
+
gr.Markdown("## Procesador de Video con ChatGPT")
|
| 31 |
+
video_input = gr.Video(label="Sube tu video")
|
| 32 |
+
output_text = gr.Textbox(label="Respuesta de ChatGPT")
|
| 33 |
+
submit_button = gr.Button("Procesar Video")
|
| 34 |
+
|
| 35 |
+
submit_button.click(process_video, inputs=video_input, outputs=output_text)
|
| 36 |
+
|
| 37 |
+
# Ejecutar la aplicaci贸n
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
demo.launch()
|