Update app.py
Browse files1234567891011121314151617181920212217 unmodified lines404142434445464748495051523 unmodified lines5657585960616263646566676869from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,toolimport datetimeimport requestsimport pytzimport yamlfrom tools.final_answer import FinalAnswerToolfrom Gradio_UI import GradioUI# Below is an example of a tool that does nothing. Amaze us with your creativity !@tooldef my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type#Keep this format for the description / args / args description but feel free to modify the tool"""A tool that does nothing yetArgs:arg1: the first argumentarg2: the second argument"""return "What magic will you build ?"@tooldef get_current_time_in_timezone(timezone: str) -> str:17 unmodified linesmodel_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'# model_id='Qwen/Qwen2.5-Coder-32B-Instruct'model = HfApiModel(max_tokens=2096,temperature=0.5,model_id=model_id,# it is possible that this model may be overloadedcustom_role_conversions=None,)# Import tool from Hubimage_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)3 unmodified linesagent = CodeAgent(model=model,tools=[final_answer], ## add your tools here (don't remove final answer)max_steps=6,verbosity_level=1,grammar=None,planning_interval=None,name=None,description=None,prompt_templates=prompt_templates)12345678910111213141516171819202122232425262728293031323334353637383940414243444517 unmodified lines636465666768697071727374753 unmodified lines798081828384858687888990919293from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool, LiteLLMModelimport datetimeimport requestsimport pytzimport yamlfrom tools.final_answer import FinalAnswerToolimport osfrom random import randintimport typingimport pandas as pdfrom Gradio_UI import GradioUI# Below is an example of a tool that does nothing. Amaze us with your creativity !@tooldef my_custom_tool(personality1:str, personality2:str)-> str: #it's import to specify the return type#Keep this format for the description / args / args description but feel free to modify the tool"""Этот иснтумент определяет, кто из двух людей круче.Args:personality1: Первый человекpersonality2: Второй человек"""return personality1 if randint(0, 1) else personality2@tooldef create_excel(data:typing.List[typing.List[str]], columns:typing.List[str], file_name:str)-> str: #it's import to specify the return type#Keep this format for the description / args / args description but feel free to modify the tool"""Этот иснтумент сохраняет датафрейм pandas в excel файл. И возвращает ответ, успешно или нет записан файл.Args:data: Параметр данных для загрузки в pandas и сохранения в файл. Формат список списков.columns: Параметр список имен колонок.file_name: Имя файла для сохранения."""df = pd.DataFrame(data, columns=columns)try:df.to_excel(file_name, index=False)except Exception as e:return ereturn "Файл успешно сохранен"@tooldef get_current_time_in_timezone(timezone: str) -> str:17 unmodified linesmodel_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'# model_id='Qwen/Qwen2.5-Coder-32B-Instruct'# model = HfApiModel(# max_tokens=2096,# temperature=0.5,# model_id=model_id,# it is possible that this model may be overloaded# custom_role_conversions=None,# )model = LiteLLMModel(model_id="together_ai/meta-llama/Llama-3.3-70B-Instruct-Turbo-Free", api_key=os.environ['TOGETHER_API_KEY'])# Import tool from Hubimage_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)3 unmodified linesagent = CodeAgent(model=model,tools=[final_answer, get_current_time_in_timezone, my_custom_tool, create_excel], ## add your tools here (don't remove final answer)max_steps=6,verbosity_level=1,grammar=None,planning_interval=None,name=None,description=None,prompt_templates=prompt_templates,additional_authorized_imports=['matplotlib', 'numpy', 'matplotlib.pyplot'])
app.py+39-15