Spaces:
Paused
Paused
new tools
Browse files
app.py
CHANGED
|
@@ -13,6 +13,8 @@ import datasets
|
|
| 13 |
from langchain.docstore.document import Document
|
| 14 |
from langgraph.graph import START, StateGraph
|
| 15 |
from langchain_community.retrievers import BM25Retriever
|
|
|
|
|
|
|
| 16 |
|
| 17 |
HUGGINGFACEHUB_API_TOKEN = os.environ["HUGGINGFACEHUB_API_TOKEN"]
|
| 18 |
login(token=HUGGINGFACEHUB_API_TOKEN, add_to_git_credential=True)
|
|
@@ -99,7 +101,50 @@ guest_info_tool = Tool(
|
|
| 99 |
description="Retrieves detailed information about gala guests based on their name or relation."
|
| 100 |
)
|
| 101 |
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
chat_with_tools = model.bind_tools(tools)
|
| 104 |
|
| 105 |
# Generate the AgentState and Agent graph
|
|
|
|
| 13 |
from langchain.docstore.document import Document
|
| 14 |
from langgraph.graph import START, StateGraph
|
| 15 |
from langchain_community.retrievers import BM25Retriever
|
| 16 |
+
from langchain_community.tools import DuckDuckGoSearchRun
|
| 17 |
+
|
| 18 |
|
| 19 |
HUGGINGFACEHUB_API_TOKEN = os.environ["HUGGINGFACEHUB_API_TOKEN"]
|
| 20 |
login(token=HUGGINGFACEHUB_API_TOKEN, add_to_git_credential=True)
|
|
|
|
| 101 |
description="Retrieves detailed information about gala guests based on their name or relation."
|
| 102 |
)
|
| 103 |
|
| 104 |
+
search_tool = DuckDuckGoSearchRun()
|
| 105 |
+
|
| 106 |
+
def get_weather_info(location: str) -> str:
|
| 107 |
+
"""Fetches dummy weather information for a given location."""
|
| 108 |
+
# Dummy weather data
|
| 109 |
+
weather_conditions = [
|
| 110 |
+
{"condition": "Rainy", "temp_c": 15},
|
| 111 |
+
{"condition": "Clear", "temp_c": 25},
|
| 112 |
+
{"condition": "Windy", "temp_c": 20}
|
| 113 |
+
]
|
| 114 |
+
# Randomly select a weather condition
|
| 115 |
+
data = random.choice(weather_conditions)
|
| 116 |
+
return f"Weather in {location}: {data['condition']}, {data['temp_c']}°C"
|
| 117 |
+
|
| 118 |
+
# Initialize the tool
|
| 119 |
+
weather_info_tool = Tool(
|
| 120 |
+
name="get_weather_info",
|
| 121 |
+
func=get_weather_info,
|
| 122 |
+
description="Fetches dummy weather information for a given location."
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def get_hub_stats(author: str) -> str:
|
| 127 |
+
"""Fetches the most downloaded model from a specific author on the Hugging Face Hub."""
|
| 128 |
+
try:
|
| 129 |
+
# List models from the specified author, sorted by downloads
|
| 130 |
+
models = list(list_models(author=author, sort="downloads", direction=-1, limit=1))
|
| 131 |
+
|
| 132 |
+
if models:
|
| 133 |
+
model = models[0]
|
| 134 |
+
return f"The most downloaded model by {author} is {model.id} with {model.downloads:,} downloads."
|
| 135 |
+
else:
|
| 136 |
+
return f"No models found for author {author}."
|
| 137 |
+
except Exception as e:
|
| 138 |
+
return f"Error fetching models for {author}: {str(e)}"
|
| 139 |
+
|
| 140 |
+
# Initialize the tool
|
| 141 |
+
hub_stats_tool = Tool(
|
| 142 |
+
name="get_hub_stats",
|
| 143 |
+
func=get_hub_stats,
|
| 144 |
+
description="Fetches the most downloaded model from a specific author on the Hugging Face Hub."
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
tools = [guest_info_tool, search_tool, weather_info_tool, hub_stats_tool]
|
| 148 |
chat_with_tools = model.bind_tools(tools)
|
| 149 |
|
| 150 |
# Generate the AgentState and Agent graph
|