Spaces:
Sleeping
Sleeping
add spam topic check
Browse files
app.py
CHANGED
|
@@ -13,7 +13,7 @@ from Gradio_UI import GradioUI
|
|
| 13 |
|
| 14 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 15 |
@tool
|
| 16 |
-
def
|
| 17 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 18 |
"""A tool that does nothing yet
|
| 19 |
Args:
|
|
@@ -22,6 +22,33 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 22 |
"""
|
| 23 |
return "What magic will you build ?"
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
@tool
|
| 26 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 27 |
"""A tool that fetches the current local time in a specified timezone.
|
|
@@ -62,7 +89,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 62 |
|
| 63 |
agent = CodeAgent(
|
| 64 |
model=model,
|
| 65 |
-
tools=[final_answer, get_current_time_in_timezone, web_searh, visit_website], ## add your tools here (don't remove final answer)
|
| 66 |
max_steps=6,
|
| 67 |
verbosity_level=1,
|
| 68 |
grammar=None,
|
|
|
|
| 13 |
|
| 14 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 15 |
@tool
|
| 16 |
+
def text_analyse_for_spam(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
| 17 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 18 |
"""A tool that does nothing yet
|
| 19 |
Args:
|
|
|
|
| 22 |
"""
|
| 23 |
return "What magic will you build ?"
|
| 24 |
|
| 25 |
+
@tool
|
| 26 |
+
def text_analyse_for_spam(text: str, dummy: int) -> str:
|
| 27 |
+
"""
|
| 28 |
+
Analyzes the text for sensitive topics.
|
| 29 |
+
|
| 30 |
+
Args:
|
| 31 |
+
text: The text to analyze.
|
| 32 |
+
dummy: An unused parameter (kept for compatibility).
|
| 33 |
+
|
| 34 |
+
Returns:
|
| 35 |
+
A string indicating which sensitive topics were detected, if any.
|
| 36 |
+
"""
|
| 37 |
+
# Convert text to lowercase for case-insensitive matching.
|
| 38 |
+
text_lower = text.lower()
|
| 39 |
+
|
| 40 |
+
# List of sensitive topics to check for.
|
| 41 |
+
sensitive_topics = ["casino", "info scam", "sick relative"]
|
| 42 |
+
|
| 43 |
+
# Identify any topics present in the text.
|
| 44 |
+
detected_topics = [topic for topic in sensitive_topics if topic in text_lower]
|
| 45 |
+
|
| 46 |
+
if detected_topics:
|
| 47 |
+
return f"Detected topics: {', '.join(detected_topics)}."
|
| 48 |
+
else:
|
| 49 |
+
return "No sensitive topics detected."
|
| 50 |
+
|
| 51 |
+
|
| 52 |
@tool
|
| 53 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 54 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 89 |
|
| 90 |
agent = CodeAgent(
|
| 91 |
model=model,
|
| 92 |
+
tools=[final_answer, get_current_time_in_timezone, web_searh, visit_website, text_analyse_for_spam], ## add your tools here (don't remove final answer)
|
| 93 |
max_steps=6,
|
| 94 |
verbosity_level=1,
|
| 95 |
grammar=None,
|