Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,12 @@ from tools.final_answer import FinalAnswerTool
|
|
| 8 |
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 my_custom_tool(arg1:str, arg2:int)-> 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
|
|
@@ -32,7 +38,48 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 32 |
return f"The current local time in {timezone} is: {local_time}"
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
|
|
|
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
| 38 |
|
|
@@ -55,7 +102,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 55 |
|
| 56 |
agent = CodeAgent(
|
| 57 |
model=model,
|
| 58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
| 59 |
max_steps=6,
|
| 60 |
verbosity_level=1,
|
| 61 |
grammar=None,
|
|
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
+
def parse_date(date_str: str) -> datetime.datetime: # Note the type hint change
|
| 12 |
+
try:
|
| 13 |
+
return parser.parse(date_str)
|
| 14 |
+
except:
|
| 15 |
+
return datetime.datetime.now()
|
| 16 |
+
|
| 17 |
@tool
|
| 18 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
| 19 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
|
|
|
| 38 |
return f"The current local time in {timezone} is: {local_time}"
|
| 39 |
except Exception as e:
|
| 40 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 41 |
+
|
| 42 |
+
@tool
|
| 43 |
+
def get_horoscope(sign: str, date: str = None, language: str = "EN") -> str:
|
| 44 |
+
"""Fetches the horoscope for a given zodiac sign and date.
|
| 45 |
+
Uses the ExaWeb API. Defaults to today if no date is provided.
|
| 46 |
+
|
| 47 |
+
Args:
|
| 48 |
+
sign: Zodiac sign (e.g., Aries, Taurus, Gemini)
|
| 49 |
+
date: Date in any format (optional)
|
| 50 |
+
language: Language code (e.g., 'EN' for English, 'HI' for Hindi)
|
| 51 |
+
"""
|
| 52 |
+
try:
|
| 53 |
+
if date:
|
| 54 |
+
date_obj = parse_date(date)
|
| 55 |
+
else:
|
| 56 |
+
date_obj = datetime.datetime.now()
|
| 57 |
+
|
| 58 |
+
formatted_date = date_obj.strftime("%d-%m-%Y")
|
| 59 |
+
|
| 60 |
+
params = {
|
| 61 |
+
"rashi": sign.upper(),
|
| 62 |
+
"language": language,
|
| 63 |
+
"day": formatted_date # Always include the formatted day
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
url = "https://api.exaweb.in:3004/api/rashi"
|
| 67 |
+
response = requests.get(url, params=params)
|
| 68 |
+
response.raise_for_status()
|
| 69 |
+
data = response.json()
|
| 70 |
+
|
| 71 |
+
sign_upper = sign.upper()
|
| 72 |
+
sign_data = data.get(sign_upper)
|
| 73 |
+
|
| 74 |
+
if sign_data:
|
| 75 |
+
return sign_data
|
| 76 |
+
|
| 77 |
+
return f"No horoscope found for sign: {sign}"
|
| 78 |
+
|
| 79 |
+
except Exception as e:
|
| 80 |
+
return f"Error fetching horoscope: {str(e)}"
|
| 81 |
|
| 82 |
+
|
| 83 |
|
| 84 |
final_answer = FinalAnswerTool()
|
| 85 |
|
|
|
|
| 102 |
|
| 103 |
agent = CodeAgent(
|
| 104 |
model=model,
|
| 105 |
+
tools=[final_answer, get_horoscope], ## add your tools here (don't remove final answer)
|
| 106 |
max_steps=6,
|
| 107 |
verbosity_level=1,
|
| 108 |
grammar=None,
|