Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,28 +12,19 @@ from typing import List, Dict, Any, Optional
|
|
| 12 |
from Gradio_UI import GradioUI
|
| 13 |
import time # For rate limiting
|
| 14 |
|
|
|
|
| 15 |
@tool
|
| 16 |
def get_healthy_cheat_meal(diet_type: str) -> List[Dict[str, Any]]:
|
| 17 |
-
"""
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
reliable, up-to-date information on healthy sweet dish alternatives.
|
| 23 |
-
|
| 24 |
-
Args:
|
| 25 |
-
diet_type (str): The diet type to search for (e.g., "Keto", "Paleo", "Vegan", "Vegetarian", "Non-Vegetarian").
|
| 26 |
-
|
| 27 |
Returns:
|
| 28 |
-
A list of
|
| 29 |
-
{
|
| 30 |
-
"recipe_name": str, # The name of the recipe.
|
| 31 |
-
"source": str # A credible source or URL where the recipe was found.
|
| 32 |
-
}
|
| 33 |
"""
|
| 34 |
-
|
| 35 |
query = f"healthy {diet_type} sweet dish recipe with ingredients and instructions"
|
| 36 |
-
|
| 37 |
try:
|
| 38 |
ddgs = DDGS() # Initialize DDGS outside the loop
|
| 39 |
search_results = ddgs.text(
|
|
@@ -42,28 +33,28 @@ def get_healthy_cheat_meal(diet_type: str) -> List[Dict[str, Any]]:
|
|
| 42 |
safesearch="moderate",
|
| 43 |
max_results=5
|
| 44 |
)
|
| 45 |
-
|
| 46 |
if not search_results:
|
| 47 |
return [{"error": "No recipes found. Try a different diet type or check your query."}]
|
| 48 |
-
|
| 49 |
recipes = []
|
| 50 |
-
|
| 51 |
for result in search_results:
|
| 52 |
title = result.get('title', '').split(' | ')[0] # Clean up title
|
| 53 |
-
link = result.get('href', '')
|
| 54 |
-
|
| 55 |
if title and link:
|
| 56 |
recipes.append({
|
| 57 |
"recipe_name": title.strip(),
|
| 58 |
"source": link
|
| 59 |
})
|
| 60 |
-
time.sleep(1)
|
| 61 |
-
|
| 62 |
if not recipes:
|
| 63 |
return [{"error": "No valid recipes found. Please try a different search."}]
|
| 64 |
-
|
| 65 |
return recipes
|
| 66 |
-
|
| 67 |
except Exception as e:
|
| 68 |
return [{"error": f"An error occurred while searching: {str(e)}"}]
|
| 69 |
|
|
|
|
| 12 |
from Gradio_UI import GradioUI
|
| 13 |
import time # For rate limiting
|
| 14 |
|
| 15 |
+
|
| 16 |
@tool
|
| 17 |
def get_healthy_cheat_meal(diet_type: str) -> List[Dict[str, Any]]:
|
| 18 |
+
"""Search for healthy sweet dish alternatives based on specific diet types.
|
| 19 |
+
|
| 20 |
+
diet_type:
|
| 21 |
+
The specific diet type to search for (e.g., Keto, Paleo, Vegan, Vegetarian, Non-Vegetarian).
|
| 22 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
Returns:
|
| 24 |
+
A list of recipe dictionaries, each containing a recipe name and source URL.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
"""
|
|
|
|
| 26 |
query = f"healthy {diet_type} sweet dish recipe with ingredients and instructions"
|
| 27 |
+
|
| 28 |
try:
|
| 29 |
ddgs = DDGS() # Initialize DDGS outside the loop
|
| 30 |
search_results = ddgs.text(
|
|
|
|
| 33 |
safesearch="moderate",
|
| 34 |
max_results=5
|
| 35 |
)
|
| 36 |
+
|
| 37 |
if not search_results:
|
| 38 |
return [{"error": "No recipes found. Try a different diet type or check your query."}]
|
| 39 |
+
|
| 40 |
recipes = []
|
| 41 |
+
|
| 42 |
for result in search_results:
|
| 43 |
title = result.get('title', '').split(' | ')[0] # Clean up title
|
| 44 |
+
link = result.get('href', '') # Use 'href' for the link
|
| 45 |
+
|
| 46 |
if title and link:
|
| 47 |
recipes.append({
|
| 48 |
"recipe_name": title.strip(),
|
| 49 |
"source": link
|
| 50 |
})
|
| 51 |
+
time.sleep(1) # Added a small delay to respect rate limits
|
| 52 |
+
|
| 53 |
if not recipes:
|
| 54 |
return [{"error": "No valid recipes found. Please try a different search."}]
|
| 55 |
+
|
| 56 |
return recipes
|
| 57 |
+
|
| 58 |
except Exception as e:
|
| 59 |
return [{"error": f"An error occurred while searching: {str(e)}"}]
|
| 60 |
|