File size: 1,436 Bytes
2095724
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import gradio as gr
import openai
from moviepy.editor import VideoFileClip
import os

# Configurar la clave de API de OpenAI (aseg煤rate de agregarla como variable de entorno)
openai.api_key = os.getenv("OPENAI_API_KEY")

# Funci贸n para extraer texto de audio o generar respuestas
def process_video(video):
    # Cargar el video y extraer audio
    clip = VideoFileClip(video)
    audio_path = "audio_extracted.wav"
    clip.audio.write_audiofile(audio_path)
    
    # (Opcional) Proceso para convertir audio a texto (usa OpenAI Whisper o cualquier herramienta ASR)
    # Aqu铆 suponemos que ya tienes texto extra铆do, pero puedes integrarlo con un modelo ASR.
    transcription = "Este es un ejemplo de transcripci贸n extra铆da del audio."

    # Generar respuesta usando ChatGPT
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": transcription}],
    )
    
    return f"Texto procesado: {response['choices'][0]['message']['content']}"

# Crear la interfaz de Gradio
with gr.Blocks() as demo:
    gr.Markdown("## Procesador de Video con ChatGPT")
    video_input = gr.Video(label="Sube tu video")
    output_text = gr.Textbox(label="Respuesta de ChatGPT")
    submit_button = gr.Button("Procesar Video")
    
    submit_button.click(process_video, inputs=video_input, outputs=output_text)

# Ejecutar la aplicaci贸n
if __name__ == "__main__":
    demo.launch()