Spaces:
Sleeping
Sleeping
Created first tool in app.py
Browse files
app.py
CHANGED
|
@@ -9,14 +9,33 @@ 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 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
-
"""A tool that
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
|
|
|
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def get_sc_name(common_name:str)-> str: #it's import to specify the return type
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 14 |
+
"""A tool that fetches scientific name of a living organism.
|
| 15 |
Args:
|
| 16 |
+
common_name: A string representing a living object whose scientic name we want (e.g., 'crow', or, 'basil')
|
| 17 |
+
Returns:
|
| 18 |
+
sc_name: A string containing scientific name of the provided organism
|
| 19 |
"""
|
| 20 |
+
try:
|
| 21 |
+
# Fetch the scientific name using DuckDuckGo
|
| 22 |
+
|
| 23 |
+
#create an instance of DuckDuckGo tool
|
| 24 |
+
web_tool = DuckDuckGoSearchTool()
|
| 25 |
+
|
| 26 |
+
#query
|
| 27 |
+
query = f"What is the scientific name of {common_name}?"
|
| 28 |
+
|
| 29 |
+
#get result
|
| 30 |
+
result = web_tool(query)
|
| 31 |
+
|
| 32 |
+
if result and isinstance(result, list):
|
| 33 |
+
for r in result:
|
| 34 |
+
if "scientific name" in r.lower():
|
| 35 |
+
return f"The scientific name of {common_name} is: {result}."
|
| 36 |
+
return "Could not find the scientific name. Please try a more specific name."
|
| 37 |
+
except Exception as e:
|
| 38 |
+
return f"Error fetching scientific name for '{common_name}':{str(e)}"
|
| 39 |
|
| 40 |
@tool
|
| 41 |
def get_current_time_in_timezone(timezone: str) -> str:
|