Socold commited on
Commit
d7aaa33
·
verified ·
1 Parent(s): 8872f6b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -52
app.py CHANGED
@@ -18,61 +18,55 @@ subprocess.run([sys.executable, "-m", "pip", "install", "-e", "VV_Clone_1"])
18
  import torch
19
  import gradio as gr
20
 
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()
 
18
  import torch
19
  import gradio as gr
20
 
21
+ # FORCER la récupération des secrets
 
 
 
 
22
  USERNAME = os.environ.get("AUTH_USERNAME")
23
  PASSWORD = os.environ.get("AUTH_PASSWORD")
 
 
 
 
 
24
 
25
+ if not USERNAME or not PASSWORD:
26
+ # Si pas de secrets, bloquer complètement
27
+ gr.Interface(
28
+ fn=lambda x: "❌ ERREUR: Configurez AUTH_USERNAME et AUTH_PASSWORD dans Settings → Variables and secrets!",
29
+ inputs="text",
30
+ outputs="text",
31
+ title="Space non configuré"
32
+ ).launch()
33
+ exit()
34
 
35
+ print(f"✅ Authentification activée pour: {USERNAME}")
36
+
37
+ # Créer un nouveau script qui wrappe tout avec auth
38
+ wrapper_script = f"""
39
+ import sys
40
+ sys.path.insert(0, "VV_Clone_1")
41
  os.chdir("VV_Clone_1")
42
 
43
+ from demo.gradio_demo import VibeVoiceDemo
44
+ import gradio as gr
45
+
46
+ # Créer l'instance
47
+ demo = VibeVoiceDemo(model_path="{MODEL_PATH}")
48
+
49
+ # Créer l'interface Gradio
50
+ interface = demo.launch()
51
+
52
+ # Fermer l'instance sans auth
53
+ interface.close()
54
+
55
+ # Relancer AVEC authentification
56
+ interface.launch(
57
+ auth=("{USERNAME}", "{PASSWORD}"),
58
+ auth_message="Entrez vos identifiants VibeVoice",
59
+ server_name="0.0.0.0",
60
+ server_port=7860,
61
+ share=False
62
+ )
63
+ """
64
+
65
+ MODEL_PATH = "aoi-ot/VibeVoice-7B"
66
+
67
+ # Écrire et exécuter le wrapper
68
+ with open("run_with_auth.py", "w") as f:
69
+ f.write(wrapper_script)
70
+
71
+ os.chdir("VV_Clone_1")
72
+ exec(open("../run_with_auth.py").read())