Skip to content

Commit 455a897

Browse files
committed
cleanup streamlit examples
1 parent 51f90a9 commit 455a897

23 files changed

+252
-111
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
# caution: path[0] is reserved for script path (or '' in REPL)
44

55
# import your demo here
6-
sys.path.insert(1, '../movie-production')
7-
sys.path.insert(1, '../travel-planner')
6+
sys.path.insert(1, './movie-production')
7+
sys.path.insert(1, './travel-planner')

examples/python/main-app.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import imports
2+
import streamlit as st
3+
4+
st.set_page_config(
5+
page_title="AWS Multi-Agent Orchestrator Demos",
6+
page_icon="👋",
7+
)
8+
9+
pg = st.navigation(
10+
[
11+
st.Page("pages/home.py", title="Home", icon="🏠"),
12+
st.Page("movie-production/movie-production-demo.py", title="AI Movie Production Demo" ,icon="🎬"),
13+
st.Page("travel-planner/travel-planner-demo.py", title="AI Travel Planner Demo" ,icon="✈️"),
14+
])
15+
pg.run()

examples/movie-production/movie-production-demo.py renamed to examples/python/movie-production/movie-production-demo.py

Lines changed: 58 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import asyncio
33
import streamlit as st
44
import os
5-
from search_web import tool_handler
5+
import boto3
6+
from botocore.exceptions import NoRegionError, NoCredentialsError, PartialCredentialsError
7+
from search_web import tool_handler
68
from tool import Tool
79
from multi_agent_orchestrator.orchestrator import MultiAgentOrchestrator, OrchestratorConfig
810
from multi_agent_orchestrator.agents import (
@@ -14,21 +16,40 @@
1416
from multi_agent_orchestrator.classifiers import ClassifierResult
1517
from supervisor_agent import SupervisorAgent, SupervisorAgentOptions
1618

19+
# Function to test AWS connection
20+
def test_aws_connection():
21+
"""Test the AWS connection and return a status message."""
22+
try:
23+
# Attempt to create an S3 client as a test
24+
boto3.client('s3').list_buckets()
25+
return True
26+
except Exception as e:
27+
print(f"Incomplete AWS credentials. Please check your AWS configuration.")
28+
29+
return False
30+
1731
# Set up the Streamlit app
1832
st.title("AI Movie Production Demo 🎬")
19-
st.caption("Bring your movie ideas to life with the teams of script writing and casting AI agents")
33+
st.caption("Bring your movie ideas to life with AI Movie Production by collaborating with AI agents powered by Anthropic's Claude for script writing and casting.")
2034

35+
# Check AWS connection
36+
if not test_aws_connection():
37+
st.error("AWS connection failed. Please check your AWS credentials and region configuration.")
38+
st.warning("Visit the AWS documentation for guidance on setting up your credentials and region.")
39+
st.stop()
2140

41+
# Define the tools
2242
search_web_tool = Tool(name='search_web',
23-
description='Search Web for information',
24-
properties={
25-
'query': {
26-
'type': 'string',
27-
'description': 'The search query'
28-
}
29-
},
30-
required=['query'])
31-
43+
description='Search Web for information',
44+
properties={
45+
'query': {
46+
'type': 'string',
47+
'description': 'The search query'
48+
}
49+
},
50+
required=['query'])
51+
52+
# Define the agents
3253
script_writer_agent = BedrockLLMAgent(BedrockLLMAgentOptions(
3354
model_id='us.anthropic.claude-3-sonnet-20240229-v1:0',
3455
name="ScriptWriterAgent",
@@ -37,10 +58,11 @@
3758
develop a compelling script outline with character descriptions and key plot points.
3859
3960
Your tasks consist of:
40-
1. Write a script outline with 3-5 main characters and key plot points
61+
1. Write a script outline with 3-5 main characters and key plot points.
4162
2. Outline the three-act structure and suggest 2-3 twists.
42-
3. Ensure the script aligns with the specified genre and target audience
43-
"""))
63+
3. Ensure the script aligns with the specified genre and target audience.
64+
"""
65+
))
4466

4567
casting_director_agent = BedrockLLMAgent(BedrockLLMAgentOptions(
4668
model_id='anthropic.claude-3-haiku-20240307-v1:0',
@@ -51,24 +73,23 @@
5173
5274
Your tasks consist of:
5375
1. Suggest 1-2 actors for each main role.
54-
2. Check actors' current status using search_web tool
76+
2. Check actors' current status using the search_web tool.
5577
3. Provide a brief explanation for each casting suggestion.
5678
4. Consider diversity and representation in your casting choices.
57-
5. Provide a final response with all the actors you suggest for the main roles
79+
5. Provide a final response with all the actors you suggest for the main roles.
5880
""",
59-
60-
tool_config={
61-
'tool': [search_web_tool.to_bedrock_format()],
62-
'toolMaxRecursions': 20,
63-
'useToolHandler': tool_handler
81+
tool_config={
82+
'tool': [search_web_tool.to_bedrock_format()],
83+
'toolMaxRecursions': 20,
84+
'useToolHandler': tool_handler
6485
},
6586
save_chat=False
6687
))
6788

6889
movie_producer_supervisor = BedrockLLMAgent(BedrockLLMAgentOptions(
6990
model_id='us.anthropic.claude-3-5-sonnet-20241022-v2:0',
7091
name='MovieProducerAgent',
71-
description="""
92+
description="""\
7293
Experienced movie producer overseeing script and casting.
7394
7495
Your tasks consist of:
@@ -77,7 +98,7 @@
7798
3. Summarize the script outline and casting suggestions.
7899
4. Provide a concise movie concept overview.
79100
5. Make sure to respond with a markdown format without mentioning it.
80-
""",
101+
"""
81102
))
82103

83104
supervisor = SupervisorAgent(SupervisorAgentOptions(
@@ -86,25 +107,23 @@
86107
trace=True
87108
))
88109

110+
# Define async function for handling requests
111+
async def handle_request(_orchestrator: MultiAgentOrchestrator, _user_input: str, _user_id: str, _session_id: str):
112+
classifier_result = ClassifierResult(selected_agent=supervisor, confidence=1.0)
89113

90-
91-
async def handle_request(_orchestrator: MultiAgentOrchestrator, _user_input:str, _user_id:str, _session_id:str):
92-
classifier_result=ClassifierResult(selected_agent=supervisor, confidence=1.0)
93-
94-
response:AgentResponse = await _orchestrator.agent_process_request(_user_input, _user_id, _session_id, classifier_result)
114+
response: AgentResponse = await _orchestrator.agent_process_request(_user_input, _user_id, _session_id, classifier_result)
95115

96116
# Print metadata
97117
print("\nMetadata:")
98118
print(f"Selected Agent: {response.metadata.agent_name}")
99119
if isinstance(response, AgentResponse) and response.streaming is False:
100120
# Handle regular response
101121
if isinstance(response.output, str):
102-
return (response.output)
122+
return response.output
103123
elif isinstance(response.output, ConversationMessage):
104-
return (response.output.content[0].get('text'))
105-
124+
return response.output.content[0].get('text')
106125

107-
# Initialize the orchestrator with some options
126+
# Initialize the orchestrator
108127
orchestrator = MultiAgentOrchestrator(options=OrchestratorConfig(
109128
LOG_AGENT_CHAT=True,
110129
LOG_CLASSIFIER_CHAT=True,
@@ -119,12 +138,10 @@ async def handle_request(_orchestrator: MultiAgentOrchestrator, _user_input:str,
119138
USER_ID = str(uuid.uuid4())
120139
SESSION_ID = str(uuid.uuid4())
121140

122-
# Input field for the report query
141+
# Input fields for the movie concept
123142
movie_idea = st.text_area("Describe your movie idea in a few sentences:")
124-
genre = st.selectbox("Select the movie genre:",
125-
["Action", "Comedy", "Drama", "Sci-Fi", "Horror", "Romance", "Thriller"])
126-
target_audience = st.selectbox("Select the target audience:",
127-
["General", "Children", "Teenagers", "Adults", "Mature"])
143+
genre = st.selectbox("Select the movie genre:", ["Action", "Comedy", "Drama", "Sci-Fi", "Horror", "Romance", "Thriller"])
144+
target_audience = st.selectbox("Select the target audience:", ["General", "Children", "Teenagers", "Adults", "Mature"])
128145
estimated_runtime = st.slider("Estimated runtime (in minutes):", 30, 180, 120)
129146

130147
# Process the movie concept
@@ -134,6 +151,7 @@ async def handle_request(_orchestrator: MultiAgentOrchestrator, _user_input:str,
134151
f"Movie idea: {movie_idea}, Genre: {genre}, "
135152
f"Target audience: {target_audience}, Estimated runtime: {estimated_runtime} minutes"
136153
)
137-
# Get the response from the assistant
138-
response = asyncio.run(handle_request(orchestrator, input_text, USER_ID, SESSION_ID))
139-
st.write(response)
154+
loop = asyncio.new_event_loop()
155+
asyncio.set_event_loop(loop)
156+
response = loop.run_until_complete(handle_request(orchestrator, input_text, USER_ID, SESSION_ID))
157+
st.write(response)

examples/movie-production/movie-production-result.png renamed to examples/python/movie-production/movie-production-result.png

File renamed without changes.
File renamed without changes.

examples/movie-production/readme.md renamed to examples/python/movie-production/readme.md

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,21 @@
11
## 🎬 AI Movie Production Agent
2-
This Streamlit app is an AI-powered movie production assistant that helps bring your movie ideas to life using Claude 3 on Amazon BedrocK. It automates the process of script writing and casting, allowing you to create compelling movie concepts with ease.
3-
### streamlit app
4-
Here is a screenshot of the streamlit app. You can describe your movie, select a movie genre, audience and duration and hit `Develop Movie Concept`
2+
This Streamlit app is an AI-powered movie production assistant that helps bring your movie ideas to life using Claude 3 on Amazon Bedrock. It automates the process of script writing and casting, allowing you to create compelling movie concepts with ease.
53

4+
### Streamlit App
5+
Here is a screenshot of the streamlit app. You can describe your movie, select a movie genre, audience and duration and hit `Develop Movie Concept`
66
![image](./movie-production.png)
77

8-
After a few seconds you should have a your movie ready! 🍿 🎬
9-
8+
After a few seconds you should have your movie ready! 🍿 🎬
109
![image](./movie-production-result.png)
1110

1211
### Features
1312
- Generates script outlines based on your movie idea, genre, and target audience
1413
- Suggests suitable actors for main roles, considering their past performances and current availability
1514
- Provides a concise movie concept overview
1615

17-
### How to get Started?
18-
19-
1. Clone the GitHub repository
20-
21-
```bash
22-
git clone https://github.com/awslabs/multi-agent-orchestrator.git
23-
```
24-
2. Install the required dependencies:
25-
26-
```bash
27-
cd examples/movie-production
28-
pip install -r requirements.txt
29-
```
30-
3. Get your AWS Credentials
16+
### How to Get Started?
3117

32-
4. Run the Streamlit App
33-
```bash
34-
streamlit run movie-production-demo.py
35-
```
18+
Check out the [demos README](../README.md) for installation and setup instructions.
3619

3720
### How it Works?
3821

File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)