Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import os | |
| import uuid | |
| import shutil | |
| # Pasta de saída | |
| OUTPUT_DIR = "outputs" | |
| os.makedirs(OUTPUT_DIR, exist_ok=True) | |
| def process_video(video_file): | |
| """ | |
| Função chamada tanto pela UI quanto pela API. | |
| Recebe um arquivo e devolve um arquivo processado. | |
| """ | |
| if video_file is None: | |
| raise ValueError("Nenhum arquivo enviado") | |
| # Nome único para evitar conflito | |
| file_id = str(uuid.uuid4()) | |
| input_path = video_file | |
| output_path = os.path.join(OUTPUT_DIR, f"{file_id}_output.webm") | |
| # ⚠️ AQUI entra sua lógica real | |
| # Por enquanto, apenas copiamos o arquivo | |
| shutil.copy(input_path, output_path) | |
| # Retornar caminho do arquivo = link de download | |
| return output_path | |
| # 🔥 INTERFACE COM API EXPLÍCITA | |
| iface = gr.Interface( | |
| fn=process_video, | |
| inputs=gr.File(label="Upload do vídeo"), | |
| outputs=gr.File(label="Download do resultado"), | |
| title="Conversor de Vídeo", | |
| description="Envie um vídeo e receba o arquivo processado.", | |
| api_name="predict" # 👈 ISSO É O MAIS IMPORTANTE | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() |