Spaces:
Runtime error
Runtime error
| from langdetect import detect | |
| def choose_model(user_input: str) -> str: | |
| """ | |
| Автоматически подбирает оптимальную модель Hugging Face | |
| в зависимости от языка, задачи и сложности запроса. | |
| """ | |
| text = user_input.lower() | |
| # Определяем язык | |
| try: | |
| lang = detect(user_input) | |
| except: | |
| lang = "en" | |
| # === Категории задач === | |
| if any(x in text for x in ["код", "python", "script", "программа", "function", "code"]): | |
| return "codellama/CodeLlama-7b-Instruct-hf" | |
| elif any(x in text for x in ["анализ", "объясни", "научи", "почему", "как работает"]): | |
| return "mistralai/Mistral-7B-Instruct-v0.3" | |
| elif any(x in text for x in ["текст", "переведи", "история", "расскажи", "объяснение"]): | |
| return "google/gemma-2b-it" | |
| elif any(x in text for x in ["чат", "ответь", "расскажи про", "что такое"]): | |
| return "microsoft/Phi-3-mini-4k-instruct" | |
| # === fallback === | |
| if lang != "ru": | |
| return "mistralai/Mistral-7B-Instruct-v0.3" | |
| return "microsoft/Phi-3-mini-4k-instruct" | |