DenverJones commited on
Commit
9198ee4
·
verified ·
1 Parent(s): 93b92b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -49
app.py CHANGED
@@ -1,69 +1,43 @@
1
- from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
- import datetime
3
- import requests
4
- import pytz
5
  import yaml
6
- from tools.final_answer import FinalAnswerTool
7
  from Gradio_UI import GradioUI
8
 
9
- # ✅ Custom Tool: Motivational Quote Generator
10
  @tool
11
- def get_motivational_quote(mood: str) -> str:
12
- """A tool that provides a motivational quote based on the user's mood.
13
- Args:
14
- mood: A string describing the user's current mood (e.g., 'happy', 'sad', 'tired').
15
- """
16
- quotes = {
17
- "happy": "Happiness is not something ready-made. It comes from your own actions. – Dalai Lama",
18
- "sad": "Tough times never last, but tough people do. – Robert H. Schuller",
19
- "tired": "Take a deep breath, you’ve got this. Rest, recharge, and rise again.",
20
- "motivated": "The secret of getting ahead is getting started. – Mark Twain",
21
- "stressed": "You are stronger than you think. Take it one step at a time."
22
- }
23
- return quotes.get(mood.lower(), "No specific quote for this mood, but remember, you're doing great!")
24
 
25
- # ✅ Custom Tool: Fetch Current Time in a Given Timezone
26
- @tool
27
- def get_current_time_in_timezone(timezone: str) -> str:
28
- """A tool that fetches the current local time in a specified timezone.
29
- Args:
30
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
31
- """
32
- try:
33
- tz = pytz.timezone(timezone)
34
- local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
35
- return f"The current local time in {timezone} is: {local_time}"
36
- except Exception as e:
37
- return f"Error fetching time for timezone '{timezone}': {str(e)}"
38
-
39
- # ✅ Load Essential Components
40
- final_answer = FinalAnswerTool()
41
  model = HfApiModel(
42
  max_tokens=2096,
43
  temperature=0.5,
44
- model_id='https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud', # Hugging Face model
45
- custom_role_conversions=None,
46
  )
47
 
48
- # ✅ Load Image Generation Tool from the Hub
49
- image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
50
-
51
- # ✅ Load Prompt Templates
52
  with open("prompts.yaml", 'r') as stream:
53
  prompt_templates = yaml.safe_load(stream)
54
-
55
- # ✅ Create the AI Agent
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer, get_motivational_quote, get_current_time_in_timezone], # Added quote tool
59
- max_steps=6,
60
  verbosity_level=1,
61
- grammar=None,
62
- planning_interval=None,
63
  name="MotivationAgent",
64
- description="An AI agent that provides motivational quotes and time info.",
65
  prompt_templates=prompt_templates
66
  )
67
 
68
- # ✅ Launch the Gradio UI
69
  GradioUI(agent).launch()
 
 
1
+ from smolagents import CodeAgent, HfApiModel, tool
 
 
 
2
  import yaml
 
3
  from Gradio_UI import GradioUI
4
 
5
+ # Define a tool to generate motivational quotes
6
  @tool
7
+ def get_motivational_quote() -> str:
8
+ """Returns a motivational quote to inspire the user."""
9
+ quotes = [
10
+ "Believe you can and you're halfway there.",
11
+ "Your limitation—it's only your imagination.",
12
+ "Push yourself, because no one else is going to do it for you.",
13
+ "Great things never come from comfort zones.",
14
+ "Dream it. Wish it. Do it."
15
+ ]
16
+ import random
17
+ return random.choice(quotes)
 
 
18
 
19
+ # Model setup
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  model = HfApiModel(
21
  max_tokens=2096,
22
  temperature=0.5,
23
+ model_id='https://wxknx1kg971u7k1n.us-east-1.aws.endpoints.huggingface.cloud'
 
24
  )
25
 
26
+ # Load prompt templates
 
 
 
27
  with open("prompts.yaml", 'r') as stream:
28
  prompt_templates = yaml.safe_load(stream)
29
+
30
+ # Create the agent
31
  agent = CodeAgent(
32
  model=model,
33
+ tools=[get_motivational_quote], # Only the necessary tool
34
+ max_steps=3,
35
  verbosity_level=1,
 
 
36
  name="MotivationAgent",
37
+ description="An agent that provides motivational quotes to inspire users.",
38
  prompt_templates=prompt_templates
39
  )
40
 
41
+ # Launch the Gradio UI
42
  GradioUI(agent).launch()
43
+