-
-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #355 from MervinPraison/develop
Add Image Generation AI Agents with Async Support
- Loading branch information
Showing
45 changed files
with
1,295 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.