-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathapp.py
More file actions
153 lines (134 loc) · 5.04 KB
/
app.py
File metadata and controls
153 lines (134 loc) · 5.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import asyncio
import streamlit as st
from semantic_kernel.contents.chat_message_content import ChatMessageContent
from semantic_kernel.contents.utils.author_role import AuthorRole
from src.mas import Orchestrator, MultiAgent
st.set_page_config(
page_title="AI Multi-Agent Presentation Builder",
page_icon=":robot_face:",
layout="wide"
)
# Enhanced CSS for a more vibrant design
st.markdown(
"""
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap');
body {
font-family: 'Poppins', sans-serif;
background: linear-gradient(-45deg, #f9d423, #ff4e50, #ff6f61, #ffa69e);
background-size: 400% 400%;
animation: gradientBG 15s ease infinite;
margin: 0;
padding: 0;
}
@keyframes gradientBG {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}
.reportview-container, .main .block-container {
background: transparent;
color: #333;
}
.sidebar .sidebar-content {
background: rgba(255,255,255,0.95);
border-radius: 10px;
padding: 1em;
}
.stButton>button {
background-color: #ff4e50;
color: #fff;
border: none;
border-radius: 10px;
font-size: 1em;
padding: 0.6em 1em;
margin-top: 1em;
transition: 0.3s;
box-shadow: 0 4px 15px rgba(255, 78, 80, 0.3);
}
.stButton>button:hover {
background-color: #f9d423;
color: #333;
box-shadow: 0 6px 20px rgba(249, 212, 35, 0.3);
}
h1, h2, h3 {
color: #fff;
text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}
</style>
""",
unsafe_allow_html=True
)
async def run(user_input, num_agents):
orchestrator = Orchestrator(user_input, num_agents)
dynamic_agents = orchestrator.run()
mas = MultiAgent()
expert_agents = mas.create_agents(dynamic_agents)
expert_agents_names = [agent.name for agent in expert_agents]
return expert_agents, expert_agents_names, mas
async def main(user_input, num_agents, max_interactions=10):
expert_agents, expert_agents_names, mas = await run(user_input, num_agents)
with st.sidebar:
st.title("Expert Agents")
agent_placeholders = {name: st.empty() for name in expert_agents_names}
for agent_name in expert_agents_names:
agent_placeholders[agent_name].info(agent_name)
await asyncio.sleep(2)
selection_function = mas.create_selection_function(expert_agents_names)
termination_keyword = 'yes'
termination_function = mas.create_termination_function(termination_keyword)
group = mas.create_chat_group(
expert_agents,
selection_function,
termination_function,
termination_keyword
)
interactions: int = 0
is_complete: bool = False
with st.spinner("Generating presentation..."):
while not is_complete and interactions < max_interactions:
await group.add_chat_message(ChatMessageContent(role=AuthorRole.USER, content=user_input))
interactions += 1
async for response in group.invoke():
agent_name = response.name
if agent_name in agent_placeholders:
agent_placeholders[agent_name].warning(agent_name)
await asyncio.sleep(3) # Highlight duration
agent_placeholders[agent_name].info(agent_name)
st.markdown(f"**{response.role} - {response.name or '*'}**")
st.info(response.content)
if group.is_complete:
st.success("Conversation completed!")
st.download_button(
"Download Presentation",
data=open("presentation.pptx", "rb").read(),
file_name="presentation.pptx",
mime="application/vnd.openxmlformats-officedocument.presentationml.presentation"
)
break
def app():
st.title(":robot_face: AI Multi-Agent Draft Presentation Builder :robot_face:")
st.subheader("Create draft presentations with AI experts")
col = st.columns([1, 1, 1])[0]
user_input = col.text_input(
"Enter the theme:",
max_chars=150,
help="Provide the main theme for your presentation.",
placeholder="e.g., Artificial Intelligence in Healthcare"
)
if user_input:
st.success("Theme received!")
col = st.columns([1, 2, 1])[0]
with col:
num_agents = st.slider("Number of agents", min_value=2, max_value=5, value=4)
if 'run_button' in st.session_state and st.session_state.run_button == True:
st.session_state.running = True
else:
st.session_state.running = False
if st.button('Create a draft Presentation', disabled=st.session_state.running, key='run_button'):
if user_input:
asyncio.run(main(user_input, num_agents))
else:
st.warning("Please enter a theme!")
if __name__ == "__main__":
app()