Update app.py
Browse files
app.py
CHANGED
@@ -10,29 +10,53 @@ from Gradio_UI import GradioUI
|
|
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,
|
14 |
-
"""
|
15 |
Args:
|
16 |
-
topic:
|
17 |
-
|
18 |
"""
|
19 |
-
# Basic
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
#
|
23 |
-
|
24 |
-
filtered_words = [word for word in words if len(word) > 2 and word not in stopwords]
|
25 |
|
26 |
-
|
27 |
-
keyword_frequency = {}
|
28 |
-
for word in filtered_words:
|
29 |
-
keyword_frequency[word] = keyword_frequency.get(word, 0) + 1
|
30 |
|
31 |
-
#
|
32 |
-
|
33 |
-
top_keywords = sorted_keywords[:max_keywords]
|
34 |
|
35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
|
38 |
@tool
|
|
|
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, num_keywords: int = 5) -> str:
|
14 |
+
"""Generates relevant keywords based on the given topic
|
15 |
Args:
|
16 |
+
topic: The main topic or subject to generate keywords for
|
17 |
+
num_keywords: Number of keywords to generate (default: 5)
|
18 |
"""
|
19 |
+
# Basic word transformations and common patterns
|
20 |
+
prefixes = ['best', 'top', 'how to', 'why', 'what is']
|
21 |
+
suffixes = ['guide', 'tutorial', 'examples', 'tips', 'basics']
|
22 |
+
related_terms = {
|
23 |
+
'programming': ['coding', 'development', 'software', 'algorithms', 'debugging'],
|
24 |
+
'business': ['marketing', 'strategy', 'management', 'startup', 'planning'],
|
25 |
+
'technology': ['tech', 'innovation', 'digital', 'software', 'hardware'],
|
26 |
+
'education': ['learning', 'teaching', 'study', 'course', 'training'],
|
27 |
+
'health': ['wellness', 'fitness', 'nutrition', 'medical', 'healthcare']
|
28 |
+
}
|
29 |
|
30 |
+
# Clean and normalize the input topic
|
31 |
+
topic = topic.lower().strip()
|
|
|
32 |
|
33 |
+
keywords = set()
|
|
|
|
|
|
|
34 |
|
35 |
+
# Add the original topic
|
36 |
+
keywords.add(topic)
|
|
|
37 |
|
38 |
+
# Add prefix + topic combinations
|
39 |
+
for prefix in prefixes:
|
40 |
+
keywords.add(f"{prefix} {topic}")
|
41 |
+
|
42 |
+
# Add topic + suffix combinations
|
43 |
+
for suffix in suffixes:
|
44 |
+
keywords.add(f"{topic} {suffix}")
|
45 |
+
|
46 |
+
# Add related terms if the topic matches any category
|
47 |
+
for category, terms in related_terms.items():
|
48 |
+
if topic in terms or category in topic:
|
49 |
+
keywords.update(terms)
|
50 |
+
|
51 |
+
# Select the most relevant keywords
|
52 |
+
final_keywords = list(keywords)[:num_keywords]
|
53 |
+
|
54 |
+
# Format the output
|
55 |
+
return "\n".join([
|
56 |
+
"Generated keywords:",
|
57 |
+
"----------------",
|
58 |
+
*[f"- {keyword}" for keyword in final_keywords]
|
59 |
+
])
|
60 |
|
61 |
|
62 |
@tool
|