add playful snippet generator with default fallbacks
Browse filesadd playful “human-centered AI” snippet generator with default fallbacks and whimsical insights
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 |
-
|
46 |
-
|
47 |
mission: str = None,
|
48 |
-
|
|
|
49 |
) -> str:
|
50 |
"""
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
Args:
|
55 |
-
|
56 |
-
|
57 |
-
|
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 |
-
#
|
62 |
-
|
63 |
-
"
|
64 |
-
"
|
65 |
-
"
|
66 |
-
"Engineer post-human empathy"
|
67 |
]
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
]
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
84 |
code_lines = [
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
"
|
92 |
-
"
|
93 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
"",
|
95 |
-
"
|
96 |
-
"
|
97 |
-
"
|
98 |
-
" raise Exception('No rift detected. Expansion halted!')",
|
99 |
"",
|
100 |
-
|
|
|
101 |
"",
|
102 |
-
|
|
|
|
|
|
|
|
|
103 |
]
|
104 |
-
|
105 |
-
|
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(
|