from flask import Flask, render_template, request from elevenlabs import generate, set_api_key import os import subprocess app = Flask(__name__) # ✅ Set your ElevenLabs API key — store securely in real apps set_api_key("sk_0be86a97d6cd7dd86b035694a0a607d3bb9466018b9090b7") @app.route('/', methods=['GET', 'POST']) def index(): show_video = False if request.method == 'POST': text = request.form.get('text', '') if text.strip(): # Generate speech audio audio = generate( text=text, voice="EXAVITQu4vr4xnSDxMaL", # Default voice model="eleven_monolingual_v1" ) # Save to MP3 os.makedirs("static", exist_ok=True) audio_path = "static/output.mp3" with open(audio_path, "wb") as f: f.write(audio) # ✅ Generate a simple video with static avatar image image_path = "static/avatar.jpg" video_path = "static/talking_avatar.mp4" subprocess.run([ "ffmpeg", "-y", "-loop", "1", "-i", image_path, "-i", audio_path, "-shortest", "-vf", "scale=640:480", "-c:v", "libx264", "-c:a", "aac", "-b:a", "192k", "-pix_fmt", "yuv420p", video_path ], check=True) show_video = True return render_template("index.html", show_video=show_video) if __name__ == '__main__': app.run(host="0.0.0.0", port=7860, debug=True) # Custom port for Hugging Face or Replit