RozzaCreat commited on
Commit
7a0dcb9
·
verified ·
1 Parent(s): a061ae1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -16
app.py CHANGED
@@ -9,28 +9,72 @@ from tools.final_answer import FinalAnswerTool
9
  from Gradio_UI import GradioUI
10
 
11
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
- @tool
13
- def create_new_vday_card_tool(theme:str) -> str: #it's import to specify the return type
14
- #Keep this format for the description / args / args description but feel free to modify the tool
15
- """A tool that generates a custom Valentine's Day card based on a given theme.
 
 
16
  Args:
17
- theme: A string representing the theme for the Valentine's Day card.
 
 
 
 
18
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  try:
20
- # Import tool from Hub
21
- '''
22
- image_generation_tool = Tool.from_space(
23
- space_id="black-forest-labs/FLUX.1-schnell",
24
- name="generate-image",
25
- description="Generate image from prompt"
26
- )
27
- '''
28
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
29
- image = image_generation_tool(theme)
30
- return final_answer(image)
31
  except Exception as e:
32
- return f"Error creating card for theme '{theme}': {str(e)}"
33
 
 
 
 
 
 
34
  #image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
35
 
36
  final_answer = FinalAnswerTool()
 
9
  from Gradio_UI import GradioUI
10
 
11
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
+
13
+
14
+
15
+ def generate_passover_coloring_pages(age: int, gender: str) -> str:
16
+ """Generates Passover-themed coloring pages based on a child's age and gender.
17
+
18
  Args:
19
+ age (int): The age of the child (1-12).
20
+ gender (str): The gender of the child ('boy' or 'girl').
21
+
22
+ Returns:
23
+ str: A list of suggested Passover-themed coloring pages or an error message.
24
  """
25
+
26
+ # Validate inputs
27
+ if not isinstance(age, int) or not (1 <= age <= 12):
28
+ return "Error: Please provide a valid age between 1 and 12."
29
+
30
+ gender = gender.lower()
31
+ if gender not in ['boy', 'girl']:
32
+ return "Error: Please specify gender as 'boy' or 'girl'."
33
+
34
+ # Determine complexity level based on age
35
+ complexity_levels = {
36
+ (1, 3): "simple",
37
+ (4, 6): "basic",
38
+ (7, 9): "intermediate",
39
+ (10, 12): "advanced"
40
+ }
41
+ complexity = next(value for (low, high), value in complexity_levels.items() if low <= age <= high)
42
+
43
+ # Define Passover-themed coloring pages
44
+ passover_pages = {
45
+ "simple": {
46
+ "boy": ["Simple matzah", "Basic Seder plate", "Moses in a basket", "Simple frog (plague)"],
47
+ "girl": ["Simple matzah", "Basic Seder plate", "Moses in a basket", "Miriam with tambourine"]
48
+ },
49
+ "basic": {
50
+ "boy": ["Parting of the Red Sea", "Ten Plagues scenes", "Four Questions illustrations", "Afikoman hunt"],
51
+ "girl": ["Parting of the Red Sea", "Ten Plagues scenes", "Four Questions illustrations", "Miriam dancing"]
52
+ },
53
+ "intermediate": {
54
+ "boy": ["Detailed Seder table", "Exodus story scenes", "Hebrew letter decorations", "Egyptian pyramids"],
55
+ "girl": ["Detailed Seder table", "Exodus story scenes", "Hebrew letter decorations", "Family Seder celebration"]
56
+ },
57
+ "advanced": {
58
+ "boy": ["Intricate Haggadah illustrations", "Detailed symbolism scene", "Combined Passover story panels", "Hebrew calligraphy art"],
59
+ "girl": ["Intricate Haggadah illustrations", "Detailed symbolism scene", "Combined Passover story panels", "Hebrew calligraphy art"]
60
+ }
61
+ }
62
+
63
+ selected_pages = passover_pages[complexity][gender]
64
+
65
+ # Try generating an image (if applicable)
66
  try:
 
 
 
 
 
 
 
 
67
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
68
+ images = [image_generation_tool(page) for page in selected_pages]
69
+ return final_answer(images)
70
  except Exception as e:
71
+ return f"Error generating images: {str(e)}"
72
 
73
+ # Fallback text response if image generation fails
74
+ response = f"Passover Coloring Pages for a {age}-year-old {gender}:\n\n"
75
+ response += "\n".join(f"- {page}" for page in selected_pages)
76
+
77
+ return response
78
  #image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
79
 
80
  final_answer = FinalAnswerTool()