Spaces:
Sleeping
Sleeping
File size: 7,785 Bytes
b93bbdb b860c6b b93bbdb 52871a6 b93bbdb 52871a6 b93bbdb 52871a6 b93bbdb 52871a6 b93bbdb 52871a6 b93bbdb 52871a6 b93bbdb | 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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 | import streamlit as st
from core.coordinator import Coordinator
import os
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Page Configuration
st.set_page_config(
page_title="AI Multi-Agent System",
page_icon="⚡",
layout="wide",
)
# --- ADVANCED UI STYLING (Full Page Dark Theme & White Text) ---
st.markdown("""
<style>
/* Full Page Background */
[data-testid="stAppViewContainer"], [data-testid="stHeader"], [data-testid="stSidebar"], .stApp {
background-color: #0d1117 !important;
color: #ffffff !important;
}
/* Ensure no white margins/borders */
[data-testid="stMainViewContainer"] {
background-color: #0d1117 !important;
}
/* Force all text to white */
html, body, [data-testid="stMarkdownContainer"] p, span, div, label {
color: #ffffff !important;
font-family: 'Inter', sans-serif;
}
/* Bottom block and Chat input styling */
[data-testid="stBottomBlockContainer"], [data-testid="stChatInput"], [data-testid="stChatInputTextArea"] {
background-color: #0d1117 !important;
color: #ffffff !important;
}
/* Target the actual textarea inside the wrapper */
[data-testid="stChatInputTextArea"] {
background-color: #161b22 !important;
color: #ffffff !important;
-webkit-text-fill-color: #ffffff !important;
border: 1px solid #30363d !important;
}
/* Ensure writing color is white regardless of focus or browser state */
[data-testid="stChatInputTextArea"] textarea {
color: #ffffff !important;
-webkit-text-fill-color: #ffffff !important;
}
/* Ensure the outer wrapper of the input is also dark */
.stChatInput {
background-color: transparent !important;
}
/* Target the specific Emotion Cache classes for the input area if needed */
div[class*="st-emotion-cache"] {
/* We use a broad selector but limit it to bottom containers to avoid breaking other things */
}
[data-testid="stBottomBlockContainer"] {
background-color: #0d1117 !important;
border-top: 1px solid #30363d !important;
}
/* Status and Progress styling (Agent Buttons) */
.stStatusWidget, [data-testid="stStatusWidget"], [data-testid="stStatusWidget"] summary {
background-color: #000000 !important;
color: #ffffff !important;
border: 1px solid #30363d !important;
transition: background-color 0.3s ease !important;
}
/* Hover effect: Grey background */
.stStatusWidget:hover, [data-testid="stStatusWidget"]:hover, [data-testid="stStatusWidget"] summary:hover {
background-color: #30363d !important;
cursor: pointer !important;
}
/* Ensure text inside status remains white */
.stStatusWidget div, .stStatusWidget span, .stStatusWidget p {
color: #ffffff !important;
}
/* Code block styling (Black text on Light background for visibility) */
code, pre, [data-testid="stCodeBlock"] code {
background-color: #f0f2f6 !important;
color: #000000 !important;
-webkit-text-fill-color: #000000 !important;
border-radius: 5px !important;
padding: 10px !important;
font-weight: 500 !important;
}
/* Target the syntax highlighting tokens to also be dark/visible */
.token {
color: #000000 !important;
}
/* Final Summary Box */
.stInfo {
background-color: #161b22 !important;
border: 1px solid #238636 !important;
color: white !important;
}
/* Custom Scrollbar for modern look */
::-webkit-scrollbar {
width: 10px;
background: #0d1117;
}
::-webkit-scrollbar-thumb {
background: #30363d;
border-radius: 5px;
}
</style>
""", unsafe_allow_html=True)
def main():
st.title("⚡ AI Multi-Agent Dashboard")
st.markdown("---")
# Initialize chat history
if "messages" not in st.session_state:
st.session_state.messages = []
# Sidebar
with st.sidebar:
st.header("🚀 Project Overview")
st.markdown("""
**AI Multi-Agent System** is an advanced platform where specialized AI agents work together to solve complex tasks.
The system works in 3 easy steps:
1. **Research** 🔍: Finds detailed information.
2. **Coding** 💻: Writes Python code solutions.
3. **Summary** 📝: Explains everything clearly.
It is designed to make research and coding simple and fast for everyone.
""")
st.markdown("---")
st.header("🛠️ System Control")
st.write("Active Agents:")
st.markdown("- 🔍 **Research Agent**")
st.markdown("- 💻 **Coding Agent**")
st.markdown("- 📝 **Summarizer Agent**")
st.markdown("---")
if st.button("🗑️ Clear History"):
st.session_state.messages = []
st.rerun()
# Display chat messages from history
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
# React to user input
if prompt := st.chat_input("Enter your task here..."):
# 1. Immediately show user message
with st.chat_message("user"):
st.markdown(prompt)
# 2. Save to history
st.session_state.messages.append({"role": "user", "content": prompt})
coordinator = Coordinator()
# 3. Process with Agents
with st.chat_message("assistant"):
try:
# --- Step 1: Research ---
with st.status("🔍 **Research Agent** is exploring...", expanded=True) as status:
research = coordinator.research_agent.think(prompt)
status.update(label="✅ Research Complete", state="complete", expanded=False)
# Show research results outside status
st.markdown("### 🔍 Research Results")
st.markdown(research)
# --- Step 2: Coding ---
with st.status("💻 **Coding Agent** is building...", expanded=True) as status:
coding_prompt = f"Based on this research:\n{research}"
code = coordinator.coding_agent.think(coding_prompt)
status.update(label="✅ Code Generated", state="complete", expanded=False)
# Show code results outside status
st.markdown("### 💻 Generated Solution")
st.code(code, language='python')
# --- Step 3: Summary ---
with st.status("📝 **Summarizer Agent** is finishing...", expanded=True) as status:
summary_prompt = f"Summarize the following research and code:\n\nRESEARCH:\n{research}\n\nCODE:\n{code}"
summary = coordinator.summarizer_agent.think(summary_prompt)
status.update(label="✅ Task Finished", state="complete", expanded=False)
# --- Final Result Display ---
st.markdown("### 🏁 Final Summary")
st.info(summary)
# Save assistant response to history
st.session_state.messages.append({"role": "assistant", "content": summary})
except Exception as e:
st.error(f"❌ Error: {str(e)}")
if __name__ == "__main__":
main()
|