Spaces:
Runtime error
Runtime error
Add kroni diagram creation to app.py
Browse files
app.py
CHANGED
|
@@ -47,7 +47,29 @@ def create_new_vday_card_tool(theme:str) -> str: #it's import to specify the ret
|
|
| 47 |
#image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 48 |
|
| 49 |
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
@tool
|
| 52 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
| 53 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
|
@@ -57,6 +79,7 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
|
|
| 57 |
arg2: the second argument
|
| 58 |
"""
|
| 59 |
return "What magic will you build ?"
|
|
|
|
| 60 |
@tool
|
| 61 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 62 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 47 |
#image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 48 |
|
| 49 |
|
| 50 |
+
# Below is an example of a tool that calls kroki api for creating amazing diagrams!
|
| 51 |
+
@tool
|
| 52 |
+
def generate_kroni_diagram(diagram_type:str, diagram_source:str) -> str: #it's import to specify the return type
|
| 53 |
+
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 54 |
+
"""A tool that calls the Kroki API to generate a diagram from textual input
|
| 55 |
+
Args:
|
| 56 |
+
diagram_type: The type of diagram (e.g., "mermaid", "graphviz").
|
| 57 |
+
diagram_source: The diagram source text in the respective format.
|
| 58 |
+
"""
|
| 59 |
+
url = f"https://kroki.io/{diagram_type}/svg"
|
| 60 |
+
headers = {"Content-Type": "text/plain"}
|
| 61 |
+
|
| 62 |
+
response = requests.post(url, headers=headers, data=diagram_source)
|
| 63 |
+
|
| 64 |
+
if response.status_code == 200:
|
| 65 |
+
svg_content = response.text # SVG content
|
| 66 |
+
encoded_svg = base64.b64encode(svg_content.encode('utf-8')).decode('utf-8')
|
| 67 |
+
html = f'<img src="data:image/svg+xml;base64,{encoded_svg}" />'
|
| 68 |
+
return html
|
| 69 |
+
else:
|
| 70 |
+
return f"Error: {response.status_code} - {response.text}"
|
| 71 |
+
|
| 72 |
+
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 73 |
@tool
|
| 74 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
| 75 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
|
|
|
| 79 |
arg2: the second argument
|
| 80 |
"""
|
| 81 |
return "What magic will you build ?"
|
| 82 |
+
|
| 83 |
@tool
|
| 84 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 85 |
"""A tool that fetches the current local time in a specified timezone.
|