Update app.py
Browse files5 unmodified lines678910111 unmodified line1314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768695 unmodified linesif not os.path.exists("VV_Clone_1"):subprocess.run(["git", "clone", "https://github.com/Socold/VV_Clone_1.git"])# Installer les dépendancessubprocess.run([sys.executable, "-m", "pip", "install", "-q","torch", "transformers>=4.40.0", "accelerate", "gradio>=4.0.0",1 unmodified linesubprocess.run([sys.executable, "-m", "pip", "install", "-e", "VV_Clone_1"])# Récupérer les secrets AVANT toutUSERNAME = os.environ.get("AUTH_USERNAME")PASSWORD = os.environ.get("AUTH_PASSWORD")if not USERNAME or not PASSWORD:print("❌ ERREUR: Configurez AUTH_USERNAME et AUTH_PASSWORD dans Settings!")exit(1)print(f"✅ Authentification activée pour: {USERNAME}")# FORCER l'authentification en modifiant Gradioimport gradio as gr# Sauvegarder la méthode originaleoriginal_launch = gr.Blocks.launch# Créer une nouvelle méthode qui force l'authdef forced_auth_launch(self, *args, **kwargs):# Forcer l'authentificationkwargs['auth'] = (USERNAME, PASSWORD)kwargs['auth_message'] = "Authentification VibeVoice requise"# Configuration spéciale pour HuggingFace Spaceskwargs['server_name'] = "0.0.0.0"kwargs['share'] = Falsekwargs['root_path'] = os.environ.get("SPACE_ID", "")# Ignorer les erreurs de localhosttry:print("🔒 AUTHENTIFICATION FORCÉE APPLIQUÉE")return original_launch(self, *args, **kwargs)except ValueError as e:if "localhost" in str(e):# Forcer le lancement même avec l'erreurkwargs['share'] = Truereturn original_launch(self, *args, **kwargs)raise# Remplacer la méthode launchgr.Blocks.launch = forced_auth_launchgr.Interface.launch = forced_auth_launchimport torchprint(f"GPU: {torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'CPU'}")# Changer de dossier AVANT l'importos.chdir("VV_Clone_1")sys.path.insert(0, os.getcwd())# Configurer les arguments SANS --sharesys.argv = ["gradio_demo.py", "--model_path", "aoi-ot/VibeVoice-7B"]# Importer et lancerfrom demo.gradio_demo import mainprint("🚀 Lancement de VibeVoice avec authentification forcée...")main()5 unmodified lines6789101112131 unmodified line1516171819202122232425262728293031323334353637383940414243444546474849505152535455565758595 unmodified linesif not os.path.exists("VV_Clone_1"):subprocess.run(["git", "clone", "https://github.com/Socold/VV_Clone_1.git"])sys.path.insert(0, "VV_Clone_1")# Installer les dépendancessubprocess.run([sys.executable, "-m", "pip", "install", "-q","torch", "transformers>=4.40.0", "accelerate", "gradio>=4.0.0",1 unmodified linesubprocess.run([sys.executable, "-m", "pip", "install", "-e", "VV_Clone_1"])import torchimport gradio as gr# Configuration - Changé pour utiliser 7BMODEL_PATH = "aoi-ot/VibeVoice-7B" # ← Modifié ici# Récupérer les secrets (invisibles publiquement)USERNAME = os.environ.get("AUTH_USERNAME")PASSWORD = os.environ.get("AUTH_PASSWORD")print(f"Chargement du modèle: {MODEL_PATH}")print(f"GPU: {torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'CPU'}")print(f"VRAM disponible: {torch.cuda.get_device_properties(0).total_memory / 1024**3:.2f} GB")# Lancer le script principal avec les argumentsos.chdir("VV_Clone_1")sys.argv = ["gradio_demo.py", "--model_path", MODEL_PATH, "--share"]# Importer et modifier le main pour ajouter l'authfrom demo.gradio_demo import main# Si les secrets existent, modifier le fichier pour ajouter l'authif USERNAME and PASSWORD:with open("demo/gradio_demo.py", "r") as f:content = f.read()# Remplacer la ligne launch pour ajouter authcontent = content.replace('demo.launch(share=args.share)',f'demo.launch(share=args.share, auth=("{USERNAME}", "{PASSWORD}"))')with open("demo/gradio_demo.py", "w") as f:f.write(content)print(f"Authentification activée pour l'utilisateur: {USERNAME}")else:print("Pas d'authentification configurée (pas de secrets définis)")# Lancer le mainprint("Démarrage de l'interface VibeVoice-7B...")main()
app.py+34-44