Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | 
         @@ -1,4 +1,4 @@ 
     | 
|
| 1 | 
         
            -
            from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
         
     | 
| 2 | 
         
             
            import datetime
         
     | 
| 3 | 
         
             
            import requests
         
     | 
| 4 | 
         
             
            import pytz
         
     | 
| 
         @@ -9,30 +9,26 @@ from Gradio_UI import GradioUI 
     | 
|
| 9 | 
         | 
| 10 | 
         
             
            # Below is an example of a tool that does nothing. Amaze us with your creativity !
         
     | 
| 11 | 
         
             
            @tool
         
     | 
| 12 | 
         
            -
            def  
     | 
| 13 | 
         
            -
                 
     | 
| 14 | 
         
            -
                """A tool that does nothing yet 
         
     | 
| 15 | 
         
             
                Args:
         
     | 
| 16 | 
         
            -
                     
     | 
| 17 | 
         
            -
                    arg2: the second argument
         
     | 
| 18 | 
         
             
                """
         
     | 
| 19 | 
         
            -
                 
     | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 20 | 
         | 
| 21 | 
         | 
| 22 | 
         
            -
            @tool
         
     | 
| 23 | 
         
            -
            def get_current_time_in_timezone(timezone: str) -> str:
         
     | 
| 24 | 
         
            -
                """A tool that fetches the current local time in a specified timezone.
         
     | 
| 25 | 
         
            -
                Args:
         
     | 
| 26 | 
         
            -
                    timezone: A string representing a valid timezone (e.g., 'America/New_York').
         
     | 
| 27 | 
         
            -
                """
         
     | 
| 28 | 
         
            -
                try:
         
     | 
| 29 | 
         
            -
                    # Create timezone object
         
     | 
| 30 | 
         
            -
                    tz = pytz.timezone(timezone)
         
     | 
| 31 | 
         
            -
                    # Get current time in that timezone
         
     | 
| 32 | 
         
            -
                    local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
         
     | 
| 33 | 
         
            -
                    return f"xxxx {timezone} xxxx: {local_time} xxx"
         
     | 
| 34 | 
         
            -
                except Exception as e:
         
     | 
| 35 | 
         
            -
                    return f"Error fetching time for timezone '{timezone}': {str(e)}"
         
     | 
| 36 | 
         | 
| 37 | 
         | 
| 38 | 
         
             
            final_answer = FinalAnswerTool()
         
     | 
| 
         @@ -56,7 +52,7 @@ with open("prompts.yaml", 'r') as stream: 
     | 
|
| 56 | 
         | 
| 57 | 
         
             
            agent = CodeAgent(
         
     | 
| 58 | 
         
             
                model=model,
         
     | 
| 59 | 
         
            -
                tools=[final_answer,  
     | 
| 60 | 
         
             
                max_steps=6,
         
     | 
| 61 | 
         
             
                verbosity_level=1,
         
     | 
| 62 | 
         
             
                grammar=None,
         
     | 
| 
         | 
|
| 1 | 
         
            +
            from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel,load_tool,tool
         
     | 
| 2 | 
         
             
            import datetime
         
     | 
| 3 | 
         
             
            import requests
         
     | 
| 4 | 
         
             
            import pytz
         
     | 
| 
         | 
|
| 9 | 
         | 
| 10 | 
         
             
            # Below is an example of a tool that does nothing. Amaze us with your creativity !
         
     | 
| 11 | 
         
             
            @tool
         
     | 
| 12 | 
         
            +
            def get_random_quotes()-> str:
         
     | 
| 13 | 
         
            +
                """A tool that gets random quote in random anime.
         
     | 
| 
         | 
|
| 14 | 
         
             
                Args:
         
     | 
| 15 | 
         
            +
                    no argument needed for this tool.
         
     | 
| 
         | 
|
| 16 | 
         
             
                """
         
     | 
| 17 | 
         
            +
                url = "https://animechan.io/api/v1/quotes/random"
         
     | 
| 18 | 
         
            +
                
         
     | 
| 19 | 
         
            +
                try:
         
     | 
| 20 | 
         
            +
                    # Make a GET request to the API endpoint using requests.get()
         
     | 
| 21 | 
         
            +
                    response = requests.get(url)
         
     | 
| 22 | 
         
            +
             
     | 
| 23 | 
         
            +
                    # Check if the request was successful (status code 200)
         
     | 
| 24 | 
         
            +
                    if response.status_code == 200:
         
     | 
| 25 | 
         
            +
                        posts = response.json()
         
     | 
| 26 | 
         
            +
                        return posts
         
     | 
| 27 | 
         
            +
                    else:
         
     | 
| 28 | 
         
            +
                        print('Error:', response.status_code)
         
     | 
| 29 | 
         
            +
                        return None
         
     | 
| 30 | 
         | 
| 31 | 
         | 
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 32 | 
         | 
| 33 | 
         | 
| 34 | 
         
             
            final_answer = FinalAnswerTool()
         
     | 
| 
         | 
|
| 52 | 
         | 
| 53 | 
         
             
            agent = CodeAgent(
         
     | 
| 54 | 
         
             
                model=model,
         
     | 
| 55 | 
         
            +
                tools=[final_answer, DuckDuckGoSearchTool, get_random_quotes], ## add your tools here (don't remove final answer)
         
     | 
| 56 | 
         
             
                max_steps=6,
         
     | 
| 57 | 
         
             
                verbosity_level=1,
         
     | 
| 58 | 
         
             
                grammar=None,
         
     |