Update app.py
Browse files
app.py
CHANGED
|
@@ -3,17 +3,17 @@ import subprocess
|
|
| 3 |
import sys
|
| 4 |
|
| 5 |
# Cloner votre repository
|
| 6 |
-
if not os.path.exists("
|
| 7 |
-
subprocess.run(["git", "clone", "https://github.com/Socold/
|
| 8 |
|
| 9 |
-
sys.path.insert(0, "
|
| 10 |
|
| 11 |
# Installer les dépendances
|
| 12 |
subprocess.run([sys.executable, "-m", "pip", "install", "-q",
|
| 13 |
"torch", "transformers>=4.40.0", "accelerate", "gradio>=4.0.0",
|
| 14 |
"soundfile", "librosa", "scipy", "numpy", "ffmpeg-python"])
|
| 15 |
|
| 16 |
-
subprocess.run([sys.executable, "-m", "pip", "install", "-e", "
|
| 17 |
|
| 18 |
import torch
|
| 19 |
import gradio as gr
|
|
@@ -21,34 +21,58 @@ import gradio as gr
|
|
| 21 |
# Configuration
|
| 22 |
MODEL_PATH = "aoi-ot/VibeVoice-7B"
|
| 23 |
|
| 24 |
-
#
|
|
|
|
| 25 |
USERNAME = os.environ.get("AUTH_USERNAME")
|
| 26 |
PASSWORD = os.environ.get("AUTH_PASSWORD")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
print(f"Modèle: {MODEL_PATH}")
|
| 29 |
print(f"GPU: {torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'CPU'}")
|
| 30 |
|
| 31 |
-
|
| 32 |
-
print(f"Auth configurée: {bool(USERNAME and PASSWORD)}")
|
| 33 |
|
| 34 |
-
#
|
| 35 |
-
|
|
|
|
| 36 |
|
| 37 |
-
#
|
| 38 |
if USERNAME and PASSWORD:
|
| 39 |
-
|
| 40 |
-
with open("demo/gradio_demo.py", "r") as f:
|
| 41 |
-
content = f.read()
|
| 42 |
|
| 43 |
-
#
|
| 44 |
-
if "demo.launch(" in
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
f'demo.launch(auth=("{USERNAME}", "{PASSWORD}")
|
| 48 |
)
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
# Lancer
|
| 53 |
-
sys.argv = ["gradio_demo.py", "--model_path", MODEL_PATH]
|
| 54 |
-
|
|
|
|
|
|
| 3 |
import sys
|
| 4 |
|
| 5 |
# Cloner votre repository
|
| 6 |
+
if not os.path.exists("VV_Clone_1"):
|
| 7 |
+
subprocess.run(["git", "clone", "https://github.com/Socold/VV_Clone_1.git"])
|
| 8 |
|
| 9 |
+
sys.path.insert(0, "VV_Clone_1")
|
| 10 |
|
| 11 |
# Installer les dépendances
|
| 12 |
subprocess.run([sys.executable, "-m", "pip", "install", "-q",
|
| 13 |
"torch", "transformers>=4.40.0", "accelerate", "gradio>=4.0.0",
|
| 14 |
"soundfile", "librosa", "scipy", "numpy", "ffmpeg-python"])
|
| 15 |
|
| 16 |
+
subprocess.run([sys.executable, "-m", "pip", "install", "-e", "VV_Clone_1"])
|
| 17 |
|
| 18 |
import torch
|
| 19 |
import gradio as gr
|
|
|
|
| 21 |
# Configuration
|
| 22 |
MODEL_PATH = "aoi-ot/VibeVoice-7B"
|
| 23 |
|
| 24 |
+
# DEBUG : Vérifier les secrets
|
| 25 |
+
print("=== VÉRIFICATION AUTHENTIFICATION ===")
|
| 26 |
USERNAME = os.environ.get("AUTH_USERNAME")
|
| 27 |
PASSWORD = os.environ.get("AUTH_PASSWORD")
|
| 28 |
+
print(f"AUTH_USERNAME présent: {USERNAME is not None}")
|
| 29 |
+
print(f"AUTH_PASSWORD présent: {PASSWORD is not None}")
|
| 30 |
+
if USERNAME:
|
| 31 |
+
print(f"Utilisateur: {USERNAME}")
|
| 32 |
+
print("====================================")
|
| 33 |
|
| 34 |
print(f"Modèle: {MODEL_PATH}")
|
| 35 |
print(f"GPU: {torch.cuda.get_device_name(0) if torch.cuda.is_available() else 'CPU'}")
|
| 36 |
|
| 37 |
+
os.chdir("VV_Clone_1")
|
|
|
|
| 38 |
|
| 39 |
+
# Lire le fichier original
|
| 40 |
+
with open("demo/gradio_demo.py", "r") as f:
|
| 41 |
+
original_content = f.read()
|
| 42 |
|
| 43 |
+
# Si auth configurée, modifier le fichier
|
| 44 |
if USERNAME and PASSWORD:
|
| 45 |
+
print("Modification du fichier pour ajouter l'authentification...")
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
# Chercher différents patterns possibles
|
| 48 |
+
if "demo.launch(share=args.share)" in original_content:
|
| 49 |
+
new_content = original_content.replace(
|
| 50 |
+
"demo.launch(share=args.share)",
|
| 51 |
+
f'demo.launch(share=args.share, auth=("{USERNAME}", "{PASSWORD}"))'
|
| 52 |
)
|
| 53 |
+
elif "demo.launch()" in original_content:
|
| 54 |
+
new_content = original_content.replace(
|
| 55 |
+
"demo.launch()",
|
| 56 |
+
f'demo.launch(auth=("{USERNAME}", "{PASSWORD}"))'
|
| 57 |
+
)
|
| 58 |
+
else:
|
| 59 |
+
# Pattern plus général
|
| 60 |
+
import re
|
| 61 |
+
new_content = re.sub(
|
| 62 |
+
r'demo\.launch\((.*?)\)',
|
| 63 |
+
f'demo.launch(\\1, auth=("{USERNAME}", "{PASSWORD}"))',
|
| 64 |
+
original_content
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
# Écrire le fichier modifié
|
| 68 |
+
with open("demo/gradio_demo.py", "w") as f:
|
| 69 |
+
f.write(new_content)
|
| 70 |
+
|
| 71 |
+
print("✅ Authentification ajoutée")
|
| 72 |
+
else:
|
| 73 |
+
print("⚠️ ATTENTION: Pas de secrets configurés - Space PUBLIC!")
|
| 74 |
|
| 75 |
+
# Lancer
|
| 76 |
+
sys.argv = ["gradio_demo.py", "--model_path", MODEL_PATH, "--share"]
|
| 77 |
+
from demo.gradio_demo import main
|
| 78 |
+
main()
|