remove unavailable libs
Browse filesAdds a tool that uses available imports
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
|
| 28 |
-
"""
|
| 29 |
-
|
| 30 |
Args:
|
| 31 |
-
|
|
|
|
| 32 |
"""
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
try:
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 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 |
-
|
|
|
|
| 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:
|