Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,62 +11,68 @@ from Gradio_UI import GradioUI
|
|
| 11 |
|
| 12 |
@tool
|
| 13 |
def generate_passover_coloring_pages(age: int) -> str:
|
| 14 |
-
"""
|
| 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
|
| 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 |
-
#
|
| 50 |
final_answer = FinalAnswerTool()
|
| 51 |
|
| 52 |
-
# Hugging Face Model Configuration
|
| 53 |
model = HfApiModel(
|
| 54 |
max_tokens=2096,
|
| 55 |
temperature=0.5,
|
| 56 |
model_id='Qwen/Qwen2.5-Coder-32B-Instruct'
|
| 57 |
)
|
| 58 |
|
| 59 |
-
# Load prompt templates
|
| 60 |
with open("prompts.yaml", 'r') as stream:
|
| 61 |
prompt_templates = yaml.safe_load(stream)
|
| 62 |
-
|
| 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 |
)
|
| 70 |
|
| 71 |
-
# Launch the UI
|
| 72 |
GradioUI(agent).launch()
|
|
|
|
|
|
| 11 |
|
| 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 |
+
|
| 17 |
Args:
|
| 18 |
age (int): The age of the child (1-12).
|
| 19 |
+
|
| 20 |
Returns:
|
| 21 |
+
str: A list of suggested Passover-themed coloring pages.
|
| 22 |
"""
|
| 23 |
+
|
| 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 |
complexity_levels = {
|
| 28 |
(1, 3): "simple",
|
| 29 |
(4, 6): "basic",
|
| 30 |
(7, 9): "intermediate",
|
| 31 |
(10, 12): "advanced"
|
| 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 |
+
# Попытка сгенерировать изображения
|
| 45 |
+
try:
|
| 46 |
+
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 47 |
+
images = [image_generation_tool(page) for page in selected_pages]
|
| 48 |
+
return final_answer(images)
|
| 49 |
+
except Exception as e:
|
| 50 |
+
return f"Error generating images: {str(e)}"
|
| 51 |
+
|
| 52 |
response = f"Passover Coloring Pages for a {age}-year-old:\n\n"
|
| 53 |
response += "\n".join(f"- {page}" for page in selected_pages)
|
| 54 |
|
| 55 |
return response
|
| 56 |
|
| 57 |
+
# Настройка агента
|
| 58 |
final_answer = FinalAnswerTool()
|
| 59 |
|
|
|
|
| 60 |
model = HfApiModel(
|
| 61 |
max_tokens=2096,
|
| 62 |
temperature=0.5,
|
| 63 |
model_id='Qwen/Qwen2.5-Coder-32B-Instruct'
|
| 64 |
)
|
| 65 |
|
|
|
|
| 66 |
with open("prompts.yaml", 'r') as stream:
|
| 67 |
prompt_templates = yaml.safe_load(stream)
|
| 68 |
+
|
|
|
|
| 69 |
agent = CodeAgent(
|
| 70 |
model=model,
|
| 71 |
tools=[final_answer, generate_passover_coloring_pages],
|
| 72 |
max_steps=6,
|
| 73 |
+
verbosity_level=1,
|
| 74 |
+
prompt_templates=prompt_templates
|
| 75 |
)
|
| 76 |
|
|
|
|
| 77 |
GradioUI(agent).launch()
|
| 78 |
+
|