CoolFace
Apppublic

tbindumadhav/quote_generator

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py116 linesDownload Raw Back to root
1from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool,OpenAIServerModel2import datetime3import requests4import pytz5import yaml6import random7import os8from tools.final_answer import FinalAnswerTool9 10from Gradio_UI import GradioUI11 12# Below is an example of a tool that does nothing. Amaze us with your creativity !13@tool14def inspirational_quote_generator(theme: str, mood: str) -> str:15    """Generates an inspirational quote based on a given theme and mood.16    17    Args:18        theme: The central idea for the quote (e.g., 'success', 'perseverance', 'creativity').19        mood: The tone of the quote (e.g., 'uplifting', 'serious', 'humorous').20    21    Returns:22        A randomly generated inspirational quote.23    """24    quotes = {25        "success": {26            "uplifting": [27                "Success is not final, failure is not fatal: it is the courage to continue that counts.",28                "The only limit to our realization of tomorrow is our doubts of today."29            ],30            "serious": [31                "The road to success and the road to failure are almost exactly the same.",32                "Don’t be afraid to give up the good to go for the great."33            ],34            "humorous": [35                "Behind every successful person is a substantial amount of coffee.",36                "Success is 10% inspiration and 90% avoiding social media distractions."37            ]38        },39        "perseverance": {40            "uplifting": [41                "It does not matter how slowly you go as long as you do not stop.",42                "The secret of our success is that we never, never give up."43            ],44            "serious": [45                "Courage doesn’t always roar. Sometimes, it’s the quiet voice at the end of the day whispering, ‘I will try again tomorrow.’",46                "A river cuts through rock not because of its power, but because of its persistence."47            ],48            "humorous": [49                "Perseverance is failing 19 times and succeeding the 20th.",50                "Some people graduate with honors, I am just honored to graduate."51            ]52        },53        "creativity": {54            "uplifting": [55                "Creativity is intelligence having fun.",56                "You can’t use up creativity. The more you use, the more you have."57            ],58            "serious": [59                "Creativity involves breaking out of established patterns to look at things in a different way.",60                "An idea that is not dangerous is unworthy of being called an idea at all."61            ],62            "humorous": [63                "Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.",64                "I am not messy. I am creatively organized."65            ]66        }67    }68    69    return random.choice(quotes.get(theme, {}).get(mood, ["Sorry, no quote available for this theme and mood."]))70 71@tool72def get_current_time_in_timezone(timezone: str) -> str:73    """A tool that fetches the current local time in a specified timezone.74    Args:75        timezone: A string representing a valid timezone (e.g., 'America/New_York').76    """77    try:78        # Create timezone object79        tz = pytz.timezone(timezone)80        # Get current time in that timezone81        local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")82        return f"The current local time in {timezone} is: {local_time}"83    except Exception as e:84        return f"Error fetching time for timezone '{timezone}': {str(e)}"85 86 87final_answer = FinalAnswerTool()88model = model = OpenAIServerModel(89    max_tokens=2096,90    temperature=0.5,91    model_id="gpt-4o",92    api_key=os.environ["API_KEY"],93    custom_role_conversions=None,94)95 96 97# Import tool from Hub98image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)99 100with open("prompts.yaml", 'r') as stream:101    prompt_templates = yaml.safe_load(stream)102    103agent = CodeAgent(104    model=model,105    tools=[final_answer, inspirational_quote_generator, get_current_time_in_timezone], ## add your tools here (don't remove final answer)106    max_steps=6,107    verbosity_level=1,108    grammar=None,109    planning_interval=None,110    name=None,111    description=None,112    prompt_templates=prompt_templates113)114 115 116GradioUI(agent).launch()