Spaces:
Sleeping
Sleeping
File size: 3,410 Bytes
ce0ec3b 652f14d |
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 |
"""
Configuration parameters for the Lyrics Analyzer Agent.
This module separates configuration from implementation,
making it easier to modify settings without changing code.
"""
import os
import yaml
from loguru import logger
# Logger configuration
def setup_logger():
"""Configure loguru logger with custom formatting."""
logger.remove() # Remove default handlers
logger.add(
lambda msg: print(msg, end=""),
level="INFO",
format="<green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{level: <8}</level> | <cyan>{message}</cyan>"
)
# API configuration
def load_api_keys():
"""Load API keys from environment variables."""
# Gemini API is the default
os.environ["GEMINI_API_KEY"] = os.getenv("GEMINI_API_KEY")
# Anthropic API for local testing
if use_anthropic():
os.environ["ANTHROPIC_API_KEY"] = os.getenv("ANTHROPIC_API_KEY")
# Default model configuration
def use_anthropic():
"""Check if we should use Anthropic instead of Gemini."""
return os.getenv("USE_ANTHROPIC", "false").lower() == "true"
def get_model_id():
"""Get the appropriate model ID based on configuration."""
if use_anthropic():
return "claude-3-haiku-20240307"
else:
return "gemini/gemini-2.0-flash"
# Load prompts from YAML
def load_prompt_templates():
"""Load prompt templates from YAML file."""
try:
with open("prompts.yaml", 'r') as stream:
return yaml.safe_load(stream)
except (FileNotFoundError, yaml.YAMLError) as e:
logger.error(f"Error loading prompts.yaml: {e}")
return {} # Return empty dict to avoid breaking the application
# Tool configuration
SEARCH_TOOL_CONFIG = {
"min_delay": 3.0,
"max_delay": 7.0
}
# Agent configuration
AGENT_CONFIG = {
"web_agent": {
"max_steps": 50,
"verbosity_level": 2,
"description": "Browses the web to find original full lyrics and scrape them. Excels at building effective search queries"
},
"analysis_agent": {
"max_steps": 5,
"verbosity_level": 2,
"description": "You are a Song Analysis Expert with deep knowledge of music theory, lyrical interpretation, cultural contexts, and music history. Your role is to analyze song lyrics to uncover their deeper meaning, artistic significance, and historical context."
},
"manager_agent": {
"max_steps": 15,
"verbosity_level": 2,
"planning_interval": 5,
"description": "Manages the search process and coordinates the search and analysis of song lyrics."
}
}
# Gradio UI configuration
def get_gradio_config(is_test=True):
"""Get the appropriate Gradio UI configuration based on environment.
Args:
is_test: If True, use test configuration (local development).
If False, use production configuration (HuggingFace).
Returns:
Dictionary with Gradio configuration parameters.
"""
if is_test:
# Configuration for local development/testing
return {
"debug": True,
"share": False,
"server_name": "127.0.0.1",
"server_port": 3000
}
else:
# Configuration for production (HuggingFace)
return {
"debug": True,
"share": False
# No server_name or server_port for HuggingFace deployment
}
|