AiWicked commited on
Commit
1056355
·
verified ·
1 Parent(s): 486555d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -37
app.py CHANGED
@@ -7,51 +7,56 @@ from tools.final_answer import FinalAnswerTool
7
  from Gradio_UI import GradioUI
8
 
9
  @tool
10
- def generate_keywords(topic: str, num_keywords: int) -> str:
11
- """A tool that generates relevant keywords for a given topic
12
-
13
  Args:
14
- topic: The main topic or subject area to generate keywords for
15
- num_keywords: Number of keywords to generate (1-20)
16
  """
17
- # Common keyword patterns and modifiers
 
 
 
18
  modifiers = [
19
- "как", "почему", "что такое", "топ", "лучший",
20
- "обзор", "руководство", "советы", "примеры",
21
- "методы", "способы", "виды", "типы"
 
 
22
  ]
23
 
24
- suffixes = [
25
- "для начинающих", "пошагово", нуля",
26
- "быстро", "эффективно", "просто",
27
- "в 2025 году", "онлайн", "на практике"
28
- ]
29
 
30
- import random
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
- # Ensure number of keywords is within reasonable range
33
- num_keywords = max(1, min(20, num_keywords))
 
 
 
 
34
 
35
- # Generate keyword combinations
36
- keywords = set()
37
- while len(keywords) < num_keywords:
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
- # Format the response
50
- response = f"""Ключевые слова по теме "{topic}":\n\n"""
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
- generate_keywords,
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
  ],