Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,71 +9,43 @@ from tools.final_answer import FinalAnswerTool
|
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
|
| 12 |
-
|
| 13 |
@tool
|
| 14 |
-
def generate_passover_coloring_pages(age: int
|
| 15 |
-
"""Generates Passover-themed coloring pages based on a child's age
|
|
|
|
| 16 |
Args:
|
| 17 |
age (int): The age of the child (1-12).
|
| 18 |
-
|
| 19 |
Returns:
|
| 20 |
str: A list of suggested Passover-themed coloring pages or an error message.
|
| 21 |
"""
|
| 22 |
-
|
| 23 |
-
# Validate inputs
|
| 24 |
if not isinstance(age, int) or not (1 <= age <= 12):
|
| 25 |
return "Error: Please provide a valid age between 1 and 12."
|
| 26 |
-
|
| 27 |
-
gender = gender.lower()
|
| 28 |
-
if gender not in ['boy', 'girl']:
|
| 29 |
-
return "Error: Please specify gender as 'boy' or 'girl'."
|
| 30 |
-
|
| 31 |
-
# Determine complexity level based on age
|
| 32 |
complexity_levels = {
|
| 33 |
(1, 3): "simple",
|
| 34 |
(4, 6): "basic",
|
| 35 |
(7, 9): "intermediate",
|
| 36 |
(10, 12): "advanced"
|
| 37 |
}
|
|
|
|
| 38 |
complexity = next(value for (low, high), value in complexity_levels.items() if low <= age <= high)
|
| 39 |
-
|
| 40 |
-
# Define Passover-themed coloring pages
|
| 41 |
passover_pages = {
|
| 42 |
-
"simple":
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
"basic": {
|
| 47 |
-
"boy": ["Parting of the Red Sea", "Ten Plagues scenes", "Four Questions illustrations", "Afikoman hunt"],
|
| 48 |
-
"girl": ["Parting of the Red Sea", "Ten Plagues scenes", "Four Questions illustrations", "Miriam dancing"]
|
| 49 |
-
},
|
| 50 |
-
"intermediate": {
|
| 51 |
-
"boy": ["Detailed Seder table", "Exodus story scenes", "Hebrew letter decorations", "Egyptian pyramids"],
|
| 52 |
-
"girl": ["Detailed Seder table", "Exodus story scenes", "Hebrew letter decorations", "Family Seder celebration"]
|
| 53 |
-
},
|
| 54 |
-
"advanced": {
|
| 55 |
-
"boy": ["Intricate Haggadah illustrations", "Detailed symbolism scene", "Combined Passover story panels", "Hebrew calligraphy art"],
|
| 56 |
-
"girl": ["Intricate Haggadah illustrations", "Detailed symbolism scene", "Combined Passover story panels", "Hebrew calligraphy art"]
|
| 57 |
-
}
|
| 58 |
}
|
| 59 |
-
|
| 60 |
-
selected_pages = passover_pages[complexity]
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
# Load the image generation tool
|
| 64 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 65 |
-
images = [image_generation_tool(page) for page in selected_pages]
|
| 66 |
-
return final_answer(images)
|
| 67 |
-
except Exception as e:
|
| 68 |
-
return f"Error generating images: {str(e)}"
|
| 69 |
-
|
| 70 |
-
# Fallback text response
|
| 71 |
-
response = f"Passover Coloring Pages for a {age}-year-old {gender}:\n\n"
|
| 72 |
response += "\n".join(f"- {page}" for page in selected_pages)
|
| 73 |
|
| 74 |
return response
|
| 75 |
|
| 76 |
-
|
| 77 |
# Initialize FinalAnswerTool
|
| 78 |
final_answer = FinalAnswerTool()
|
| 79 |
|
|
@@ -91,7 +63,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 91 |
# Initialize the agent with registered tools
|
| 92 |
agent = CodeAgent(
|
| 93 |
model=model,
|
| 94 |
-
tools=[final_answer, generate_passover_coloring_pages],
|
| 95 |
max_steps=6,
|
| 96 |
verbosity_level=1
|
| 97 |
)
|
|
|
|
| 9 |
from Gradio_UI import GradioUI
|
| 10 |
|
| 11 |
|
|
|
|
| 12 |
@tool
|
| 13 |
+
def generate_passover_coloring_pages(age: int) -> str:
|
| 14 |
+
"""Generates Passover-themed coloring pages based on a child's age.
|
| 15 |
+
|
| 16 |
Args:
|
| 17 |
age (int): The age of the child (1-12).
|
| 18 |
+
|
| 19 |
Returns:
|
| 20 |
str: A list of suggested Passover-themed coloring pages or an error message.
|
| 21 |
"""
|
| 22 |
+
|
|
|
|
| 23 |
if not isinstance(age, int) or not (1 <= age <= 12):
|
| 24 |
return "Error: Please provide a valid age between 1 and 12."
|
| 25 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
complexity_levels = {
|
| 27 |
(1, 3): "simple",
|
| 28 |
(4, 6): "basic",
|
| 29 |
(7, 9): "intermediate",
|
| 30 |
(10, 12): "advanced"
|
| 31 |
}
|
| 32 |
+
|
| 33 |
complexity = next(value for (low, high), value in complexity_levels.items() if low <= age <= high)
|
| 34 |
+
|
|
|
|
| 35 |
passover_pages = {
|
| 36 |
+
"simple": ["Simple matzah", "Basic Seder plate", "Moses in a basket", "Simple frog (plague)"],
|
| 37 |
+
"basic": ["Parting of the Red Sea", "Ten Plagues scenes", "Four Questions illustrations", "Afikoman hunt"],
|
| 38 |
+
"intermediate": ["Detailed Seder table", "Exodus story scenes", "Hebrew letter decorations", "Egyptian pyramids"],
|
| 39 |
+
"advanced": ["Intricate Haggadah illustrations", "Detailed symbolism scene", "Combined Passover story panels", "Hebrew calligraphy art"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
}
|
| 41 |
+
|
| 42 |
+
selected_pages = passover_pages[complexity]
|
| 43 |
+
|
| 44 |
+
response = f"Passover Coloring Pages for a {age}-year-old:\n\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
response += "\n".join(f"- {page}" for page in selected_pages)
|
| 46 |
|
| 47 |
return response
|
| 48 |
|
|
|
|
| 49 |
# Initialize FinalAnswerTool
|
| 50 |
final_answer = FinalAnswerTool()
|
| 51 |
|
|
|
|
| 63 |
# Initialize the agent with registered tools
|
| 64 |
agent = CodeAgent(
|
| 65 |
model=model,
|
| 66 |
+
tools=[final_answer, generate_passover_coloring_pages],
|
| 67 |
max_steps=6,
|
| 68 |
verbosity_level=1
|
| 69 |
)
|