sascow commited on
Commit
490e450
·
verified ·
1 Parent(s): b9b94b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +97 -96
app.py CHANGED
@@ -1,124 +1,126 @@
1
  from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
- import datetime
3
- import requests
4
- import pytz
5
- import yaml
6
  import random
7
  from tools.final_answer import FinalAnswerTool
8
  from Gradio_UI import GradioUI
9
 
10
  @tool
11
- def excuse_generator(situation: str, formality_level: str = "casual") -> str:
12
- """A tool that generates creative excuses for various situations
13
 
14
  Args:
15
- situation: The situation requiring an excuse (e.g., 'late_to_meeting', 'missing_deadline', 'forgot_birthday')
16
- formality_level: How formal the excuse should be ('casual', 'professional', or 'elaborate')
17
  """
18
 
19
- excuse_components = {
20
- 'tech_problems': [
21
- "my smart home went into lockdown mode",
22
- "my AI assistant started writing poetry instead of setting alarms",
23
- "my laptop decided to update all 247 applications at once",
24
- "my coffee maker hacked my calendar and deleted all my meetings",
25
- "my virtual reality headset trapped me in a meditation session"
26
- ],
27
- 'transportation': [
28
- "a parade of ducks was crossing the road",
29
- "my car's GPS insisted on taking me through a renaissance fair",
30
- "my bicycle was requisitioned by time travelers",
31
- "a group of joggers mistook me for their running coach",
32
- "my helicopter uber got stuck in a cloud"
33
- ],
34
- 'pet_related': [
35
- "my cat unplugged my alarm clock to charge their phone",
36
- "my dog ate my keys and the vet was closed",
37
- "my goldfish needed emotional support",
38
- "my hamster staged a protest for better wheel conditions",
39
- "my pet plant needed emergency repotting"
40
- ],
41
- 'weather': [
42
- "a localized rain cloud followed me around all morning",
43
- "a rainbow appeared and I had to document it for science",
44
- "the wind kept pushing me in the wrong direction",
45
- "a mysterious fog turned my neighborhood into a maze",
46
- "the sun was in my eyes (it was night time)"
47
- ],
48
- 'professional': [
49
- "I was trapped in an endless email chain",
50
- "the coffee machine initiated a workplace revolution",
51
- "my keyboard only typed in emoji",
52
- "my desk chair rolled me into an impromptu meeting",
53
- "my productivity app became too productive"
54
- ]
55
  }
56
 
57
- situation_categories = {
58
- 'late_to_meeting': ['tech_problems', 'transportation', 'professional'],
59
- 'missing_deadline': ['tech_problems', 'professional'],
60
- 'forgot_birthday': ['tech_problems', 'pet_related'],
61
- 'missed_call': ['tech_problems', 'weather', 'pet_related'],
62
- 'general': ['tech_problems', 'transportation', 'pet_related', 'weather', 'professional']
63
- }
 
 
 
 
 
64
 
65
- formality_modifiers = {
66
- 'casual': [
67
- "You're not gonna believe this, but...",
68
- "So, funny story...",
69
- "Well...",
70
- "Here's the thing...",
71
- "Would you believe..."
 
 
 
 
 
 
 
 
 
 
 
 
72
  ],
73
- 'professional': [
74
- "I regret to inform you that...",
75
- "Due to unforeseen circumstances...",
76
- "I must apologize, as...",
77
- "Please be advised that...",
78
- "I am writing to inform you that..."
79
  ],
80
- 'elaborate': [
81
- "In an unprecedented turn of events that defies explanation...",
82
- "Through a series of increasingly improbable occurrences...",
83
- "In what can only be described as a cosmic convergence of unlikely events...",
84
- "After careful consideration of the extraordinary circumstances...",
85
- "In a stunning display of Murphy's Law..."
86
  ]
87
  }
88
 
89
- # Default to 'general' if situation not found
90
- valid_categories = situation_categories.get(situation, situation_categories['general'])
 
 
 
 
91
 
92
- # Select random category and excuse from that category
93
- category = random.choice(valid_categories)
94
- core_excuse = random.choice(excuse_components[category])
 
 
 
 
 
 
 
 
95
 
96
- # Add formality modifier
97
- modifier = random.choice(formality_modifiers.get(formality_level, formality_modifiers['casual']))
98
 
99
- # Construct the full excuse
100
- full_excuse = f"{modifier} {core_excuse}"
 
 
 
 
 
 
 
 
101
 
102
- # Add a random consequence for elaborate excuses
103
- if formality_level == 'elaborate':
104
- consequences = [
105
- "This naturally led to a cascade of bureaucratic complications.",
106
- "The authorities have been notified, but they were equally puzzled.",
107
- "I'm still waiting for the insurance adjuster to stop laughing.",
108
- "The local news has already contacted me for an exclusive.",
109
- "Scientists are currently studying the phenomenon."
110
  ]
111
- full_excuse += f" {random.choice(consequences)}"
112
 
113
- return full_excuse
114
 
115
  @tool
116
  def get_current_time_in_timezone(timezone: str) -> str:
117
- """A tool that fetches the current local time in a specified timezone.
118
-
119
- Args:
120
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
121
- """
122
  try:
123
  tz = pytz.timezone(timezone)
124
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
@@ -135,7 +137,6 @@ model = HfApiModel(
135
  custom_role_conversions=None,
136
  )
137
 
138
- # Import tool from Hub
139
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
140
 
141
  with open("prompts.yaml", 'r') as stream:
@@ -143,7 +144,7 @@ with open("prompts.yaml", 'r') as stream:
143
 
144
  agent = CodeAgent(
145
  model=model,
146
- tools=[get_current_time_in_timezone, excuse_generator, DuckDuckGoSearchTool(), final_answer],
147
  max_steps=6,
148
  verbosity_level=1,
149
  grammar=None,
 
1
  from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
 
 
 
 
2
  import random
3
  from tools.final_answer import FinalAnswerTool
4
  from Gradio_UI import GradioUI
5
 
6
  @tool
7
+ def corporate_nonsense(input_text: str, enthusiasm_level: str = "standard") -> str:
8
+ """Converts normal text into ridiculous corporate buzzword-speak
9
 
10
  Args:
11
+ input_text: The normal text to convert
12
+ enthusiasm_level: How extreme to make it ('standard', 'synergistic', or 'full_consultant')
13
  """
14
 
15
+ buzzword_replacements = {
16
+ 'good': ['synergistic', 'paradigm-shifting', 'game-changing', 'disruptive'],
17
+ 'bad': ['sub-optimal', 'paradigm-deficient', 'value-deteriorating', 'legacy-minded'],
18
+ 'idea': ['value proposition', 'strategic framework', 'thought leadership initiative', 'blue-sky ideation'],
19
+ 'meeting': ['deep-dive synchronization', 'stakeholder alignment summit', 'value-stream mapping session', 'agile scrum standup'],
20
+ 'problem': ['challenge opportunity', 'growth impediment', 'success barrier', 'optimization potential'],
21
+ 'work': ['value creation', 'deliverable orchestration', 'bandwidth allocation', 'resource optimization'],
22
+ 'think': ['ideate', 'mindshare', 'thought-shower', 'brain-tsunami'],
23
+ 'talk': ['dialogue interface', 'verbal value stream', 'synchronous communication', 'stakeholder soundboarding'],
24
+ 'help': ['leverage synergies', 'provide optimization support', 'facilitate enablement', 'drive value realization'],
25
+ 'team': ['cross-functional tiger team', 'agile pod', 'centers of excellence', 'value stream collective']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  }
27
 
28
+ corporate_prefixes = [
29
+ "Moving forward,",
30
+ "At the end of the day,",
31
+ "In this space,",
32
+ "Taking this offline,",
33
+ "Per our last alignment,",
34
+ "Through a holistic lens,",
35
+ "With all hands on deck,",
36
+ "In the spirit of transparency,",
37
+ "Leveraging our core competencies,",
38
+ "During this digital transformation journey,"
39
+ ]
40
 
41
+ corporate_suffixes = [
42
+ "in accordance with best practices.",
43
+ "to drive meaningful outcomes.",
44
+ "while maintaining operational excellence.",
45
+ "through strategic partnerships.",
46
+ "leveraging our competitive advantage.",
47
+ "in this volatile marketplace.",
48
+ "across the value chain.",
49
+ "with a laser focus on ROI.",
50
+ "utilizing bleeding-edge methodologies.",
51
+ "while pivoting to Web3."
52
+ ]
53
+
54
+ amplifiers = {
55
+ 'standard': [
56
+ 'leverage',
57
+ 'optimize',
58
+ 'streamline',
59
+ 'facilitate'
60
  ],
61
+ 'synergistic': [
62
+ 'hyper-leverage',
63
+ 'mega-optimize',
64
+ 'ultra-streamline',
65
+ 'super-facilitate'
 
66
  ],
67
+ 'full_consultant': [
68
+ 'quantum-leverage',
69
+ 'cyber-optimize',
70
+ 'blockchain-streamline',
71
+ 'ai-powered-facilitate'
 
72
  ]
73
  }
74
 
75
+ # Convert text to lowercase for matching
76
+ words = input_text.lower().split()
77
+ translated_words = []
78
+
79
+ # Get appropriate amplifiers based on enthusiasm level
80
+ current_amplifiers = amplifiers.get(enthusiasm_level, amplifiers['standard'])
81
 
82
+ for word in words:
83
+ # Check if word is in our replacement dictionary
84
+ for key, replacements in buzzword_replacements.items():
85
+ if word == key:
86
+ # Add random amplifier based on enthusiasm level
87
+ if random.random() > 0.5:
88
+ translated_words.append(random.choice(current_amplifiers))
89
+ translated_words.append(random.choice(replacements))
90
+ break
91
+ else:
92
+ translated_words.append(word)
93
 
94
+ # Add corporate prefix and suffix
95
+ result = f"{random.choice(corporate_prefixes)} {' '.join(translated_words)} {random.choice(corporate_suffixes)}"
96
 
97
+ # For full_consultant mode, add extra buzzwords
98
+ if enthusiasm_level == 'full_consultant':
99
+ ai_buzzwords = [
100
+ "AI-driven",
101
+ "blockchain-enabled",
102
+ "quantum-computing-powered",
103
+ "machine-learning-optimized",
104
+ "digital-twin-synchronized"
105
+ ]
106
+ result = f"{random.choice(ai_buzzwords)} {result}"
107
 
108
+ # Add random KPIs for synergistic and full_consultant modes
109
+ if enthusiasm_level in ['synergistic', 'full_consultant']:
110
+ kpis = [
111
+ "Target KPI: 110% mindshare optimization",
112
+ "Expected ROI: 3000% paradigm shift",
113
+ "Synergy metric: Over 9000",
114
+ "Innovation index: Breaking new ground",
115
+ "Disruption quotient: Maximum"
116
  ]
117
+ result += f"\n{random.choice(kpis)}"
118
 
119
+ return result
120
 
121
  @tool
122
  def get_current_time_in_timezone(timezone: str) -> str:
123
+ """A tool that fetches the current local time in a specified timezone."""
 
 
 
 
124
  try:
125
  tz = pytz.timezone(timezone)
126
  local_time = datetime.datetime.now(tz).strftime("%Y-%m-%d %H:%M:%S")
 
137
  custom_role_conversions=None,
138
  )
139
 
 
140
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
141
 
142
  with open("prompts.yaml", 'r') as stream:
 
144
 
145
  agent = CodeAgent(
146
  model=model,
147
+ tools=[get_current_time_in_timezone, corporate_nonsense, DuckDuckGoSearchTool(), final_answer],
148
  max_steps=6,
149
  verbosity_level=1,
150
  grammar=None,