RozzaCreat commited on
Commit
7576cb6
·
verified ·
1 Parent(s): a86f149

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -31
app.py CHANGED
@@ -12,7 +12,7 @@ from Gradio_UI import GradioUI
12
  @tool
13
  def generate_passover_coloring_pages(age: int) -> str:
14
  """
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
  Returns:
@@ -30,45 +30,45 @@ def generate_passover_coloring_pages(age: int) -> str:
30
 
31
  complexity = next(value for (low, high), value in complexity_levels.items() if low <= age <= high)
32
 
33
- # Enhanced prompts for better coloring pages
34
  passover_pages = {
35
  "simple": [
36
- "Line drawing of a matzah for a simple coloring page, thick black outlines, white background, perfect for a child's coloring book",
37
- "Simple black and white outline of a Seder plate with clear divisions, coloring book style, thick lines",
38
- "Black and white line art of baby Moses in a basket for a child's coloring book, simple outlines",
39
- "Simple black and white outline of a frog (plague) for children's coloring book, thick lines, no shading"
40
  ],
41
  "basic": [
42
- "Black and white outline of the Parting of the Red Sea scene for a coloring book, clear distinct lines",
43
- "Coloring book page with Ten Plagues illustrations, black outline on white background, no shading",
44
- "Black and white outline illustrations of the Four Questions for a Passover coloring book",
45
- "Afikoman hunt maze in black and white outline for a coloring book, thick lines"
46
  ],
47
  "intermediate": [
48
- "Detailed black and white outline of a Seder table for a coloring book, clear distinct elements",
49
- "Black and white outline of Exodus story scenes for coloring book, clear lines",
50
- "Hebrew letter decorations for 'Pesach' in black and white outline style for coloring book",
51
- "Black and white outline of Egyptian pyramids with Israelites for a coloring book"
52
  ],
53
  "advanced": [
54
- "Intricate black and white line art of Haggadah illustrations for a coloring book, detailed outlines",
55
- "Detailed symbolism scene in black and white outline for an advanced coloring book",
56
- "Combined Passover story panels in black and white line art for coloring book",
57
- "Hebrew calligraphy art in black and white outline for a coloring book, intricate details"
58
  ]
59
  }
60
 
61
  selected_pages = passover_pages[complexity]
62
- descriptions = [f"- {page.split(',')[0]}" for page in selected_pages]
63
 
64
- # Try to generate images with improved prompts
65
  try:
66
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
67
 
68
- # Use more specific prompts for coloring pages
69
  enhanced_prompts = []
70
  for page in selected_pages:
71
- enhanced_prompts.append(f"{page}, suitable for printing as a coloring page")
72
 
73
  images = [image_generation_tool(prompt) for prompt in enhanced_prompts]
74
 
@@ -82,15 +82,15 @@ def generate_passover_coloring_pages(age: int) -> str:
82
  image_paths.append(temp_path)
83
 
84
  # Create a formatted response with descriptions
85
- response = f"## Passover Coloring Pages for a {age}-year-old:\n\n"
86
- response += "\n".join(descriptions)
87
 
88
  # Return the response with image paths
89
  return f"{response}\n\nImages are saved and ready for display."
90
  except Exception as e:
91
  # If image generation fails, return text description
92
- response = f"## Passover Coloring Pages for a {age}-year-old:\n\n"
93
- response += "\n".join(descriptions)
94
  return f"{response}\n\nError generating images: {str(e)}"
95
 
96
  # Custom UI wrapper to handle image display
@@ -105,7 +105,8 @@ class CustomGradioUI(GradioUI):
105
  with gr.Blocks() as demo:
106
  with gr.Row():
107
  with gr.Column(scale=1):
108
- gr.Markdown("# Passover Coloring Pages Generator")
 
109
 
110
  with gr.Row():
111
  with gr.Column(scale=1):
@@ -117,7 +118,7 @@ class CustomGradioUI(GradioUI):
117
  output_text = gr.Markdown(label="Generated Pages")
118
 
119
  with gr.Row():
120
- gallery = gr.Gallery(label="Coloring Pages", show_label=True)
121
 
122
  def process_input(input_text):
123
  try:
@@ -152,13 +153,16 @@ class CustomGradioUI(GradioUI):
152
 
153
  # Modified prompt templates to handle simple age input
154
  custom_prompt_templates = {
155
- "react-system": """You are an helpful agent that helps children learn about Passover through coloring pages.
156
  You have access to the following tools:
157
 
158
  {tools_string}
159
 
160
- When a user enters a number between 1 and 12, interpret it as the age of a child and generate Passover coloring pages suitable for that age using the generate_passover_coloring_pages tool.
161
- If you're asked to generate coloring pages or if the input is just a number, assume the user wants Passover coloring pages for a child of that age.
 
 
 
162
 
163
  To use a tool, output an action in this format:
164
  ```py
 
12
  @tool
13
  def generate_passover_coloring_pages(age: int) -> str:
14
  """
15
+ Generates Jewish Passover/Pesach-themed coloring pages based on a child's age.
16
  Args:
17
  age (int): The age of the child (1-12).
18
  Returns:
 
30
 
31
  complexity = next(value for (low, high), value in complexity_levels.items() if low <= age <= high)
32
 
33
+ # Enhanced prompts specifically for Jewish Passover/Pesach themes
34
  passover_pages = {
35
  "simple": [
36
+ "Line drawing of matzah for Jewish Passover coloring page, thick black outlines, white background, child-friendly",
37
+ "Simple black outline of a Seder plate with spaces for the six items (karpas, charoset, maror, zeroa, beitzah, chazeret), coloring book style, thick lines",
38
+ "Simple outline drawing of the Afikoman (broken piece of matzah) hidden in fabric, black and white for coloring",
39
+ "Simple outline of a Kiddush cup for Passover seder, black and white for coloring"
40
  ],
41
  "basic": [
42
+ "Black and white outline of Moses parting the Red Sea, traditional Jewish Pesach story, no Christian symbols, coloring book style",
43
+ "Outline drawing of the Ten Plagues (blood, frogs, lice, wild animals, cattle disease, boils, hail, locusts, darkness, death of firstborn) in separated panels, Jewish Passover theme",
44
+ "Haggadah Four Questions illustrations in Hebrew and English for coloring, Jewish Passover tradition",
45
+ "Afikoman hunt maze with matzah at the center, black and white outline for Jewish Passover coloring"
46
  ],
47
  "intermediate": [
48
+ "Detailed black and white outline of a traditional Jewish Seder table with all symbolic foods and Haggadah, no crosses or Christian symbols",
49
+ "Hebrew letter decorations spelling 'Pesach' (פסח) for coloring, traditional Jewish style",
50
+ "Outline drawing of ancient Israelites leaving Egypt, Jewish Passover story, historically accurate depiction",
51
+ "Black and white outline of the Four Sons from the Haggadah, traditional Jewish Passover story characters"
52
  ],
53
  "advanced": [
54
+ "Intricate Haggadah page illustrations in black and white, showing the order of the Seder, traditional Jewish style",
55
+ "Detailed scene of Miriam and women celebrating after crossing the Red Sea with tambourines, Jewish Passover story",
56
+ "Intricate Hebrew calligraphy spelling 'Next year in Jerusalem' (לשנה הבאה בירושלים) for coloring",
57
+ "Detailed symbolic Jewish Passover illustrations showing the journey from slavery to freedom, with proper Jewish symbols only"
58
  ]
59
  }
60
 
61
  selected_pages = passover_pages[complexity]
62
+ descriptions = [page.split(',')[0] for page in selected_pages]
63
 
64
+ # Try to generate images with improved Jewish Passover prompts
65
  try:
66
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
67
 
68
+ # Use more specific prompts for coloring pages, emphasizing Jewish traditions
69
  enhanced_prompts = []
70
  for page in selected_pages:
71
+ enhanced_prompts.append(f"{page}, Jewish traditional Passover symbols only, no Christian imagery, suitable for printing as a coloring page")
72
 
73
  images = [image_generation_tool(prompt) for prompt in enhanced_prompts]
74
 
 
82
  image_paths.append(temp_path)
83
 
84
  # Create a formatted response with descriptions
85
+ response = f"## Jewish Passover (Pesach) Coloring Pages for a {age}-year-old:\n\n"
86
+ response += "\n".join([f"- {desc}" for desc in descriptions])
87
 
88
  # Return the response with image paths
89
  return f"{response}\n\nImages are saved and ready for display."
90
  except Exception as e:
91
  # If image generation fails, return text description
92
+ response = f"## Jewish Passover (Pesach) Coloring Pages for a {age}-year-old:\n\n"
93
+ response += "\n".join([f"- {desc}" for desc in descriptions])
94
  return f"{response}\n\nError generating images: {str(e)}"
95
 
96
  # Custom UI wrapper to handle image display
 
105
  with gr.Blocks() as demo:
106
  with gr.Row():
107
  with gr.Column(scale=1):
108
+ gr.Markdown("# Jewish Passover (Pesach) Coloring Pages Generator")
109
+ gr.Markdown("Generate traditional Jewish Passover coloring pages for children")
110
 
111
  with gr.Row():
112
  with gr.Column(scale=1):
 
118
  output_text = gr.Markdown(label="Generated Pages")
119
 
120
  with gr.Row():
121
+ gallery = gr.Gallery(label="Jewish Passover Coloring Pages", show_label=True)
122
 
123
  def process_input(input_text):
124
  try:
 
153
 
154
  # Modified prompt templates to handle simple age input
155
  custom_prompt_templates = {
156
+ "react-system": """You are a helpful agent that helps children learn about Jewish Passover/Pesach through coloring pages.
157
  You have access to the following tools:
158
 
159
  {tools_string}
160
 
161
+ When a user enters a number between 1 and 12, interpret it as the age of a child and generate Jewish Passover coloring pages suitable for that age using the generate_passover_coloring_pages tool.
162
+ If you're asked to generate coloring pages or if the input is just a number, assume the user wants Jewish Passover coloring pages for a child of that age.
163
+
164
+ Important: Only generate authentic Jewish Passover (Pesach) symbols and imagery - including matzah, seder plate, haggadah, afikoman, four cups of wine, the exodus story, etc.
165
+ Do NOT include any Christian symbols or imagery like crosses, Jesus, or other non-Jewish religious elements.
166
 
167
  To use a tool, output an action in this format:
168
  ```py