Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +55 -40
src/streamlit_app.py
CHANGED
|
@@ -1,41 +1,52 @@
|
|
| 1 |
-
# import phase
|
| 2 |
-
import streamlit as st
|
| 3 |
-
from pydantic import BaseModel, Field
|
| 4 |
from typing import List, Literal, Dict, Optional
|
| 5 |
from agency_swarm import Agent, Agency, set_openai_key, BaseTool
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
class
|
| 8 |
-
project_name: str = Field(..., description
|
| 9 |
-
project_description: str = Field(..., description
|
| 10 |
-
project_type: Literal["Web Application", "Mobile App", "API Development",
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
class ToolConfig:
|
| 14 |
name = "analyze_project"
|
| 15 |
-
description = "
|
| 16 |
one_call_at_a_time = True
|
| 17 |
|
| 18 |
def run(self) -> str:
|
| 19 |
-
"""
|
| 20 |
if self._shared_state.get("project_analysis", None) is not None:
|
| 21 |
-
raise ValueError(
|
| 22 |
-
|
| 23 |
analysis = {
|
| 24 |
"name": self.project_name,
|
| 25 |
"type": self.project_type,
|
| 26 |
"complexity": "high",
|
| 27 |
"timeline": "6 months",
|
| 28 |
"budget_feasibility": "within range",
|
| 29 |
-
"requirements": ["Scalable
|
| 30 |
}
|
| 31 |
-
|
| 32 |
self._shared_state.set("project_analysis", analysis)
|
| 33 |
-
return "Project analysis completed. Please proceed with technical specification"
|
| 34 |
|
| 35 |
class CreateTechnicalSpecification(BaseTool):
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
class ToolConfig:
|
| 41 |
name = "create_technical_spec"
|
|
@@ -43,47 +54,51 @@ class CreateTechnicalSpecification(BaseTool):
|
|
| 43 |
one_call_at_a_time = True
|
| 44 |
|
| 45 |
def run(self) -> str:
|
| 46 |
-
"""
|
| 47 |
project_analysis = self._shared_state.get("project_analysis", None)
|
| 48 |
if project_analysis is None:
|
| 49 |
-
raise ValueError("Please
|
| 50 |
-
|
| 51 |
-
spec ={
|
| 52 |
-
"project_name"
|
| 53 |
"architecture": self.architecture_type,
|
| 54 |
-
"technologies": self.core_technologies.split(","),
|
| 55 |
-
"scalability": self.
|
| 56 |
}
|
|
|
|
| 57 |
self._shared_state.set("technical_specification", spec)
|
| 58 |
-
return f"Technical
|
| 59 |
|
| 60 |
def init_session_state() -> None:
|
| 61 |
-
"""
|
| 62 |
-
if
|
| 63 |
-
st.session_state.
|
| 64 |
-
if
|
| 65 |
st.session_state.api_key = None
|
| 66 |
|
| 67 |
-
|
| 68 |
def main() -> None:
|
| 69 |
-
st.set_page_config(page_title
|
| 70 |
init_session_state()
|
| 71 |
-
|
| 72 |
-
st.title("
|
| 73 |
-
|
| 74 |
# API Configuration
|
| 75 |
with st.sidebar:
|
| 76 |
-
st.header("API Configuration")
|
| 77 |
openai_api_key = st.text_input(
|
| 78 |
"OpenAI API Key",
|
| 79 |
-
type
|
| 80 |
-
help
|
| 81 |
)
|
| 82 |
|
| 83 |
if openai_api_key:
|
| 84 |
st.session_state.api_key = openai_api_key
|
| 85 |
-
st.success("API Key accepted")
|
| 86 |
else:
|
| 87 |
-
st.warning("⚠️
|
| 88 |
st.markdown("[Get your API key here](https://platform.openai.com/api-keys)")
|
| 89 |
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from typing import List, Literal, Dict, Optional
|
| 2 |
from agency_swarm import Agent, Agency, set_openai_key, BaseTool
|
| 3 |
+
from pydantic import Field, BaseModel
|
| 4 |
+
import streamlit as st
|
| 5 |
|
| 6 |
+
class AnalyzeProjectRequirements(BaseTool):
|
| 7 |
+
project_name: str = Field(..., description="Name of the project")
|
| 8 |
+
project_description: str = Field(..., description="Project description and goals")
|
| 9 |
+
project_type: Literal["Web Application", "Mobile App", "API Development",
|
| 10 |
+
"Data Analytics", "AI/ML Solution", "Other"] = Field(...,
|
| 11 |
+
description="Type of project")
|
| 12 |
+
budget_range: Literal["$10k-$25k", "$25k-$50k", "$50k-$100k", "$100k+"] = Field(...,
|
| 13 |
+
description="Budget range for the project")
|
| 14 |
|
| 15 |
class ToolConfig:
|
| 16 |
name = "analyze_project"
|
| 17 |
+
description = "Analyzes project requirements and feasibility"
|
| 18 |
one_call_at_a_time = True
|
| 19 |
|
| 20 |
def run(self) -> str:
|
| 21 |
+
"""Analyzes project and stores results in shared state"""
|
| 22 |
if self._shared_state.get("project_analysis", None) is not None:
|
| 23 |
+
raise ValueError("Project analysis already exists. Please proceed with technical specification.")
|
| 24 |
+
|
| 25 |
analysis = {
|
| 26 |
"name": self.project_name,
|
| 27 |
"type": self.project_type,
|
| 28 |
"complexity": "high",
|
| 29 |
"timeline": "6 months",
|
| 30 |
"budget_feasibility": "within range",
|
| 31 |
+
"requirements": ["Scalable architecture", "Security", "API integration"]
|
| 32 |
}
|
| 33 |
+
|
| 34 |
self._shared_state.set("project_analysis", analysis)
|
| 35 |
+
return "Project analysis completed. Please proceed with technical specification."
|
| 36 |
|
| 37 |
class CreateTechnicalSpecification(BaseTool):
|
| 38 |
+
architecture_type: Literal["monolithic", "microservices", "serverless", "hybrid"] = Field(
|
| 39 |
+
...,
|
| 40 |
+
description="Proposed architecture type"
|
| 41 |
+
)
|
| 42 |
+
core_technologies: str = Field(
|
| 43 |
+
...,
|
| 44 |
+
description="Comma-separated list of main technologies and frameworks"
|
| 45 |
+
)
|
| 46 |
+
scalability_requirements: Literal["high", "medium", "low"] = Field(
|
| 47 |
+
...,
|
| 48 |
+
description="Scalability needs"
|
| 49 |
+
)
|
| 50 |
|
| 51 |
class ToolConfig:
|
| 52 |
name = "create_technical_spec"
|
|
|
|
| 54 |
one_call_at_a_time = True
|
| 55 |
|
| 56 |
def run(self) -> str:
|
| 57 |
+
"""Creates technical specification based on analysis"""
|
| 58 |
project_analysis = self._shared_state.get("project_analysis", None)
|
| 59 |
if project_analysis is None:
|
| 60 |
+
raise ValueError("Please analyze project requirements first using AnalyzeProjectRequirements tool.")
|
| 61 |
+
|
| 62 |
+
spec = {
|
| 63 |
+
"project_name": project_analysis["name"],
|
| 64 |
"architecture": self.architecture_type,
|
| 65 |
+
"technologies": self.core_technologies.split(","),
|
| 66 |
+
"scalability": self.scalability_requirements
|
| 67 |
}
|
| 68 |
+
|
| 69 |
self._shared_state.set("technical_specification", spec)
|
| 70 |
+
return f"Technical specification created for {project_analysis['name']}."
|
| 71 |
|
| 72 |
def init_session_state() -> None:
|
| 73 |
+
"""Initialize session state variables"""
|
| 74 |
+
if 'messages' not in st.session_state:
|
| 75 |
+
st.session_state.messages = []
|
| 76 |
+
if 'api_key' not in st.session_state:
|
| 77 |
st.session_state.api_key = None
|
| 78 |
|
|
|
|
| 79 |
def main() -> None:
|
| 80 |
+
st.set_page_config(page_title="AI Services Agency", layout="wide")
|
| 81 |
init_session_state()
|
| 82 |
+
|
| 83 |
+
st.title("🚀 AI Services Agency")
|
| 84 |
+
|
| 85 |
# API Configuration
|
| 86 |
with st.sidebar:
|
| 87 |
+
st.header("🔑 API Configuration")
|
| 88 |
openai_api_key = st.text_input(
|
| 89 |
"OpenAI API Key",
|
| 90 |
+
type="password",
|
| 91 |
+
help="Enter your OpenAI API key to continue"
|
| 92 |
)
|
| 93 |
|
| 94 |
if openai_api_key:
|
| 95 |
st.session_state.api_key = openai_api_key
|
| 96 |
+
st.success("API Key accepted!")
|
| 97 |
else:
|
| 98 |
+
st.warning("⚠️ Please enter your OpenAI API Key to proceed")
|
| 99 |
st.markdown("[Get your API key here](https://platform.openai.com/api-keys)")
|
| 100 |
return
|
| 101 |
+
|
| 102 |
+
# Initialize agents with the provided API key
|
| 103 |
+
set_openai_key(st.session_state.api_key)
|
| 104 |
+
api_headers = {"Authorization": f"Bearer {st.session_state.api_key}"}
|