Update app.py
Browse files
app.py
CHANGED
|
@@ -8,15 +8,32 @@ from tools.final_answer import FinalAnswerTool
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity!
|
|
|
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
"""A tool that generate keywords by the topic
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -51,7 +68,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 51 |
|
| 52 |
agent = CodeAgent(
|
| 53 |
model=model,
|
| 54 |
-
tools=[final_answer,
|
| 55 |
max_steps=6,
|
| 56 |
verbosity_level=1,
|
| 57 |
grammar=None,
|
|
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity!
|
| 11 |
+
|
| 12 |
@tool
|
| 13 |
+
def generate_keywords(topic: str, max_keywords: int) -> str:
|
| 14 |
+
"""A tool that generates the most relevant keywords based on a given topic.
|
|
|
|
| 15 |
Args:
|
| 16 |
+
topic: the subject or theme for which keywords need to be generated
|
| 17 |
+
max_keywords: the maximum number of keywords to generate
|
| 18 |
"""
|
| 19 |
+
# Basic preprocessing to remove common stopwords (without external libraries)
|
| 20 |
+
stopwords = set(["и", "в", "на", "с", "по", "для", "как", "что", "это", "а", "но", "я", "у", "за", "из", "о", "об", "от"])
|
| 21 |
+
|
| 22 |
+
# Splitting the topic into words and filtering out short words and stopwords
|
| 23 |
+
words = topic.lower().split()
|
| 24 |
+
filtered_words = [word for word in words if len(word) > 2 and word not in stopwords]
|
| 25 |
+
|
| 26 |
+
# Generating unique keywords by frequency and limiting to max_keywords
|
| 27 |
+
keyword_frequency = {}
|
| 28 |
+
for word in filtered_words:
|
| 29 |
+
keyword_frequency[word] = keyword_frequency.get(word, 0) + 1
|
| 30 |
+
|
| 31 |
+
# Sorting keywords by frequency (descending) and selecting top ones
|
| 32 |
+
sorted_keywords = sorted(keyword_frequency.keys(), key=lambda x: keyword_frequency[x], reverse=True)
|
| 33 |
+
top_keywords = sorted_keywords[:max_keywords]
|
| 34 |
+
|
| 35 |
+
return ", ".join(top_keywords) if top_keywords else "Нет релевантных ключевых слов"
|
| 36 |
+
|
| 37 |
|
| 38 |
@tool
|
| 39 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 68 |
|
| 69 |
agent = CodeAgent(
|
| 70 |
model=model,
|
| 71 |
+
tools=[final_answer, generate_keywords], # add your tools here (don't remove final_answer)
|
| 72 |
max_steps=6,
|
| 73 |
verbosity_level=1,
|
| 74 |
grammar=None,
|