Spaces:
Sleeping
Sleeping
Victoria Shevchenko commited on
Commit ·
050d686
1
Parent(s): 3d1237b
new tools + timezone tool in agent
Browse files1234567891011121314156 unmodified lines2223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666727 unmodified lines959697549899100101from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,toolimport datetimeimport fitzimport requestsimport spacyimport pandas as pdimport pytzimport yamlfrom tools.final_answer import FinalAnswerTool
from 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 page for 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 spaCy doc = nlp(text)
# Extract entities that match the desired types entities = [(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 entities entities = extract_entities(text, desired_entities)
# Create a DataFrame with desired entities as columns df = pd.DataFrame(columns=desired_entities)
# Populate the DataFrame with entity values for entity, label in entities: df.loc[len(df), label] = entity
return df
@tooldef get_current_time_in_timezone(timezone: str) -> str: """A tool that fetches the current local time in a specified timezone.27 unmodified lines agent = CodeAgent( model=model, tools=[final_answer], ## add your tools here (don't remove final answer) 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