Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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
|
| 12 |
-
"""
|
| 13 |
|
| 14 |
Args:
|
| 15 |
-
|
| 16 |
-
|
| 17 |
"""
|
| 18 |
|
| 19 |
-
|
| 20 |
-
'
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
],
|
| 27 |
-
'
|
| 28 |
-
|
| 29 |
-
|
| 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 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
],
|
| 73 |
-
'
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
"I am writing to inform you that..."
|
| 79 |
],
|
| 80 |
-
'
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
"In a stunning display of Murphy's Law..."
|
| 86 |
]
|
| 87 |
}
|
| 88 |
|
| 89 |
-
#
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
|
| 96 |
-
# Add
|
| 97 |
-
|
| 98 |
|
| 99 |
-
#
|
| 100 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
-
# Add
|
| 103 |
-
if
|
| 104 |
-
|
| 105 |
-
"
|
| 106 |
-
"
|
| 107 |
-
"
|
| 108 |
-
"
|
| 109 |
-
"
|
| 110 |
]
|
| 111 |
-
|
| 112 |
|
| 113 |
-
return
|
| 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,
|
| 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,
|