subba5076 commited on
Commit
4594455
·
verified ·
1 Parent(s): dcad982

Upload 3 files

Browse files
Files changed (3) hide show
  1. agent_core.py +242 -0
  2. app.py +15 -0
  3. requirements.txt +3 -0
agent_core.py ADDED
@@ -0,0 +1,242 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import CodeAgent, WebSearchTool, InferenceClientModel, VisitWebpageTool, Tool, tool
2
+ import random
3
+
4
+ # -----------------------------
5
+ # MENU SUGGESTION TOOL
6
+ # -----------------------------
7
+ @tool
8
+ def suggest_menu(occasion: str) -> str:
9
+ """
10
+ Suggests a single Indian chicken-based dish depending on the occasion.
11
+
12
+ Args:
13
+ occasion: 'casual' for roommates only, 'formal' when guests come.
14
+ """
15
+ casual_dishes = [
16
+ "Chicken 65",
17
+ "Chicken Biryani",
18
+ "Pepper Chicken Fry",
19
+ "Andhra Chicken Roast",
20
+ "Chicken Ghee Roast"
21
+ ]
22
+
23
+ formal_dishes = [
24
+ "Hyderabadi Chicken Dum Biryani",
25
+ "Butter Chicken",
26
+ "Chicken Tandoori",
27
+ "Chicken Chettinad",
28
+ "Chicken Mughlai"
29
+ ]
30
+
31
+ import random
32
+
33
+ if occasion == "casual":
34
+ dish = random.choice(casual_dishes)
35
+ return f"Casual Menu Dish: {dish}"
36
+ elif occasion == "formal":
37
+ dish = random.choice(formal_dishes)
38
+ return f"Formal Menu Dish: {dish}"
39
+ else:
40
+ return "Please choose 'casual' or 'formal'."
41
+
42
+
43
+ # -----------------------------
44
+ # CATERING SERVICE TOOL (4 PEOPLE)
45
+ # -----------------------------
46
+ @tool
47
+ def catering_service_tool(query: str) -> str:
48
+ """
49
+ Returns the highest-rated person among the 4 roommates.
50
+
51
+ Args:
52
+ query: A search term or keyword (not used in logic, but required for schema).
53
+ """
54
+ services = {
55
+ "Srikanth": 4.9,
56
+ "Nitish": 4.8,
57
+ "Subrahmanya": 4.7,
58
+ "Rahul": 4.6,
59
+ }
60
+
61
+ best_service = max(services, key=services.get)
62
+ return best_service
63
+
64
+ # -----------------------------
65
+ # INDIAN MOVIE THEME TOOL
66
+ # -----------------------------
67
+ class IndianMovieThemeTool(Tool):
68
+ name = "indian_movie_theme_generator"
69
+ description = "Suggests Indian movie/series-based party themes."
70
+
71
+ inputs = {
72
+ "category": {
73
+ "type": "string",
74
+ "description": "Theme type (e.g., 'mass', 'romantic', 'gangster', 'pan-india').",
75
+ }
76
+ }
77
+
78
+ output_type = "string"
79
+
80
+ def forward(self, category: str):
81
+ themes = {
82
+ "mass": "KGF Theme Night: Gold, black outfits, heavy bass music, and dramatic lighting.",
83
+ "romantic": "YJHD Theme: Colorful decor, travel vibes, and chill Bollywood playlist.",
84
+ "gangster": "Gangs of Wasseypur Theme: Rustic setup, desi snacks, and intense Bollywood tracks.",
85
+ "pan-india": "RRR Theme: Traditional outfits, energetic Telugu/Hindi songs, and festive lighting."
86
+ }
87
+ return themes.get(category.lower(), "Theme not found. Try 'mass', 'romantic', 'gangster', or 'pan-india'.")
88
+
89
+ # -----------------------------
90
+ # PLAYLIST GENERATOR TOOL
91
+ # -----------------------------
92
+ @tool
93
+ def playlist_tool(theme: str) -> str:
94
+ """
95
+ Generates a playlist based on the theme.
96
+ If no playlist is found, returns a structured failure signal so the agent
97
+ automatically tries WebSearchTool.
98
+
99
+ Args:
100
+ theme: The selected theme name.
101
+ """
102
+ playlists = {
103
+ "KGF": ["Salaam Rocky Bhai", "Garbadhi", "Dheera Dheera"],
104
+ "YJHD": ["Badtameez Dil", "Kabira", "Ilahi"],
105
+ "Gangs of Wasseypur": ["Jiya Tu", "Hunter", "Keh Ke Lunga"],
106
+ "RRR": ["Naatu Naatu", "Komuram Bheemudo", "Dosti"]
107
+ }
108
+
109
+ for key in playlists:
110
+ if key.lower() in theme.lower():
111
+ return f"Playlist for {key}:\n" + "\n".join(playlists[key])
112
+
113
+ # IMPORTANT: structured failure signal
114
+ return {
115
+ "error": "playlist_not_found",
116
+ "reason": f"No playlist found for theme '{theme}'. Try searching online."
117
+ }
118
+ @tool
119
+ def smart_playlist_resolver(theme: str) -> str:
120
+ """
121
+ Resolves playlists intelligently:
122
+ - First tries playlist_tool
123
+ - If it fails, instructs the agent to use WebSearchTool automatically
124
+
125
+ Args:
126
+ theme: The theme or language for the playlist.
127
+ """
128
+ result = playlist_tool(theme=theme)
129
+
130
+ # If playlist_tool returned a dict, it means failure
131
+ if isinstance(result, dict) and result.get("error") == "playlist_not_found":
132
+ # This is the key: a structured instruction to the agent
133
+ return {
134
+ "tool": "websearch",
135
+ "query": f"top 5 {theme} songs"
136
+ }
137
+
138
+ return result
139
+
140
+ # -----------------------------
141
+ # SHOPPING LIST TOOL
142
+ # -----------------------------
143
+ @tool
144
+ def shopping_list_tool(menu_type: str) -> str:
145
+ """
146
+ Generates a shopping list for the selected menu.
147
+
148
+ Args:
149
+ menu_type: 'casual' or 'formal'
150
+ """
151
+ if menu_type == "casual":
152
+ return (
153
+ "Shopping List (Casual):\n"
154
+ "- 2 kg Chicken\n"
155
+ "- Biryani Rice\n"
156
+ "- Curd\n"
157
+ "- Masala Powders\n"
158
+ "- Onions, Tomatoes\n"
159
+ "- Soft Drinks"
160
+ )
161
+ elif menu_type == "formal":
162
+ return (
163
+ "Shopping List (Formal):\n"
164
+ "- 3 kg Chicken\n"
165
+ "- Naan Ingredients\n"
166
+ "- Biryani Rice\n"
167
+ "- Butter & Cream\n"
168
+ "- Dessert Items\n"
169
+ "- Mocktail Mixes"
170
+ )
171
+ else:
172
+ return "Choose 'casual' or 'formal'."
173
+
174
+ # -----------------------------
175
+ # CLEANING DUTY ROTATION TOOL
176
+ # -----------------------------
177
+ @tool
178
+ def cleaning_rotation_tool(dummy: str) -> str:
179
+ """
180
+ Assigns cleaning duty to one of the 4 roommates randomly.
181
+
182
+ Args:
183
+ dummy: Placeholder argument (not used).
184
+ """
185
+ people = ["Srikanth", "Nitish", "Subrahmanya", "Rahul"]
186
+ return f"Cleaning duty today: {random.choice(people)}"
187
+
188
+ # -----------------------------
189
+ # WHO COOKS TODAY TOOL
190
+ # -----------------------------
191
+ @tool
192
+ def cooking_rotation_tool(dummy: str) -> str:
193
+ """
194
+ Randomly selects who cooks today.
195
+
196
+ Args:
197
+ dummy: Placeholder argument (not used).
198
+ """
199
+ people = ["Srikanth", "Nitish", "Subrahmanya", "Rahul"]
200
+ return f"Today's cook: {random.choice(people)}"
201
+
202
+ # -----------------------------
203
+ # BUDGET CALCULATOR TOOL
204
+ # -----------------------------
205
+ @tool
206
+ def budget_tool(total_cost: float) -> str:
207
+ """
208
+ Splits the total cost among 4 roommates.
209
+
210
+ Args:
211
+ total_cost: Total amount spent on the party in euros.
212
+ """
213
+ per_person = total_cost / 4
214
+ return f"Each person pays: €{per_person:.2f}"
215
+
216
+ # -----------------------------
217
+ # AGENT SETUP
218
+ # -----------------------------
219
+ agent = CodeAgent(
220
+ tools=[
221
+ WebSearchTool(),
222
+ VisitWebpageTool(),
223
+ suggest_menu,
224
+ catering_service_tool,
225
+ IndianMovieThemeTool(),
226
+ playlist_tool,
227
+ shopping_list_tool,
228
+ cleaning_rotation_tool,
229
+ cooking_rotation_tool,
230
+ budget_tool
231
+ ],
232
+ model=InferenceClientModel(),
233
+ max_steps=10,
234
+ verbosity_level=2
235
+ )
236
+
237
+ # -----------------------------
238
+ # RUN THE AGENT
239
+ # -----------------------------
240
+ agent.run(
241
+ "we 4 are having party give whos gonna clean today and 5 kannada songs to play now"
242
+ )
app.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+
3
+ import streamlit as st
4
+ from agent_core import run_agent
5
+
6
+ st.title("🎉 Berlin Roommate Party Planner AI")
7
+
8
+ user_input = st.text_input("Ask something:")
9
+
10
+ if st.button("Run"):
11
+ if user_input.strip():
12
+ with st.spinner("Thinking..."):
13
+ result = run_agent(user_input)
14
+ st.write("### Output")
15
+ st.write(result)
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ smolagents
2
+ streamlit
3
+ huggingface_hub