Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,82 +1,58 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import sys
|
| 3 |
import warnings
|
| 4 |
|
| 5 |
-
# 🟢 CRITICAL: Disable SSR at the environment level so Hugging Face's internal server respects it
|
| 6 |
-
os.environ["GRADIO_SSR_MODE"] = "False"
|
| 7 |
-
|
| 8 |
-
# 🟢 CRITICAL: Must import gradio AFTER setting the env var, but BEFORE using it
|
| 9 |
-
import gradio as gr
|
| 10 |
-
from huggingface_hub import HfApi
|
| 11 |
-
|
| 12 |
# Filter warnings immediately
|
| 13 |
warnings.filterwarnings("ignore", category=SyntaxWarning, module="pydub")
|
| 14 |
|
| 15 |
-
# Add the 'src' directory to Python path
|
| 16 |
-
sys.path.append(os.path.join(os.path.dirname(__file__), "src"))
|
| 17 |
-
|
| 18 |
# --- INTERNAL IMPORTS ---
|
| 19 |
from config import AppConfig
|
| 20 |
from src.utils import create_warning_beep
|
|
|
|
|
|
|
| 21 |
from src.managers import GeminiManager, HFManager
|
| 22 |
from src.input_agent import AgentInput
|
| 23 |
from src.brain_agent import AgentInterpretation
|
| 24 |
from src.trust_agent import AgentTrust
|
| 25 |
from src.ux_agent import AgentUX
|
| 26 |
-
from src.bridge_agent import AgentBridge
|
| 27 |
-
from src.watcher_agent import AgentWatcher
|
| 28 |
-
|
| 29 |
-
# ==========================================
|
| 30 |
-
# 🚀 GLOBAL INITIALIZATION
|
| 31 |
-
# ==========================================
|
| 32 |
-
print("🚀 Initializing Modular Architecture IEDI (MA-IEDI)...")
|
| 33 |
-
|
| 34 |
-
# 1. Setup Configuration & Directories
|
| 35 |
-
AppConfig.setup_directories()
|
| 36 |
-
|
| 37 |
-
# 2. Initialize Managers
|
| 38 |
-
hf_manager = HFManager(AppConfig)
|
| 39 |
-
hf_manager.pull_datasets()
|
| 40 |
-
|
| 41 |
-
gemini_manager = GeminiManager(AppConfig.GOOGLE_API_KEY) if AppConfig.GOOGLE_API_KEY else None
|
| 42 |
-
|
| 43 |
-
# 3. Initialize Agents
|
| 44 |
-
agent1 = AgentInput()
|
| 45 |
-
agent2 = AgentInterpretation(AppConfig, gemini_manager_instance=gemini_manager)
|
| 46 |
-
agent4 = AgentTrust(AppConfig)
|
| 47 |
-
agent4.hf_manager_ref = hf_manager
|
| 48 |
-
|
| 49 |
-
# 4. Initialize The Watcher (Background Logic)
|
| 50 |
-
watcher_agent = AgentWatcher(AppConfig)
|
| 51 |
-
|
| 52 |
-
# 5. Initialize Interfaces
|
| 53 |
-
agent3 = AgentUX(agent1, agent2, agent4)
|
| 54 |
-
agent_bridge = AgentBridge(agent1, agent2, agent4)
|
| 55 |
-
agent2.ux = agent3 # Circular link for updates
|
| 56 |
-
agent3.WARNING_BEEP_PATH = create_warning_beep()
|
| 57 |
-
|
| 58 |
-
print("✅ System Assembled. Launching Interface...")
|
| 59 |
-
|
| 60 |
-
# 6. Create UIs
|
| 61 |
-
admin_ui = agent3.create_ui()
|
| 62 |
-
api_ui = agent_bridge.launch()
|
| 63 |
-
|
| 64 |
-
# 🟢 Mount globally as 'app' so Hugging Face can find it
|
| 65 |
-
app = gr.TabbedInterface(
|
| 66 |
-
[admin_ui, api_ui],
|
| 67 |
-
["👮 Admin Dashboard", "🔗 React Bridge API"]
|
| 68 |
-
)
|
| 69 |
|
| 70 |
-
|
| 71 |
-
print("
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
| 74 |
-
# 8. Local Launch Fallback
|
| 75 |
if __name__ == "__main__":
|
| 76 |
-
|
| 77 |
-
server_name="0.0.0.0",
|
| 78 |
-
server_port=7860,
|
| 79 |
-
show_error=True,
|
| 80 |
-
allowed_paths=["/app/saved_audio", "/app/iuuy_datasets", "."],
|
| 81 |
-
ssr_mode=False
|
| 82 |
-
)
|
|
|
|
|
|
|
|
|
|
| 1 |
import warnings
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
# Filter warnings immediately
|
| 4 |
warnings.filterwarnings("ignore", category=SyntaxWarning, module="pydub")
|
| 5 |
|
|
|
|
|
|
|
|
|
|
| 6 |
# --- INTERNAL IMPORTS ---
|
| 7 |
from config import AppConfig
|
| 8 |
from src.utils import create_warning_beep
|
| 9 |
+
|
| 10 |
+
# Import your refactored classes
|
| 11 |
from src.managers import GeminiManager, HFManager
|
| 12 |
from src.input_agent import AgentInput
|
| 13 |
from src.brain_agent import AgentInterpretation
|
| 14 |
from src.trust_agent import AgentTrust
|
| 15 |
from src.ux_agent import AgentUX
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
def main():
|
| 18 |
+
print("🚀 Initializing Modular Architecture IEDI (MA-IEDI)...")
|
| 19 |
+
|
| 20 |
+
# 1. Setup Configuration & Directories
|
| 21 |
+
AppConfig.setup_directories()
|
| 22 |
+
|
| 23 |
+
# 2. Initialize Managers (Inject Config)
|
| 24 |
+
# We pass AppConfig to HFManager so it knows where to download files
|
| 25 |
+
hf_manager = HFManager(AppConfig)
|
| 26 |
+
hf_manager.pull_datasets()
|
| 27 |
+
|
| 28 |
+
# Initialize Gemini (Brain Stem)
|
| 29 |
+
gemini_manager = GeminiManager(AppConfig.GOOGLE_API_KEY) if AppConfig.GOOGLE_API_KEY else None
|
| 30 |
+
|
| 31 |
+
# 3. Initialize Agents (Dependency Injection)
|
| 32 |
+
|
| 33 |
+
# Agent 1: Input (Whisper)
|
| 34 |
+
agent1 = AgentInput()
|
| 35 |
+
|
| 36 |
+
# Agent 2: Brain (Interpretation)
|
| 37 |
+
# We pass AppConfig so it knows where PROFILES_DIR is
|
| 38 |
+
agent2 = AgentInterpretation(AppConfig, gemini_manager_instance=gemini_manager)
|
| 39 |
+
|
| 40 |
+
# Agent 4: Trust (Blockchain/IPFS)
|
| 41 |
+
# We pass AppConfig so it has keys for Web3 and Pinata
|
| 42 |
+
agent4 = AgentTrust(AppConfig)
|
| 43 |
+
# Inject hf_manager into Trust so it can save audio files to HF
|
| 44 |
+
agent4.hf_manager_ref = hf_manager
|
| 45 |
+
|
| 46 |
+
# Agent 3: UX (Interface)
|
| 47 |
+
agent3 = AgentUX(agent1, agent2, agent4)
|
| 48 |
+
|
| 49 |
+
# 4. Launch
|
| 50 |
+
print("✅ System Assembled. Launching Interface...")
|
| 51 |
+
|
| 52 |
+
# Pass the warning beep path
|
| 53 |
+
agent3.WARNING_BEEP_PATH = create_warning_beep()
|
| 54 |
+
|
| 55 |
+
agent3.launch()
|
| 56 |
|
|
|
|
| 57 |
if __name__ == "__main__":
|
| 58 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|