Download src/backend/tools/image_tool.py from anas-ahmed/Agentex-Hyper-Personalized-Tutor: direct link, hf CLI and curl.
- Browser
- Download file 1.91 kB
-
https://huggingface.co/spaces/anas-ahmed/Agentex-Hyper-Personalized-Tutor/resolve/main/src/backend/tools/image_tool.py
- Command line
-
hf download hf://spaces/anas-ahmed/Agentex-Hyper-Personalized-Tutor/src/backend/tools/image_tool.py
-
curl -L -o image_tool.py https://huggingface.co/spaces/anas-ahmed/Agentex-Hyper-Personalized-Tutor/resolve/main/src/backend/tools/image_tool.py
1.91 kB
| """Image generation tool for agents.""" | |
| from typing import Literal | |
| from agents import function_tool | |
| from backend.services.image_generator import ( | |
| generate_educational_image, | |
| generate_concept_visualization, | |
| ) | |
| async def generate_image( | |
| description: str, | |
| style: Literal[ | |
| "realistic", | |
| "cartoon", | |
| "diagram", | |
| "sketch", | |
| "watercolor", | |
| "3d", | |
| "minimalist", | |
| "educational", | |
| ] = "educational", | |
| context: str = "", | |
| ) -> str: | |
| """ | |
| Generate an educational image using AI. | |
| Args: | |
| description: What to visualize in the image | |
| style: Style of the image | |
| context: Additional learning context | |
| Returns: | |
| Base64 encoded image data or error message | |
| """ | |
| result = await generate_educational_image( | |
| description=description, | |
| style=style, | |
| context=context if context else None, | |
| ) | |
| if "error" in result: | |
| return f"ERROR: {result['error']}" | |
| image_data = result.get("image_data", "") | |
| mime_type = result.get("mime_type", "image/png") | |
| return f"data:{mime_type};base64,{image_data}" | |
| async def visualize_concept( | |
| concept: str, | |
| level: Literal["beginner", "intermediate", "advanced"] = "intermediate", | |
| ) -> str: | |
| """ | |
| Generate a visualization for a learning concept. | |
| Args: | |
| concept: The concept to visualize | |
| level: Explanation level (beginner, intermediate, advanced) | |
| Returns: | |
| Base64 encoded image data URL or error message | |
| """ | |
| result = await generate_concept_visualization( | |
| concept=concept, | |
| explanation_level=level, | |
| ) | |
| if "error" in result: | |
| return f"ERROR: {result['error']}" | |
| image_data = result.get("image_data", "") | |
| mime_type = result.get("mime_type", "image/png") | |
| return f"data:{mime_type};base64,{image_data}" | |