Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
| 7 |
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
|
@@ -69,40 +70,29 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 69 |
return f"The current local time in {timezone} is: {local_time}"
|
| 70 |
except Exception as e:
|
| 71 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 72 |
-
|
| 73 |
@tool
|
| 74 |
-
def
|
|
|
|
| 75 |
Get horoscope from API for specified zodiac sign.
|
| 76 |
|
| 77 |
Args:
|
| 78 |
-
zodiac_sign: Zodiac sign in English
|
| 79 |
-
|
| 80 |
|
| 81 |
Returns:
|
| 82 |
-
Horoscope text
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
|
| 94 |
-
if response.status_code == 200:
|
| 95 |
-
data = response.json()
|
| 96 |
-
horoscope = data.get('data', {}).get('horoscope_data', 'Horoscope not found')
|
| 97 |
-
return f"Horoscope for {zodiac_sign.capitalize()} for {period}:\n\n{horoscope}"
|
| 98 |
-
else:
|
| 99 |
-
return f"API Error: Failed to get horoscope (status: {response.status_code})"
|
| 100 |
-
|
| 101 |
-
except ImportError:
|
| 102 |
-
return "Error: Requests library not installed"
|
| 103 |
-
except Exception as e:
|
| 104 |
-
return f"Error getting horoscope from API: {str(e)}"
|
| 105 |
-
"""
|
| 106 |
|
| 107 |
final_answer = FinalAnswerTool()
|
| 108 |
|
|
@@ -125,7 +115,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 125 |
|
| 126 |
agent = CodeAgent(
|
| 127 |
model=model,
|
| 128 |
-
tools=[final_answer, get_weather, web_search, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
|
| 129 |
max_steps=6,
|
| 130 |
verbosity_level=1,
|
| 131 |
grammar=None,
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
from bs4 import BeautifulSoup
|
| 8 |
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
|
|
|
| 70 |
return f"The current local time in {timezone} is: {local_time}"
|
| 71 |
except Exception as e:
|
| 72 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 73 |
+
|
| 74 |
@tool
|
| 75 |
+
def get_horoscope(zodiac_sign: str, day: str = 'today') -> str:
|
| 76 |
+
"""
|
| 77 |
Get horoscope from API for specified zodiac sign.
|
| 78 |
|
| 79 |
Args:
|
| 80 |
+
zodiac_sign: Zodiac sign in English - 'aries','taurus','gemini','cancer','leo','virgo','libra','scorpio','sagittarius','capricorn','aquarius','pisces'
|
| 81 |
+
day: Day - 'today', 'tomorrow', 'yesterday'
|
| 82 |
|
| 83 |
Returns:
|
| 84 |
+
Horoscope text
|
| 85 |
+
"""
|
| 86 |
+
url = (
|
| 87 |
+
"https://www.horoscope.com/us/horoscopes/general/"
|
| 88 |
+
f"horoscope-general-daily-{day}.aspx?sign={zodiac_sign}"
|
| 89 |
+
)
|
| 90 |
+
soup = BeautifulSoup(requests.get(url).content,
|
| 91 |
+
"html.parser")
|
| 92 |
+
|
| 93 |
+
# print(soup.find("div", class_="main-horoscope").p.text)
|
| 94 |
+
return soup.find("div", class_="main-horoscope").p.text
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
final_answer = FinalAnswerTool()
|
| 98 |
|
|
|
|
| 115 |
|
| 116 |
agent = CodeAgent(
|
| 117 |
model=model,
|
| 118 |
+
tools=[final_answer, get_weather, web_search, get_current_time_in_timezone, get_horoscope], ## add your tools here (don't remove final answer)
|
| 119 |
max_steps=6,
|
| 120 |
verbosity_level=1,
|
| 121 |
grammar=None,
|