Update app.py
Browse files
app.py
CHANGED
|
@@ -7,51 +7,56 @@ from tools.final_answer import FinalAnswerTool
|
|
| 7 |
from Gradio_UI import GradioUI
|
| 8 |
|
| 9 |
@tool
|
| 10 |
-
def
|
| 11 |
-
"""
|
| 12 |
-
|
| 13 |
Args:
|
| 14 |
-
topic:
|
| 15 |
-
|
| 16 |
"""
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
| 18 |
modifiers = [
|
| 19 |
-
"
|
| 20 |
-
"
|
| 21 |
-
"
|
|
|
|
|
|
|
| 22 |
]
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
"быстро", "эффективно", "просто",
|
| 27 |
-
"в 2025 году", "онлайн", "на практике"
|
| 28 |
-
]
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
#
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
keyword_type = random.randint(1, 3)
|
| 39 |
-
|
| 40 |
-
if keyword_type == 1:
|
| 41 |
-
keyword = f"{random.choice(modifiers)} {topic}"
|
| 42 |
-
elif keyword_type == 2:
|
| 43 |
-
keyword = f"{topic} {random.choice(suffixes)}"
|
| 44 |
-
else:
|
| 45 |
-
keyword = f"{random.choice(modifiers)} {topic} {random.choice(suffixes)}"
|
| 46 |
-
|
| 47 |
-
keywords.add(keyword)
|
| 48 |
|
| 49 |
-
#
|
| 50 |
-
|
| 51 |
-
for i, keyword in enumerate(keywords, 1):
|
| 52 |
-
response += f"{i}. {keyword}\n"
|
| 53 |
-
|
| 54 |
-
return response
|
| 55 |
|
| 56 |
# Initialize components
|
| 57 |
final_answer = FinalAnswerTool()
|
|
@@ -75,7 +80,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 75 |
agent = CodeAgent(
|
| 76 |
tools=[
|
| 77 |
image_generation_tool,
|
| 78 |
-
|
| 79 |
final_answer,
|
| 80 |
DuckDuckGoSearchTool()
|
| 81 |
],
|
|
|
|
| 7 |
from Gradio_UI import GradioUI
|
| 8 |
|
| 9 |
@tool
|
| 10 |
+
def keyword_research_tool(topic: str, max_results: int) -> str:
|
| 11 |
+
"""Генерирует релевантные ключевые слова для заданной темы
|
|
|
|
| 12 |
Args:
|
| 13 |
+
topic: Основная тема для генерации ключевых слов
|
| 14 |
+
max_results: Максимальное количество возвращаемых ключевых слов
|
| 15 |
"""
|
| 16 |
+
import random
|
| 17 |
+
from typing import List
|
| 18 |
+
|
| 19 |
+
# Базовые модификаторы для расширения темы
|
| 20 |
modifiers = [
|
| 21 |
+
"лучшие", "топ", "как", "советы", "рецепты",
|
| 22 |
+
"польза", "вред", "отзывы", "купить", "сделать",
|
| 23 |
+
"обзор", "курс", "уроки", "для начинающих",
|
| 24 |
+
"2023", "идеи", "примеры", "методы", "технологии",
|
| 25 |
+
"тренды", "планы", "стоимость", "бесплатно", "преимущества"
|
| 26 |
]
|
| 27 |
|
| 28 |
+
# Разбиваем тему на основные слова
|
| 29 |
+
seed_words = [word.strip() for word in topic.split() if len(word) > 3]
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
# Генерируем комбинации
|
| 32 |
+
candidates = set()
|
| 33 |
+
|
| 34 |
+
# Добавляем базовые варианты
|
| 35 |
+
candidates.add(topic)
|
| 36 |
+
candidates.add(f"лучшие {topic}")
|
| 37 |
+
candidates.add(f"{topic} 2023")
|
| 38 |
+
|
| 39 |
+
# Генерируем комбинации с модификаторами
|
| 40 |
+
for modifier in modifiers:
|
| 41 |
+
candidates.add(f"{modifier} {topic}")
|
| 42 |
+
candidates.add(f"{topic} {modifier}")
|
| 43 |
+
for word in seed_words:
|
| 44 |
+
candidates.add(f"{modifier} {word}")
|
| 45 |
+
candidates.add(f"{word} {modifier}")
|
| 46 |
|
| 47 |
+
# Добавляем вопросы
|
| 48 |
+
question_words = ["как", "что", "где", "когда", "почему"]
|
| 49 |
+
for qw in question_words:
|
| 50 |
+
candidates.add(f"{qw} {topic}")
|
| 51 |
+
for word in seed_words:
|
| 52 |
+
candidates.add(f"{qw} {word}")
|
| 53 |
|
| 54 |
+
# Преобразуем в список и перемешиваем
|
| 55 |
+
results = list(candidates)
|
| 56 |
+
random.shuffle(results)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
+
# Выбираем запрошенное количество
|
| 59 |
+
return ", ".join(results[:max(max_results, 1)])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
# Initialize components
|
| 62 |
final_answer = FinalAnswerTool()
|
|
|
|
| 80 |
agent = CodeAgent(
|
| 81 |
tools=[
|
| 82 |
image_generation_tool,
|
| 83 |
+
keyword_research_tool,
|
| 84 |
final_answer,
|
| 85 |
DuckDuckGoSearchTool()
|
| 86 |
],
|