Spaces:
Sleeping
Sleeping
| from typing import Any, Optional | |
| from smolagents.tools import Tool | |
| import requests | |
| import markdownify | |
| import smolagents | |
| class RecipeGeneratorTool(Tool): | |
| name = "recipe_generator" | |
| description = "Generates a high-protein recipe based on given parameters like calories, protein content, and ingredients." | |
| inputs = { | |
| 'calories': {'type': 'number', 'description': 'The desired calorie content for the recipe.'}, | |
| 'protein': {'type': 'number', 'description': 'The desired protein content (in grams) for the recipe.'}, | |
| 'ingredients': {'type': 'array', 'description': 'Array of ingredients to include in the recipe.'} | |
| } | |
| output_type = 'string' | |
| def generate_recipe(self, calories: float, protein: float, ingredients: list): | |
| # Placeholder for a real API request to a recipe database or calculation logic | |
| recipe_data = { | |
| "title": "Protein-Packed Chicken Salad", | |
| "description": "A healthy, protein-rich salad with chicken, spinach, and quinoa.", | |
| "ingredients": ingredients, | |
| "steps": [ | |
| "Cook the chicken breast until fully done.", | |
| "Cook quinoa according to package instructions.", | |
| "Mix cooked chicken and quinoa with spinach.", | |
| "Add a drizzle of olive oil and a squeeze of lemon." | |
| ], | |
| "calories": calories, | |
| "protein": protein | |
| } | |
| # Converting recipe data to markdown for better readability | |
| recipe_markdown = f"# {recipe_data['title']}\n\n" | |
| recipe_markdown += f"**Description**: {recipe_data['description']}\n\n" | |
| recipe_markdown += "## Ingredients:\n" | |
| for ingredient in recipe_data['ingredients']: | |
| recipe_markdown += f"- {ingredient}\n" | |
| recipe_markdown += "\n## Steps:\n" | |
| for step in recipe_data['steps']: | |
| recipe_markdown += f"1. {step}\n" | |
| recipe_markdown += f"\n**Calories**: {recipe_data['calories']} kcal\n" | |
| recipe_markdown += f"**Protein**: {recipe_data['protein']} g\n" | |
| return markdownify.markdownify(recipe_markdown) | |
| def forward(self, calories: float, protein: float, ingredients: list): | |
| return self.generate_recipe(calories, protein, ingredients) | |