Skip to content

Commit

Permalink
Merge pull request #355 from MervinPraison/develop
Browse files Browse the repository at this point in the history
Add Image Generation AI Agents with Async Support
  • Loading branch information
MervinPraison authored Jan 31, 2025
2 parents e45b844 + 2ab8ea0 commit 747aa08
Show file tree
Hide file tree
Showing 45 changed files with 1,295 additions and 72 deletions.
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM python:3.11-slim
WORKDIR /app
COPY . .
RUN pip install flask praisonai==2.0.60 gunicorn markdown
RUN pip install flask praisonai==2.0.61 gunicorn markdown
EXPOSE 8080
CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]
2 changes: 1 addition & 1 deletion docs/api/praisonai/deploy.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ <h2 id="raises">Raises</h2>
file.write(&#34;FROM python:3.11-slim\n&#34;)
file.write(&#34;WORKDIR /app\n&#34;)
file.write(&#34;COPY . .\n&#34;)
file.write(&#34;RUN pip install flask praisonai==2.0.60 gunicorn markdown\n&#34;)
file.write(&#34;RUN pip install flask praisonai==2.0.61 gunicorn markdown\n&#34;)
file.write(&#34;EXPOSE 8080\n&#34;)
file.write(&#39;CMD [&#34;gunicorn&#34;, &#34;-b&#34;, &#34;0.0.0.0:8080&#34;, &#34;api:app&#34;]\n&#39;)

Expand Down
126 changes: 126 additions & 0 deletions docs/features/image-generation.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
title: "Image Generation AI Agents"
sidebarTitle: "Image Generation"
description: "Generate high-quality images using PraisonAI Image Agents with both synchronous and asynchronous capabilities."
icon: "image"
---

```mermaid
flowchart LR
In[Start] --> Process[Image Description]
Process --> Agent[Image Agent]
Agent --> Out[Image URL]
style In fill:#8B0000,color:#fff
style Process fill:#2E8B57,color:#fff
style Agent fill:#2E8B57,color:#fff
style Out fill:#8B0000,color:#fff
```

Image Generation in PraisonAI allows you to create high-quality images using natural language descriptions. The Image Agent supports both synchronous and asynchronous operations, making it flexible for various use cases.

## Quick Start

<Tabs>
<Tab title="Code">
<Steps>
<Step title="Install Package">
First, install the PraisonAI Agents package with LLM support:
```bash
pip install "praisonaiagents[llm]"
```
</Step>

<Step title="Set API Key">
Set your OpenAI API key as an environment variable:
```bash
export OPENAI_API_KEY=your_api_key_here
```
</Step>

<Step title="Create Agent">
Create a new file `image_gen.py` with the basic setup:
```python
from praisonaiagents.agent.image_agent import ImageAgent

# Create an image agent
agent = ImageAgent(
llm="dall-e-3",
verbose=True
)

# Generate an image
result = agent.chat("A cute baby sea otter playing with a laptop")
print("Image generation result:", result)
```
</Step>
</Steps>
</Tab>

<Tab title="Async">
<Steps>
<Step title="Install Package">
First, install the PraisonAI Agents package with LLM support:
```bash
pip install "praisonaiagents[llm]"
```
</Step>

<Step title="Set API Key">
Set your OpenAI API key as an environment variable:
```bash
export OPENAI_API_KEY=your_api_key_here
```
</Step>

<Step title="Create Async Agent">
Create a new file `image_gen_async.py` with the async setup:
```python
import asyncio
from praisonaiagents import ImageAgent

async def main():
agent = ImageAgent(
name="ImageCreator",
llm="dall-e-3",
style="natural"
)

result = await agent.achat("A cute baby sea otter playing with a laptop")
print(f"Image generation result: {result}")

if __name__ == "__main__":
asyncio.run(main())
```
</Step>
</Steps>
</Tab>
</Tabs>

## Features

<CardGroup cols={2}>
<Card title="DALL-E Integration" icon="image">
Seamless integration with DALL-E for high-quality image generation.
</Card>
<Card title="Async Support" icon="bolt">
Asynchronous operations for better performance in concurrent environments.
</Card>
<Card title="Natural Style" icon="paintbrush">
Generate images with natural, realistic styling options.
</Card>
<Card title="Verbose Mode" icon="message">
Detailed output logging for better debugging and monitoring.
</Card>
</CardGroup>

## Next Steps

<CardGroup>
<Card title="Agents Overview" icon="robot" href="/agents">
Learn more about PraisonAI Agents and their capabilities
</Card>
<Card title="API Reference" icon="code" href="/api-reference">
View the complete API documentation
</Card>
</CardGroup>
1 change: 1 addition & 0 deletions docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"group": "Features",
"pages": [
"features/autoagents",
"features/image-generation",
"features/selfreflection",
"features/rag",
"features/reasoning-extract",
Expand Down
15 changes: 15 additions & 0 deletions examples/image/image-agent-async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import asyncio
from praisonaiagents import ImageAgent

async def main():
agent = ImageAgent(
name="ImageCreator",
llm="dall-e-3",
style="natural"
)

result = await agent.achat("A cute baby sea otter playing with a laptop")
print(f"Image generation result: {result}")

if __name__ == "__main__":
asyncio.run(main())
8 changes: 8 additions & 0 deletions examples/image/image-agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from praisonaiagents.agent.image_agent import ImageAgent

# Create an image agent with normal mode
agent = ImageAgent(llm="dall-e-3")

# Generate an image
result = agent.chat("A cute baby sea otter playing with a laptop")
print("Image generation result:", result)
2 changes: 1 addition & 1 deletion praisonai.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Praisonai < Formula

desc "AI tools for various AI applications"
homepage "https://github.com/MervinPraison/PraisonAI"
url "https://github.com/MervinPraison/PraisonAI/archive/refs/tags/2.0.60.tar.gz"
url "https://github.com/MervinPraison/PraisonAI/archive/refs/tags/2.0.61.tar.gz"
sha256 "1828fb9227d10f991522c3f24f061943a254b667196b40b1a3e4a54a8d30ce32" # Replace with actual SHA256 checksum
license "MIT"

Expand Down
2 changes: 1 addition & 1 deletion praisonai/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def create_dockerfile(self):
file.write("FROM python:3.11-slim\n")
file.write("WORKDIR /app\n")
file.write("COPY . .\n")
file.write("RUN pip install flask praisonai==2.0.60 gunicorn markdown\n")
file.write("RUN pip install flask praisonai==2.0.61 gunicorn markdown\n")
file.write("EXPOSE 8080\n")
file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n')

Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "PraisonAI"
version = "2.0.60"
version = "2.0.61"
description = "PraisonAI is an AI Agents Framework with Self Reflection. PraisonAI application combines PraisonAI Agents, AutoGen, and CrewAI into a low-code solution for building and managing multi-agent LLM systems, focusing on simplicity, customisation, and efficient human-agent collaboration."
readme = "README.md"
license = ""
Expand All @@ -12,7 +12,7 @@ dependencies = [
"rich>=13.7",
"markdown>=3.5",
"pyparsing>=3.0.0",
"praisonaiagents>=0.0.60",
"praisonaiagents>=0.0.61",
"python-dotenv>=0.19.0",
"instructor>=1.3.3",
"PyYAML>=6.0",
Expand Down Expand Up @@ -84,7 +84,7 @@ autogen = ["pyautogen>=0.2.19", "praisonai-tools>=0.0.7", "crewai"]

[tool.poetry]
name = "PraisonAI"
version = "2.0.60"
version = "2.0.61"
description = "PraisonAI is an AI Agents Framework with Self Reflection. PraisonAI application combines PraisonAI Agents, AutoGen, and CrewAI into a low-code solution for building and managing multi-agent LLM systems, focusing on simplicity, customisation, and efficient human–agent collaboration."
authors = ["Mervin Praison"]
license = ""
Expand All @@ -102,7 +102,7 @@ python = ">=3.10,<3.13"
rich = ">=13.7"
markdown = ">=3.5"
pyparsing = ">=3.0.0"
praisonaiagents = ">=0.0.60"
praisonaiagents = ">=0.0.61"
python-dotenv = ">=0.19.0"
instructor = ">=1.3.3"
PyYAML = ">=6.0"
Expand Down
15 changes: 15 additions & 0 deletions src/praisonai-agents/image-agent-async.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import asyncio
from praisonaiagents import ImageAgent

async def main():
agent = ImageAgent(
name="ImageCreator",
llm="dall-e-3",
style="natural"
)

result = await agent.achat("A cute baby sea otter playing with a laptop")
print(f"Image generation result: {result}")

if __name__ == "__main__":
asyncio.run(main())
51 changes: 6 additions & 45 deletions src/praisonai-agents/image-agent.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,8 @@
from praisonaiagents import Agent, Tools
from praisonaiagents.tools import duckduckgo
from praisonaiagents.agent.image_agent import ImageAgent

agent = Agent(instructions="You are a Image Analysis Agent", tools=[duckduckgo])
agent.start("I want to go London next week, find me a good hotel and flight")
# Create an image agent with normal mode
agent = ImageAgent(llm="dall-e-3")

from praisonaiagents import Agent, Task, PraisonAIAgents

# Create Image Analysis Agent
image_agent = Agent(
name="ImageAnalyst",
role="Image Analysis Specialist",
goal="Analyze images and videos to extract meaningful information",
backstory="""You are an expert in computer vision and image analysis.
You excel at describing images, detecting objects, and understanding visual content.""",
llm="gpt-4o-mini",
self_reflect=False
)

# 1. Task with Image URL
task1 = Task(
name="analyze_landmark",
description="Describe this famous landmark and its architectural features.",
expected_output="Detailed description of the landmark's architecture and significance",
agent=image_agent,
images=["https://upload.wikimedia.org/wikipedia/commons/b/bf/Krakow_-_Kosciol_Mariacki.jpg"]
)

# 2. Task with Local Image File
task2 = Task(
name="analyze_local_image",
description="What objects can you see in this image? Describe their arrangement.",
expected_output="Detailed description of objects and their spatial relationships",
agent=image_agent,
images=["image.jpg"]
)

# Create PraisonAIAgents instance
agents = PraisonAIAgents(
agents=[image_agent],
tasks=[task1, task2],
process="sequential",
verbose=1
)

# Run all tasks
agents.start()
# Generate an image
result = agent.chat("A cute baby sea otter playing with a laptop")
print("Image generation result:", result)
47 changes: 47 additions & 0 deletions src/praisonai-agents/image-understanding-agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from praisonaiagents import Agent, Tools
from praisonaiagents.tools import duckduckgo

agent = Agent(instructions="You are a Image Analysis Agent", tools=[duckduckgo])
agent.start("I want to go London next week, find me a good hotel and flight")

from praisonaiagents import Agent, Task, PraisonAIAgents

# Create Image Analysis Agent
image_agent = Agent(
name="ImageAnalyst",
role="Image Analysis Specialist",
goal="Analyze images and videos to extract meaningful information",
backstory="""You are an expert in computer vision and image analysis.
You excel at describing images, detecting objects, and understanding visual content.""",
llm="gpt-4o-mini",
self_reflect=False
)

# 1. Task with Image URL
task1 = Task(
name="analyze_landmark",
description="Describe this famous landmark and its architectural features.",
expected_output="Detailed description of the landmark's architecture and significance",
agent=image_agent,
images=["https://upload.wikimedia.org/wikipedia/commons/b/bf/Krakow_-_Kosciol_Mariacki.jpg"]
)

# 2. Task with Local Image File
task2 = Task(
name="analyze_local_image",
description="What objects can you see in this image? Describe their arrangement.",
expected_output="Detailed description of objects and their spatial relationships",
agent=image_agent,
images=["image.jpg"]
)

# Create PraisonAIAgents instance
agents = PraisonAIAgents(
agents=[image_agent],
tasks=[task1, task2],
process="sequential",
verbose=1
)

# Run all tasks
agents.start()
2 changes: 2 additions & 0 deletions src/praisonai-agents/praisonaiagents/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from .agent.agent import Agent
from .agent.image_agent import ImageAgent
from .agents.agents import PraisonAIAgents
from .task.task import Task
from .tools.tools import Tools
Expand Down Expand Up @@ -30,6 +31,7 @@

__all__ = [
'Agent',
'ImageAgent',
'PraisonAIAgents',
'Agents',
'Tools',
Expand Down
3 changes: 2 additions & 1 deletion src/praisonai-agents/praisonaiagents/agent/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Agent module for AI agents"""
from .agent import Agent
from .image_agent import ImageAgent

__all__ = ['Agent']
__all__ = ['Agent', 'ImageAgent']
1 change: 0 additions & 1 deletion src/praisonai-agents/praisonaiagents/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
display_self_reflection,
ReflectionOutput,
client,
error_logs,
adisplay_instruction
)
import inspect
Expand Down
Loading

0 comments on commit 747aa08

Please sign in to comment.