Spaces:
Runtime error
Runtime error
| from tools.web_search import DuckDuckGoSearchTool | |
| from tools.final_answer import FinalAnswerTool | |
| from tools.healthcare_llm_visualizer import HealthcareLLMVisualizerTool | |
| from Gradio_UI import GradioUI | |
| from agent import ResearchAgent | |
| from model_init import ModelInitializer # Новий імпорт | |
| import os | |
| from dotenv import load_dotenv | |
| import logging | |
| from pathlib import Path | |
| # Налаштування логування | |
| logging.basicConfig( | |
| level=logging.INFO, | |
| format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', | |
| handlers=[ | |
| logging.FileHandler('research_agent.log'), | |
| logging.StreamHandler() | |
| ] | |
| ) | |
| logger = logging.getLogger(__name__) | |
| # Завантаження змінних середовища | |
| load_dotenv() | |
| def initialize_tools(): | |
| """Ініціалізація всіх доступних інструментів""" | |
| logger.info("Ініціалізація інструментів...") | |
| try: | |
| tools = [ | |
| DuckDuckGoSearchTool( | |
| max_results=int(os.getenv('MAX_SEARCH_RESULTS', 10)) | |
| ), | |
| FinalAnswerTool(), | |
| HealthcareLLMVisualizerTool() | |
| ] | |
| logger.info("Інструменти успішно ініціалізовано") | |
| return tools | |
| except Exception as e: | |
| logger.error(f"Помилка ініціалізації інструментів: {e}") | |
| raise | |
| def initialize_model(model_key=None): | |
| """Ініціалізація моделі""" | |
| logger.info("Ініціалізація мовної моделі...") | |
| try: | |
| config_path = Path("models_config.json") | |
| model_initializer = ModelInitializer(config_path) | |
| model = model_initializer.initialize_model(model_key) | |
| if model_key: | |
| logger.info(f"Модель ініціалізовано: {model_key}") | |
| else: | |
| logger.info("Ініціалізовано модель за замовчуванням") | |
| return model, model_initializer | |
| except Exception as e: | |
| logger.error(f"Помилка ініціалізації моделі: {e}") | |
| raise | |
| def main(): | |
| """Головна точка входу в програму""" | |
| try: | |
| logger.info("Запуск Research Agent...") | |
| # Ініціалізація компонентів | |
| tools = initialize_tools() | |
| model, model_initializer = initialize_model() | |
| # Ініціалізація дослідницького агента | |
| agent = ResearchAgent( | |
| model=model, | |
| tools=tools, | |
| max_steps=int(os.getenv('MAX_STEPS', 10)), | |
| verbosity_level=int(os.getenv('VERBOSITY_LEVEL', 1)) | |
| ) | |
| # Додавання model_initializer до агента для можливості зміни моделі | |
| agent.model_initializer = model_initializer | |
| # Запуск інтерфейсу | |
| logger.info("Запуск Gradio інтерфейсу...") | |
| ui = GradioUI(agent) | |
| ui.launch( | |
| debug=os.getenv('DEBUG_MODE', 'False').lower() == 'true', | |
| share=os.getenv('SHARE_GRADIO', 'True').lower() == 'true', | |
| server_name=os.getenv('GRADIO_SERVER_NAME', '0.0.0.0'), | |
| server_port=int(os.getenv('GRADIO_SERVER_PORT', 7860)) | |
| ) | |
| except Exception as e: | |
| logger.error(f"Помилка запуску програми: {e}") | |
| raise | |
| if __name__ == "__main__": | |
| main() |