Spaces:
Sleeping
Sleeping
Update app.py
Browse files8 unmodified lines91011121314151617181920212223242526272829303132333 unmodified lines373839404142434445464748495051525354555657584 unmodified lines636465666768697 unmodified lines7778798081828384859 unmodified lines95969798991001011021031041051061071081091101118 unmodified linesfrom tools.final_answer import FinalAnswerToolfrom smolagents import CodeAgent, LiteLLMModel, DuckDuckGoSearchTool, HfApiModel, load_tool, toolfrom Gradio_UI import GradioUI# === TOOLS ===@tooldef web_search(query: str) -> str:"""Allows search through DuckDuckGo.Args:query: what you want to search"""search_tool = DuckDuckGoSearchTool()results = search_tool(query)return "\n".join(results)@tooldef get_current_time_in_timezone(timezone: str) -> str:"""Fetches the current local time in a specified timezone.Args:timezone: A string representing a valid timezone (e.g., 'America/New_York')."""try:tz = pytz.timezone(timezone)local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")3 unmodified lines@tooldef visit_webpage(url: str) -> str:"""Fetches raw HTML content of a web page.Args:url: The url of the webpage."""try:response = requests.get(url, timeout=5)return response.text[:5000] # Limit lengthexcept Exception as e:return f"[ERROR fetching {url}]: {str(e)}"@tooldef text_splitter(text: str) -> List[str]:"""Splits text into chunks using LangChain's CharacterTextSplitter.Args:text: A string of text to split."""splitter = CharacterTextSplitter(chunk_size=450, chunk_overlap=10)return splitter.split_text(text)4 unmodified lineswith open("prompts.yaml", "r") as stream:prompt_templates = yaml.safe_load(stream)# === LOAD agent.json CONFIG ===with open("agent.json", "r") as f:agent_config = yaml.safe_load(f)7 unmodified linesmax_tokens=1024,)# === IMPORT TOOL FROM HUB ===image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)# === BUILD AGENT ===9 unmodified lines],max_steps=6,verbosity_level=1,grammar=None,planning_interval=None,name=None,description=None,prompt_templates=prompt_templates)# === LAUNCH UI ===# GradioUI(agent).launch() # This was the original one we replacedfrom submit import submit_answersGradioUI(agent, file_upload_folder="downloads").launch(submit_fn=lambda: submit_answers(agent))8 unmodified lines910111213141516171819202122232425263 unmodified lines30313233343536373839404142434 unmodified lines484950515253547 unmodified lines626364656667689 unmodified lines78798081828384858 unmodified linesfrom tools.final_answer import FinalAnswerToolfrom smolagents import CodeAgent, LiteLLMModel, DuckDuckGoSearchTool, HfApiModel, load_tool, toolfrom Gradio_UI import GradioUIfrom submit import submit_answers # <- no circular import since submit.py doesn't import this file# === TOOLS ===@tooldef web_search(query: str) -> str:search_tool = DuckDuckGoSearchTool()results = search_tool(query)return "\n".join(results)@tooldef get_current_time_in_timezone(timezone: str) -> str:try:tz = pytz.timezone(timezone)local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")3 unmodified lines@tooldef visit_webpage(url: str) -> str:try:response = requests.get(url, timeout=5)return response.text[:5000]except Exception as e:return f"[ERROR fetching {url}]: {str(e)}"@tooldef text_splitter(text: str) -> List[str]:splitter = CharacterTextSplitter(chunk_size=450, chunk_overlap=10)return splitter.split_text(text)4 unmodified lineswith open("prompts.yaml", "r") as stream:prompt_templates = yaml.safe_load(stream)# === LOAD AGENT CONFIG ===with open("agent.json", "r") as f:agent_config = yaml.safe_load(f)7 unmodified linesmax_tokens=1024,)# === LOAD ADDITIONAL TOOLS ===image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)# === BUILD AGENT ===9 unmodified lines],max_steps=6,verbosity_level=1,prompt_templates=prompt_templates)# === LAUNCH GRADIO WITH SUBMIT SUPPORT ===GradioUI(agent, file_upload_folder="downloads", submit_fn=lambda: submit_answers(agent)).launch()
app.py+6-32