Spaces:
Runtime error
Runtime error
Andre Pettersson
commited on
Leet speak added
Browse files
app.py
CHANGED
|
@@ -36,14 +36,47 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 36 |
except Exception as e:
|
| 37 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
#Lib tools
|
| 40 |
visit_webpage = VisitWebpageTool()
|
| 41 |
final_answer = FinalAnswerTool()
|
| 42 |
web_search = DuckDuckGoSearchTool()
|
|
|
|
|
|
|
| 43 |
|
| 44 |
# Import tool from Hub
|
| 45 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 46 |
-
translate_tool = load_tool("Iker/Translate-100-languages", trust_remote_code=True)
|
| 47 |
|
| 48 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
| 49 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
@@ -61,7 +94,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 61 |
|
| 62 |
agent = CodeAgent(
|
| 63 |
model=model,
|
| 64 |
-
tools=[final_answer, visit_webpage, web_search, image_generation_tool,
|
| 65 |
max_steps=6,
|
| 66 |
verbosity_level=1,
|
| 67 |
grammar=None,
|
|
|
|
| 36 |
except Exception as e:
|
| 37 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 38 |
|
| 39 |
+
@tool
|
| 40 |
+
def to_leet_speak(text):
|
| 41 |
+
"""
|
| 42 |
+
Converts a string to l33t speak using a substitution table.
|
| 43 |
+
|
| 44 |
+
Args:
|
| 45 |
+
text (str): The input string to convert.
|
| 46 |
+
|
| 47 |
+
Returns:
|
| 48 |
+
str: The converted l33t speak string.
|
| 49 |
+
"""
|
| 50 |
+
# Substitution table
|
| 51 |
+
leet_table_basic = {
|
| 52 |
+
'a': '4',
|
| 53 |
+
'b': '8',
|
| 54 |
+
'e': '3',
|
| 55 |
+
'g': '6',
|
| 56 |
+
'i': '1',
|
| 57 |
+
'l': '1',
|
| 58 |
+
'o': '0',
|
| 59 |
+
's': '5',
|
| 60 |
+
't': '7',
|
| 61 |
+
'z': '2'
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
# Convert the text to l33t speak
|
| 65 |
+
leet_text = []
|
| 66 |
+
for char in text.lower(): # Convert to lowercase for case-insensitive matching
|
| 67 |
+
leet_text.append(leet_table_basic.get(char, char)) # Use substitution if available, else keep the original character
|
| 68 |
+
|
| 69 |
+
return ''.join(leet_text)
|
| 70 |
+
|
| 71 |
#Lib tools
|
| 72 |
visit_webpage = VisitWebpageTool()
|
| 73 |
final_answer = FinalAnswerTool()
|
| 74 |
web_search = DuckDuckGoSearchTool()
|
| 75 |
+
to_leet_speak_converter = to_leet_speak()
|
| 76 |
+
|
| 77 |
|
| 78 |
# Import tool from Hub
|
| 79 |
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
|
|
|
| 80 |
|
| 81 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
| 82 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
|
|
| 94 |
|
| 95 |
agent = CodeAgent(
|
| 96 |
model=model,
|
| 97 |
+
tools=[final_answer, visit_webpage, web_search, image_generation_tool, to_leet_speak_converter], ## add your tools here (don't remove final answer)
|
| 98 |
max_steps=6,
|
| 99 |
verbosity_level=1,
|
| 100 |
grammar=None,
|