Spaces:
Sleeping
Sleeping
File size: 2,334 Bytes
ce0ec3b de58e79 ce0ec3b 775ea0b 8fca8f3 ce0ec3b 013068f 775ea0b 8fca8f3 013068f ce0ec3b 013068f ce0ec3b 013068f ce0ec3b 05a3ce6 1841510 8fca8f3 ce0ec3b 1841510 ce0ec3b 8fca8f3 0e9bb01 013068f ce0ec3b 775ea0b ce0ec3b 652f14d 775ea0b 652f14d 775ea0b ce0ec3b |
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 |
#!/usr/bin/env python3
"""
Lyrics Analyzer Agent - Main Entry Point
This module serves as the entry point for the Lyrics Analyzer application, which
uses a system of specialized agents to search for and analyze song lyrics.
"""
import os
from loguru import logger
from smolagents import LiteLLMModel
from agents.single_agent import create_single_agent
from config import (
get_gradio_config,
get_model_id,
get_ollama_api_base,
load_api_keys,
setup_logger,
)
from Gradio_UI import GradioUI
def main():
"""
Main function to initialize and run the Lyrics Analyzer Agent.
This function sets up logging, loads API keys, initializes the LLM model,
and starts the Gradio UI server with the manager agent.
"""
# Setup logger and API keys
setup_logger()
load_api_keys()
is_test = os.environ.get('SPACE_ID') is None
# If using Ollama, we need to specify the API base URL
# Initialize the LLM model based on configuration
model_id = get_model_id(is_test=is_test)
logger.info(f"Initializing with model: {model_id}")
if is_test:
api_base = get_ollama_api_base()
logger.info(f"Using Ollama API base: {api_base}")
model = LiteLLMModel(model_id=model_id, api_base=api_base)
else:
model = LiteLLMModel(model_id=model_id)
# Create the manager agent which will create and manage the other agents
single_agent = create_single_agent(model)
# Start the Gradio UI server
logger.info("Initializing Gradio UI and launching server")
# Determine if we're in test mode (local) or production (HuggingFace)
# HuggingFace environment has SPACE_ID environment variable
gradio_config = get_gradio_config(is_test)
# Launch with appropriate configuration
launch_kwargs = {
"debug": gradio_config["debug"],
"share": gradio_config["share"]
}
# Add server parameters only for local testing
if is_test:
launch_kwargs.update({
"server_name": gradio_config["server_name"],
"server_port": gradio_config["server_port"]
})
GradioUI(single_agent).launch(**launch_kwargs)
logger.success("Server started successfully")
# Run the application when executed directly
if __name__ == "__main__":
main()
|