Telegram Para Cambiar Caras En Videos Work: Bot De
A working solution requires three main components:
| Component | Technology | Purpose |
|-----------|------------|---------|
| Bot Interface | python-telegram-bot v20+ | Handles user commands, media uploads, and async messaging |
| Face Swapping Engine | InsightFace + GFPGAN | Detects, swaps, and enhances faces in video frames |
| Video Processing Pipeline | FFmpeg + OpenCV | Extracts frames, rebuilds video with audio |
Ejemplo mínimo (esqueleto, no listo para producción): bot de telegram para cambiar caras en videos work
# bot.py (aiogram simplified)
from aiogram import Bot, Dispatcher, types
from aiogram.utils import executor
import requests, uuid
API_TOKEN = "TELEGRAM_TOKEN"
bot = Bot(API_TOKEN)
dp = Dispatcher(bot)
@dp.message_handler(content_types=['video', 'photo'])
async def handle_media(message: types.Message):
job_id = str(uuid.uuid4())
file = (await message.video.get_file()) if message.video else (await message.photo[-1].get_file())
path = f"/tmp/job_id"
await file.download(destination_file=path)
# enqueue job (simplified): call local processing function or push to queue
enqueue_job(job_id, path, message.from_user.id)
await message.reply("Tu video está en cola. Te avisaré cuando esté listo.")
if __name__ == "__main__":
executor.start_polling(dp)
Worker invoca pipeline de procesamiento que use modelos (First Order Motion Model por ejemplo) y genera el archivo final.
Este es el más avanzado del listado. No solo cambia la cara, sino que tiene una beta que permite clonar la voz para que coincida con la nueva cara (aunque no lo pidas, es un extra). A working solution requires three main components: |
from telegram import Update from telegram.ext import Application, CommandHandler, MessageHandler, filtersasync def swap_command(update: Update, context): await update.message.reply_text("Send me a video first, then a face photo.") context.user_data['state'] = 'awaiting_video'
async def handle_video(update, context): if context.user_data.get('state') != 'awaiting_video': return video_file = await update.message.video.get_file() video_path = f"downloads/update.effective_user.id_video.mp4" await video_file.download_to_drive(video_path) context.user_data['video_path'] = video_path context.user_data['state'] = 'awaiting_face' await update.message.reply_text("Now send the face image.") Worker invoca pipeline de procesamiento que use modelos
async def handle_photo(update, context): if context.user_data.get('state') != 'awaiting_face': return photo_file = await update.message.photo[-1].get_file() face_path = f"downloads/update.effective_user.id_face.jpg" await photo_file.download_to_drive(face_path) # Enqueue job job = q.enqueue(process_face_swap, context.user_data['video_path'], face_path, update.effective_chat.id) await update.message.reply_text(f"Processing... Job ID: job.id. I'll notify you when done.")