Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,49 +16,66 @@ def get_youtube_channel_info(channel_name: str) -> str:
|
|
| 16 |
"""
|
| 17 |
search_tool = DuckDuckGoSearchTool()
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
print(f"
|
| 22 |
|
| 23 |
-
#
|
| 24 |
-
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
| 26 |
print(f"sub_search_results: {sub_search_results}")
|
| 27 |
-
|
|
|
|
| 28 |
channel_info = f"Information about YouTube channel '{channel_name}':\n\n"
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
|
| 34 |
-
sub_patterns = [
|
| 35 |
-
r'(\d+(?:\.\d+)?)\s*(?:M|million)\s+subscribers',
|
| 36 |
-
r'(\d+(?:\.\d+)?)\s*(?:K|thousand)\s+subscribers',
|
| 37 |
-
r'(\d+)\s+subscribers',
|
| 38 |
-
r'subscribers:\s*(\d+(?:\.\d+)?(?:\s*[KM])?)',
|
| 39 |
-
]
|
| 40 |
|
| 41 |
-
for result in
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
break
|
| 47 |
-
if subscriber_count != "Could not determine subscriber count":
|
| 48 |
-
break
|
| 49 |
|
| 50 |
-
|
| 51 |
-
channel_info += f"Channel Name: {channel_name}\n"
|
| 52 |
-
channel_info += f"Subscriber Count: {subscriber_count}\n"
|
| 53 |
|
| 54 |
-
#
|
| 55 |
-
|
|
|
|
| 56 |
if "about" in result.lower() and channel_name.lower() in result.lower():
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
break
|
| 59 |
|
|
|
|
|
|
|
|
|
|
| 60 |
return channel_info
|
| 61 |
|
|
|
|
|
|
|
| 62 |
@tool
|
| 63 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 64 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 16 |
"""
|
| 17 |
search_tool = DuckDuckGoSearchTool()
|
| 18 |
|
| 19 |
+
# Search for channel statistics specifically
|
| 20 |
+
stats_search_results = search_tool(f"{channel_name} youtube channel statistics subscribers")
|
| 21 |
+
print(f"stats_search_results: {stats_search_results}")
|
| 22 |
|
| 23 |
+
# Search for channel information
|
| 24 |
+
info_search_results = search_tool(f"{channel_name} youtube channel about")
|
| 25 |
+
print(f"info_search_results: {info_search_results}")
|
| 26 |
+
|
| 27 |
+
# Search specifically for subscriber count
|
| 28 |
+
sub_search_results = search_tool(f"how many subscribers does {channel_name} have on youtube")
|
| 29 |
print(f"sub_search_results: {sub_search_results}")
|
| 30 |
+
|
| 31 |
+
# Compile information
|
| 32 |
channel_info = f"Information about YouTube channel '{channel_name}':\n\n"
|
| 33 |
+
channel_info += f"Channel Name: {channel_name}\n"
|
| 34 |
+
|
| 35 |
+
# Extract subscriber count from search results
|
| 36 |
+
subscriber_info = "Could not determine subscriber count"
|
| 37 |
|
| 38 |
+
# Check all search results for subscriber information
|
| 39 |
+
all_results = stats_search_results + sub_search_results + info_search_results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
+
for result in all_results:
|
| 42 |
+
result_lower = result.lower()
|
| 43 |
+
# Look for common subscriber count patterns without regex
|
| 44 |
+
if "subscribers" in result_lower:
|
| 45 |
+
# Extract the sentence containing subscriber information
|
| 46 |
+
sentences = result.split('.')
|
| 47 |
+
for sentence in sentences:
|
| 48 |
+
if "subscribers" in sentence.lower():
|
| 49 |
+
subscriber_info = sentence.strip()
|
| 50 |
+
break
|
| 51 |
+
if subscriber_info != "Could not determine subscriber count":
|
| 52 |
break
|
|
|
|
|
|
|
| 53 |
|
| 54 |
+
channel_info += f"Subscriber Count: {subscriber_info}\n"
|
|
|
|
|
|
|
| 55 |
|
| 56 |
+
# Add channel description
|
| 57 |
+
channel_description = "No description available"
|
| 58 |
+
for result in info_search_results:
|
| 59 |
if "about" in result.lower() and channel_name.lower() in result.lower():
|
| 60 |
+
channel_description = result
|
| 61 |
+
break
|
| 62 |
+
|
| 63 |
+
channel_info += f"Description: {channel_description}\n"
|
| 64 |
+
|
| 65 |
+
# Add content type/category if available
|
| 66 |
+
content_info = ""
|
| 67 |
+
for result in info_search_results:
|
| 68 |
+
if "content" in result.lower() or "videos" in result.lower():
|
| 69 |
+
content_info = result
|
| 70 |
break
|
| 71 |
|
| 72 |
+
if content_info:
|
| 73 |
+
channel_info += f"Content: {content_info}\n"
|
| 74 |
+
|
| 75 |
return channel_info
|
| 76 |
|
| 77 |
+
|
| 78 |
+
|
| 79 |
@tool
|
| 80 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 81 |
"""A tool that fetches the current local time in a specified timezone.
|