adal-glez-a commited on
Commit
e942853
·
verified ·
1 Parent(s): 73d3b5b

add playful snippet generator with default fallbacks

Browse files

add playful “human-centered AI” snippet generator with default fallbacks and whimsical insights

Files changed (1) hide show
  1. app.py +65 -52
app.py CHANGED
@@ -4,6 +4,7 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
7
 
8
  from Gradio_UI import GradioUI
9
 
@@ -42,69 +43,81 @@ def get_current_time_in_timezone(timezone: str) -> str:
42
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
43
 
44
  @tool
45
- def generate_futuristic_code_snippet(
46
- company_name: str,
47
  mission: str = None,
48
- key_values: str = None
 
49
  ) -> str:
50
  """
51
- Generates a futuristic-style Python code snippet given a company name,
52
- an optional mission, and an optional set of key values.
53
-
54
  Args:
55
- company_name: The name of the company (e.g. "Design Thinking Japan")
56
- mission: The company's mission statement (e.g. "Human Centered, AI Accelerated").
57
- If not provided, a random futuristic mission is chosen.
58
- key_values: A comma-separated string of key values (e.g. "empathy, innovation").
59
- If not provided, a set of futuristic key values is randomly picked.
60
  """
61
- # 1. Provide random defaults if mission/key_values are missing
62
- random_missions = [
63
- "Automate the intergalactic supply chain",
64
- "Enlighten minds through quantum synergy",
65
- "Transcend beyond the boundaries of reality",
66
- "Engineer post-human empathy"
67
  ]
68
- random_values = [
69
- "hyper-collaboration",
70
- "cosmic curiosity",
71
- "matrix-like agility",
72
- "singularity-driven passion"
73
- ]
74
-
75
- if mission is None or not mission.strip():
76
- mission = random.choice(random_missions)
77
-
78
- if key_values is None or not key_values.strip():
79
- # pick 2–3 random values
80
- chosen_values = random.sample(random_values, k=2)
81
- key_values = ", ".join(chosen_values)
82
-
83
- # 2. Prepare the snippet lines
 
 
 
84
  code_lines = [
85
- f"def {company_name.lower().replace(' ', '_')}_futuristic():",
86
- f" \"\"\"",
87
- f" This function encapsulates {company_name}'s futuristic ambitions.",
88
- f" Mission: {mission}",
89
- f" Key Values: {key_values}",
90
- f" \"\"\"",
91
- " # Initiating hyper-drive synergy with mission parameters",
92
- " synergy_level = 9999",
93
- " dimensional_rift = True",
 
 
 
 
 
 
 
 
 
94
  "",
95
- " if dimensional_rift:",
96
- " print(f'Breach opened! {company_name} is transcending conventional limits...')",
97
- " else:",
98
- " raise Exception('No rift detected. Expansion halted!')",
99
  "",
100
- f" print(f'{company_name} pushing forward with unstoppable momentum...')",
 
101
  "",
102
- f" return f'{company_name} has successfully infused the future with {mission}!'",
 
 
 
 
103
  ]
104
-
105
- # 3. Combine the lines into a single string
106
- snippet = "\n".join(code_lines)
107
- return snippet
108
 
109
  final_answer = FinalAnswerTool()
110
  model = HfApiModel(
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ import random
8
 
9
  from Gradio_UI import GradioUI
10
 
 
43
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
44
 
45
  @tool
46
+ @tool
47
+ def generate_human_centered_ai_snippet(
48
  mission: str = None,
49
+ human_insights_str: str = None,
50
+ ai_insights_str: str = None,
51
  ) -> str:
52
  """
53
+ Generate a playful code snippet showing a HumanCenteredAI system with:
54
+ - A default mission if not provided
55
+ - Some random picks for human insights & AI insights if not provided
56
  Args:
57
+ mission: The mission statement for the system
58
+ human_insights_str: Optional comma-separated list of human insights
59
+ ai_insights_str: Optional comma-separated list of AI insights
 
 
60
  """
61
+ # Provide random fallback if mission is empty
62
+ default_missions = [
63
+ "Human Centered, AI Accelerated",
64
+ "Designing Tomorrow, Together",
65
+ "Empathy-Driven AI Solutions"
 
66
  ]
67
+ if not mission or not mission.strip():
68
+ mission = random.choice(default_missions)
69
+
70
+ # Provide some comedic fallback lists
71
+ default_human_insights = ["empathy", "innovation", "collaboration", "creativity", "wonder"]
72
+ default_ai_insights = ["machine_learning", "automation", "data_analysis", "quantum_computing"]
73
+
74
+ # Convert the user inputs (if any) to Python lists
75
+ if not human_insights_str or not human_insights_str.strip():
76
+ human_insights = default_human_insights
77
+ else:
78
+ human_insights = [h.strip() for h in human_insights_str.split(",") if h.strip()]
79
+
80
+ if not ai_insights_str or not ai_insights_str.strip():
81
+ ai_insights = default_ai_insights
82
+ else:
83
+ ai_insights = [a.strip() for a in ai_insights_str.split(",") if a.strip()]
84
+
85
+ # Build the code snippet lines
86
  code_lines = [
87
+ "# Design Thinking Japan - Human Centered, AI Accelerated",
88
+ "import random",
89
+ "",
90
+ "class HumanCenteredAI:",
91
+ " def __init__(self, mission):",
92
+ " self.mission = mission",
93
+ " self.ideas = []",
94
+ " self.ai_accelerated = True",
95
+ "",
96
+ " def generate_idea(self):",
97
+ f" human_insights = {human_insights}",
98
+ f" ai_insights = {ai_insights}",
99
+ " idea = (",
100
+ " f\"Combining {random.choice(human_insights)} \"",
101
+ " f\"with {random.choice(ai_insights)}\"",
102
+ " )",
103
+ " self.ideas.append(idea)",
104
+ " return idea",
105
  "",
106
+ " def present_ideas(self):",
107
+ " for i, idea in enumerate(self.ideas, 1):",
108
+ " print(f\"Idea {i}: {idea}\")",
 
109
  "",
110
+ "# Initialize the HumanCenteredAI system",
111
+ f"design_thinking_japan = HumanCenteredAI(mission=\"{mission}\")",
112
  "",
113
+ "# Generate and present some ideas",
114
+ "for _ in range(5):",
115
+ " design_thinking_japan.generate_idea()",
116
+ "",
117
+ "design_thinking_japan.present_ideas()"
118
  ]
119
+
120
+ return "\n".join(code_lines)
 
 
121
 
122
  final_answer = FinalAnswerTool()
123
  model = HfApiModel(