Update app.py
#225
by
Mickaaa
- opened
app.py
CHANGED
@@ -33,7 +33,50 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
33 |
except Exception as e:
|
34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
|
|
|
|
|
|
|
|
37 |
final_answer = FinalAnswerTool()
|
38 |
|
39 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
|
|
33 |
except Exception as e:
|
34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
35 |
|
36 |
+
from bs4 import BeautifulSoup
|
37 |
+
import requests
|
38 |
+
|
39 |
+
class TiktokTrendTool:
|
40 |
+
def __init__(self):
|
41 |
+
self.name = "TiktokTrendTool"
|
42 |
+
self.description = "Tool to scrape TikTok trends from public web pages."
|
43 |
+
self.arguments = ["region", "language"]
|
44 |
+
self.outputs = "list of trending hashtags or videos"
|
45 |
+
|
46 |
+
def fetch_tiktok_trends(self, region="world", language="en"):
|
47 |
+
# URL de recherche publique des tendances TikTok (à adapter si besoin)
|
48 |
+
url = f"https://www.tiktok.com/tag/trending?lang={language}®ion={region}"
|
49 |
+
|
50 |
+
# Effectuer la requête HTTP
|
51 |
+
response = requests.get(url, headers={"User-Agent": "Mozilla/5.0"})
|
52 |
+
|
53 |
+
if response.status_code != 200:
|
54 |
+
raise Exception(f"Failed to fetch trends: {response.status_code}")
|
55 |
+
|
56 |
+
# Analyser le HTML de la page
|
57 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
58 |
+
|
59 |
+
# Extraire les hashtags populaires ou titres de vidéos
|
60 |
+
trends = []
|
61 |
+
for tag in soup.find_all('a', {'class': 'tiktok-trend-link'}):
|
62 |
+
trends.append(tag.text.strip())
|
63 |
+
|
64 |
+
# Si aucune tendance trouvée, retourne un message
|
65 |
+
if not trends:
|
66 |
+
trends.append("No trends found. The page structure might have changed.")
|
67 |
+
|
68 |
+
return trends
|
69 |
+
|
70 |
+
def __call__(self, region="world", language="en"):
|
71 |
+
return self.fetch_tiktok_trends(region, language)
|
72 |
+
|
73 |
+
def to_string(self):
|
74 |
+
return f"{self.name}: {self.description}\nArguments: {self.arguments}\nOutputs: {self.outputs}"
|
75 |
|
76 |
+
# Exemple d'utilisation
|
77 |
+
tool = TiktokTrendTool()
|
78 |
+
trends = tool(region="us", language="en")
|
79 |
+
print("TikTok Trends:", trends)
|
80 |
final_answer = FinalAnswerTool()
|
81 |
|
82 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|