File size: 3,673 Bytes
0e42e6e
d10a695
27fb911
 
 
 
 
3e76c01
8663d4d
1f1a6cb
5c249a8
0e42e6e
61a6628
0e42e6e
623da50
0e42e6e
3a383f1
 
f8f5b17
623da50
 
 
d3ee24c
461d1e2
229b298
9c3f79e
 
 
aeb0d77
 
 
 
 
 
 
 
 
d10a695
 
 
27fb911
7c6553f
3a383f1
 
 
aeb0d77
171efda
 
 
 
 
 
 
 
3a383f1
 
 
 
959adae
f8f5b17
 
 
3a383f1
f8f5b17
3a383f1
 
 
 
 
 
 
 
f8f5b17
 
 
 
3a383f1
 
 
 
 
 
 
461d1e2
f8f5b17
461d1e2
 
3a383f1
 
 
 
 
 
 
5eb1339
3a383f1
fd556c6
 
42b2a55
 
 
 
27fb911
 
 
 
 
0e42e6e
27fb911
 
959adae
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import warnings
import os
import sys

# Force UTF-8 for console output (Windows fix)
sys.stdout.reconfigure(encoding='utf-8')

from huggingface_hub import HfApi, login
import gradio as gr

# Filter warnings immediately
warnings.filterwarnings("ignore", category=SyntaxWarning, module="pydub")

# --- INTERNAL IMPORTS ---
from config import AppConfig
from src.utils import create_warning_beep

# Import your refactored classes
from src.managers import GeminiManager, HFManager, GroqManager
from src.input_agent import AgentInput
from src.brain_agent import AgentInterpretation
from src.trust_agent import AgentTrust
from src.ux_agent import AgentUX
from src.acoustic_agent import AgentAcoustic

# 1. Add the import for your recovery script
import recover_chain # (or 'from src import recover_chain' depending on where the file is)

# 2. Add this block before ui.launch()
print("🔄 Initiating Blockchain Recovery Sequence...")
try:
    # Assuming your recover_chain.py has a main() or run() function
    recover_chain.main() 
    print("✅ Recovery Complete!")
except Exception as e:
    print(f"❌ Recovery Failed: {e}")

# ==========================================
# MAIN APPLICATION LOGIC
# ==========================================
def create_app():
    print("🚀 Initializing PureVersation...")

    # 1. Setup Configuration & Directories
    AppConfig.setup_directories()
    
    # 🟢 NEW: The Silver Bullet - Global Hugging Face Login
    # This must happen BEFORE HFManager tries to pull datasets
    if AppConfig.HF_TOKEN:
        login(token=AppConfig.HF_TOKEN)
        print("✅ Hugging Face Global Login Successful.")
    else:
        print("🚨 WARNING: HF_TOKEN is missing in AppConfig! Downloads will fail.")

    # 2. Initialize Managers (Inject Config)
    # We pass AppConfig to HFManager so it knows where to download files
    hf_manager = HFManager(AppConfig)
    hf_manager.pull_datasets()

    # Initialize Groq (New Brain Stem)
    groq_manager = GroqManager(AppConfig.GROQ_API_KEY) if AppConfig.GROQ_API_KEY else None
    
    # Initialize Gemini (Brain Stem)
    #gemini_manager = GeminiManager(AppConfig.GOOGLE_API_KEY) if AppConfig.GOOGLE_API_KEY else None

    # 3. Initialize Agents (Dependency Injection)
    
    # Agent 1: Input (Whisper)
    agent1 = AgentInput()
    
    # Agent 2: Brain (Interpretation)
    # We pass AppConfig so it knows where PROFILES_DIR is
    # agent2 = AgentInterpretation(AppConfig, gemini_manager_instance=gemini_manager)

    # Inject groq_manager instead of gemini_manager
    agent2 = AgentInterpretation(AppConfig, gemini_manager_instance=groq_manager)
    
    # Agent 4: Trust (Blockchain/IPFS)
    # We pass AppConfig so it has keys for Web3 and Pinata
    agent4 = AgentTrust(AppConfig)
    # Inject hf_manager into Trust so it can save audio files to HF
    agent4.hf_manager_ref = hf_manager 

    # Agent 5: Acoustic (Phonetic IPA)
    agent5 = AgentAcoustic(groq_manager)
    agent4.acoustic_agent = agent5

    # Agent 3: UX (Interface)
    agent3 = AgentUX(agent1, agent2, agent4)
    
    # 4. Launch
    print("✅ System Assembled. Launching Interface...")
    
    # Pass the warning beep path
    agent3.alert_sound = create_warning_beep() 
    
    # 1. Generate the UI blocks
    app = agent3.create_ui()

    # 🟢 FIX: Enable the Gradio Queue here to prevent async loop collisions!
    app.queue(default_concurrency_limit=10)
    
    return app

# Expose 'demo' at the module level for Gradio Hot Reload
demo = create_app()

if __name__ == "__main__":
    # 2. Launch the app and apply your theme here safely!
    demo.launch(theme=gr.themes.Soft(primary_hue="blue"))