experimentation / app.py
rahulnamdev's picture
Update app.py
de7b4bb verified
raw
history blame
1.24 kB
from smolagents import CodeAgent
from smolagents import HfApiModel
#from smolagents import DuckDuckGoSearchTool
import os
from datasets import load_dataset
dataset = load_dataset("ckandemir/amazon-products1", revision="main" )
@tool
def predict_price_tool(arg1:str)-> float: #it's import to specify the return type
#Keep this format for the description / args / args description but feel free to modify the tool
"""This is a tool which look on a dataset as defined by user input and give you a price
Args:
arg1: the category of product
"""
filter_dataset = dataset['Category' == arg1]
filter_dataset_min = filter_dataset['Selling Price'].min()
filter_dataset_max = filter_dataset['Selling Price'].min()
return (filter_dataset_min + filter_dataset_max )/2
#Agent Example
model = HfApiModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct", token=os.getenv('Testing'))
agent = CodeAgent(tools=[predict_price_tool], model=model)
agent.run("Get price quoatition for catageory = Toys & Games | Arts & Crafts | Craft Kits | Paper Craft")
# Access HF Hub
#from huggingface_hub import list_models
#for model in list_models(limit=10, sort="downloads", direction=-1):
# print(model.id, model.downloads)