Spaces:
Sleeping
Sleeping
Victoria Shevchenko commited on
Commit ·
050d686
1
Parent(s): 3d1237b
new tools + timezone tool in agent
Browse files12345678910116 unmodified lines18192021222327 unmodified lines51525354555657from 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 !@tool6 unmodified lines"""return "What magic will you build ?"@tooldef get_current_time_in_timezone(timezone: str) -> str:"""A tool that fetches the current local time in a specified timezone.27 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,1234567891011121314156 unmodified lines2223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666727 unmodified lines9596979899100101from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,toolimport datetimeimport fitzimport requestsimport spacyimport pandas as pdimport pytzimport yamlfrom tools.final_answer import FinalAnswerToolfrom Gradio_UI import GradioUInlp = spacy.load("en_core_web_sm")# Below is an example of a tool that does nothing. Amaze us with your creativity !@tool6 unmodified lines"""return "What magic will you build ?"@tooldef extract_text_from_pdf(pdf_path):"""A tool that extracts text from a PDF file.Args:pdf_path: A string representing the path to the PDF file."""document = fitz.open(pdf_path)text = ""# Iterate through each pagefor page_num in range(len(document)):page = document.load_page(page_num)text += page.get_text()return text@tooldef extract_entities(text, desired_entities):# Process the text with spaCydoc = nlp(text)# Extract entities that match the desired typesentities = [(ent.text, ent.label_) for ent in doc.ents if ent.label_ in desired_entities]return entities@tooldef create_table_with_specific_entities(text, desired_entities):# Extract specific entitiesentities = extract_entities(text, desired_entities)# Create a DataFrame with desired entities as columnsdf = pd.DataFrame(columns=desired_entities)# Populate the DataFrame with entity valuesfor entity, label in entities:df.loc[len(df), label] = entityreturn df@tooldef get_current_time_in_timezone(timezone: str) -> str:"""A tool that fetches the current local time in a specified timezone.27 unmodified linesagent = CodeAgent(model=model,tools=[get_current_time_in_timezone, final_answer], ## add your tools here (don't remove final answer)max_steps=6,verbosity_level=1,grammar=None,
app.py+45-1