DeepSpaceMuse commited on
Commit
f438bed
·
verified ·
1 Parent(s): a3d657a

remove unavailable libs

Browse files

Adds a tool that uses available imports

Files changed (1) hide show
  1. app.py +44 -60
app.py CHANGED
@@ -3,10 +3,6 @@ import datetime
3
  import requests
4
  import pytz
5
  import yaml
6
- import yfinance as yf
7
- from ta.momentum import RSIIndicator, StochasticOscillator
8
- from ta.trend import MACD
9
- from ta.volume import volume_weighted_average_price
10
  from tools.final_answer import FinalAnswerTool
11
 
12
 
@@ -24,66 +20,54 @@ from Gradio_UI import GradioUI
24
  # return "What magic will you build ?"
25
 
26
  @tool
27
- def get_stock_price(ticker: str) -> Union[Dict, str]:
28
- """
29
- A tool that fetches the historical stock price data and technical indicators for a given ticker.
30
  Args:
31
- ticker: A string representing a stocke ticker name (e.g AAPL)
 
32
  """
33
-
 
 
 
 
 
 
34
  try:
35
- data = yf.download(
36
- ticker,
37
- start=dt.datetime.now() - dt.timedelta(weeks=24 * 3),
38
- end=dt.datetime.now(),
39
- interval="1wk",
40
- )
41
- df = data.copy()
42
- data.reset_index(inplace=True)
43
- data.Date = data.Date.astype(str)
44
-
45
- indicators = {}
46
-
47
- rsi_series = RSIIndicator(df["Close"], window=14).rsi().iloc[-12:]
48
- indicators["RSI"] = {
49
- date.strftime("%Y-%m-%d"): int(value)
50
- for date, value in rsi_series.dropna().to_dict().items()
51
- }
52
-
53
- stochastic_series = (
54
- StochasticOscillator(df["High"], df["Low"], df["Close"], window=14)
55
- .stoch()
56
- .iloc[-12:]
57
- )
58
- indicators["Stochastic Oscillator"] = {
59
- date.strftime("%Y-%m-%d"): int(value)
60
- for date, value in stochastic_series.dropna().to_dict().items()
61
- }
62
-
63
- macd = MACD(df["Close"])
64
- macd_series = macd.macd().iloc[-12:]
65
- indicators["MACD"] = {
66
- date.strftime("%Y-%m-%d"): int(value)
67
- for date, value in macd_series.to_dict().items()
68
- }
69
-
70
- macd_signal_series = macd.macd_signal().iloc[-12:]
71
- indicators["MACD Signal"] = {
72
- date.strftime("%Y-%m-%d"): int(value)
73
- for date, value in macd_signal_series.to_dict().items()
74
- }
75
-
76
- vwap_series = volume_weighted_average_price(
77
- df["High"], df["Low"], df["Close"], df["Volume"]
78
- ).iloc[-12:]
79
- indicators["vwap"] = {
80
- date.strftime("%Y-%m-%d"): int(value)
81
- for date, value in vwap_series.to_dict().items()
82
- }
83
-
84
- return {"stock_price": data.to_dict(orient="records"), "indicators": indicators}
85
  except Exception as e:
86
- return f"Error fetching price data: {str(e)}"
 
87
 
88
  @tool
89
  def get_current_time_in_timezone(timezone: str) -> str:
 
3
  import requests
4
  import pytz
5
  import yaml
 
 
 
 
6
  from tools.final_answer import FinalAnswerTool
7
 
8
 
 
20
  # return "What magic will you build ?"
21
 
22
  @tool
23
+ def trending_topic_analyzer(topic: str, hours_back: int) -> str:
24
+ """A tool that analyzes trending topics and provides timestamped insights with web search data
25
+
26
  Args:
27
+ topic: The topic or keyword to analyze
28
+ hours_back: How many hours back to consider for the analysis
29
  """
30
+ # Initialize search tool
31
+ search_tool = DuckDuckGoSearchTool()
32
+
33
+ # Get current time in UTC
34
+ utc_now = datetime.datetime.now(pytz.UTC)
35
+ time_threshold = utc_now - datetime.timedelta(hours=hours_back)
36
+
37
  try:
38
+ # Perform search for recent content about the topic
39
+ search_query = f"{topic} after:{time_threshold.strftime('%Y-%m-%d')}"
40
+ search_results = search_tool.run(search_query)
41
+
42
+ # Process search results
43
+ if not search_results:
44
+ return f"No recent data found for '{topic}' in the last {hours_back} hours"
45
+
46
+ # Analyze basic statistics
47
+ result_count = len(search_results)
48
+ timestamp = utc_now.strftime("%Y-%m-%d %H:%M:%S UTC")
49
+
50
+ # Extract key information from top results
51
+ summary = []
52
+ for i, result in enumerate(search_results[:3], 1): # Top 3 results
53
+ title = result.get('title', 'No title')
54
+ snippet = result.get('snippet', 'No description')[:100] + "..."
55
+ summary.append(f"{i}. {title}\n {snippet}")
56
+
57
+ # Compile the analysis
58
+ analysis = f"Trending Topic Analysis for '{topic}'\n"
59
+ analysis += f"Generated at: {timestamp}\n"
60
+ analysis += f"Timeframe: Last {hours_back} hours\n"
61
+ analysis += f"Number of relevant results: {result_count}\n\n"
62
+ analysis += "Top Recent Mentions:\n"
63
+ analysis += "\n".join(summary)
64
+ analysis += "\n\nStatus: Analysis completed successfully"
65
+
66
+ return analysis
67
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  except Exception as e:
69
+ error_time = utc_now.strftime("%Y-%m-%d %H:%M:%S UTC")
70
+ return f"Error analyzing topic '{topic}' at {error_time}: {str(e)}"
71
 
72
  @tool
73
  def get_current_time_in_timezone(timezone: str) -> str: