Spaces:
Sleeping
Sleeping
Update README.md
Browse filesinitiated readme.md
README.md
CHANGED
@@ -12,3 +12,227 @@ short_description: LLMs via LangChain SDLC workflow
|
|
12 |
---
|
13 |
|
14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
---
|
13 |
|
14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
15 |
+
|
16 |
+
|
17 |
+
# AI-Powered SDLC Orchestrator (Streamlit App)
|
18 |
+
|
19 |
+
## Description
|
20 |
+
|
21 |
+
This application leverages Large Language Models (LLMs) via LangChain to orchestrate a simplified Software Development Lifecycle (SDLC) workflow within a Streamlit user interface. It guides the user through various stages, from requirements gathering to deployment planning, using AI to generate artifacts and providing feedback loops involving both AI and human input.
|
22 |
+
|
23 |
+
The application is designed to be modular, with the Streamlit UI (`app.py`) handling user interaction and state management, while the core AI logic, state definitions, and artifact saving are encapsulated in the backend module (`newSDLC.py`).
|
24 |
+
|
25 |
+
## Features
|
26 |
+
|
27 |
+
* **Multi-Stage SDLC Simulation:** Covers key stages:
|
28 |
+
* Requirements Gathering (Iterative Q&A)
|
29 |
+
* User Story Generation & Refinement
|
30 |
+
* Product Owner Review & Refinement
|
31 |
+
* Design Document Generation & Refinement
|
32 |
+
* UML Diagram Selection, Generation (PlantUML), & Refinement
|
33 |
+
* Code Generation (based on design/UML) & Refinement (with Web Search via Tavily)
|
34 |
+
* Code Review & Security Analysis
|
35 |
+
* Test Case Generation & Code Refinement (based on test pass/fail)
|
36 |
+
* Quality Analysis Report Generation & Refinement
|
37 |
+
* Deployment Plan Generation & Refinement
|
38 |
+
* **Interactive Feedback Loops:** Incorporates both AI-generated feedback and user input at various stages for iterative refinement.
|
39 |
+
* **Dynamic LLM Configuration:** Allows users to select LLM providers (OpenAI, Groq, extensible) and specific models via the UI. API keys are entered securely.
|
40 |
+
* **Tavily Web Search Integration:** Uses Tavily API for web searches during the code generation cycle to find relevant solutions or fix errors based on user feedback.
|
41 |
+
* **Artifact Generation & Saving:** Creates text files (.md, .txt), PlantUML files (.puml), and attempts PNG generation for diagrams. Saves code files organized into stage-specific folders.
|
42 |
+
* **Downloadable Artifacts:** Provides download links in the sidebar for key documents, UML diagrams (PNGs if generated), and code snapshots (ZIP archives) from critical stages (Review, Testing, Final).
|
43 |
+
* **Workflow Visualization:** Includes a graph diagram (`SDLC_Workflow_Graph_Diagram.png`) visualizing the application's state transitions (Note: This static image doesn't update dynamically).
|
44 |
+
* **State Management:** Uses Streamlit's session state to maintain progress throughout the workflow.
|
45 |
+
* **Error Handling & Retry:** Incorporates basic retry logic (using Tenacity) for potentially flaky LLM calls and provides UI feedback on errors.
|
46 |
+
|
47 |
+
## Workflow Diagram
|
48 |
+
|
49 |
+

|
50 |
+
*(This diagram illustrates the general flow of stages and decision points within the application)*
|
51 |
+
|
52 |
+
## Technology Stack
|
53 |
+
|
54 |
+
* **Frontend:** Python, Streamlit
|
55 |
+
* **Backend Logic:** Python
|
56 |
+
* **AI Orchestration:** LangChain (`langchain`, `langchain-core`, `langchain-openai`, `langchain-groq`)
|
57 |
+
* **LLM APIs:** OpenAI API, Groq API (extensible)
|
58 |
+
* **Web Search:** Tavily API
|
59 |
+
* **UML Generation:** `plantuml` library (requires Java runtime)
|
60 |
+
* **Data Validation:** Pydantic
|
61 |
+
* **Retry Logic:** Tenacity
|
62 |
+
* **Environment Mgmt:** `python-dotenv`
|
63 |
+
|
64 |
+
## Setup & Local Run
|
65 |
+
|
66 |
+
### Prerequisites
|
67 |
+
|
68 |
+
* Python 3.9+
|
69 |
+
* Git
|
70 |
+
* Java Runtime Environment (JRE/JDK) installed and added to your system's PATH (required for PlantUML PNG generation). You can often test this by running `java -version` in your terminal.
|
71 |
+
|
72 |
+
### Steps
|
73 |
+
|
74 |
+
1. **Clone the Repository:**
|
75 |
+
```bash
|
76 |
+
git clone <your-repo-url>
|
77 |
+
cd <your-repo-name>
|
78 |
+
```
|
79 |
+
|
80 |
+
2. **Create Virtual Environment (Recommended):**
|
81 |
+
```bash
|
82 |
+
python -m venv env
|
83 |
+
# Activate it:
|
84 |
+
# Windows:
|
85 |
+
.\env\Scripts\activate
|
86 |
+
# macOS/Linux:
|
87 |
+
source env/bin/activate
|
88 |
+
```
|
89 |
+
|
90 |
+
3. **Install Dependencies:**
|
91 |
+
```bash
|
92 |
+
pip install -r requirements.txt
|
93 |
+
```
|
94 |
+
|
95 |
+
4. **Configure API Keys (.env file):**
|
96 |
+
* Create a file named `.env` in the project's root directory.
|
97 |
+
* Add your API keys to this file. **Important:** The Streamlit app now takes keys via the UI, but `newSDLC.py` *might* still load other variables from `.env` if you added any. For local testing *without* the UI configuration, you might populate these (but the UI method is preferred for deployment):
|
98 |
+
```dotenv
|
99 |
+
# --- LLM Configuration (NOW HANDLED BY UI, but keep for reference) ---
|
100 |
+
# MODEL_PROVIDER="OpenAI" # or "Groq"
|
101 |
+
# OPENAI_MODEL_NAME="gpt-4o"
|
102 |
+
# OPENAI_API_KEY="sk-..."
|
103 |
+
# GROQ_MODEL_NAME="llama3-70b-8192"
|
104 |
+
# GROQ_API_KEY="gsk_..."
|
105 |
+
|
106 |
+
# --- Tavily Configuration (NOW HANDLED BY UI, but keep for reference) ---
|
107 |
+
# TAVILY_API_KEY="tvly-..."
|
108 |
+
|
109 |
+
# --- Optional: LangSmith Tracing ---
|
110 |
+
# LANGCHAIN_TRACING_V2="true"
|
111 |
+
# LANGSMITH_API_KEY="ls__..."
|
112 |
+
# LANGCHAIN_ENDPOINT="https://api.smith.langchain.com"
|
113 |
+
# LANGCHAIN_PROJECT="Your-Project-Name" # Replace with your LangSmith project
|
114 |
+
```
|
115 |
+
* **Never commit your `.env` file to Git!** Add `.env` to your `.gitignore` file.
|
116 |
+
|
117 |
+
5. **Run the Streamlit App:**
|
118 |
+
```bash
|
119 |
+
streamlit run app.py
|
120 |
+
```
|
121 |
+
|
122 |
+
6. **Configure in UI:** Open the app in your browser. Use the "Configuration" section in the sidebar to select your LLM provider, model, and enter the corresponding LLM API key and your Tavily API key. Click "Apply Configuration".
|
123 |
+
|
124 |
+
7. **Start Workflow:** Once configuration is applied successfully, the initial project setup form will appear. Fill it in and click "Start Workflow".
|
125 |
+
|
126 |
+
## Configuration (API Keys & Models)
|
127 |
+
|
128 |
+
* **LLM Provider & Model:** Select your desired LLM provider (e.g., OpenAI, Groq) and the specific model from the dropdowns in the Streamlit sidebar's "Configuration" section.
|
129 |
+
* **LLM API Key:** Enter the API key corresponding to the selected provider in the password input field within the sidebar configuration.
|
130 |
+
* **Tavily API Key:** Enter your Tavily API key in the password input field for web search functionality. This is optional; if left blank, web search steps will be skipped.
|
131 |
+
* **Apply:** Click "Apply Configuration" to initialize the LLM and Tavily clients. The main workflow UI will only become active after successful configuration.
|
132 |
+
|
133 |
+
**Important API Key Notes:**
|
134 |
+
|
135 |
+
* **Security:** API keys entered via the UI are stored in Streamlit's session state *for the duration of the session*. They are **not** saved permanently in any file by the application itself. However, be mindful when deploying, especially to public platforms. Use Hugging Face Secrets (see Deployment section).
|
136 |
+
* **Provider Requirements:**
|
137 |
+
* **Groq:** Requires a GroqCloud API key. Free tiers might have rate limits or context window limitations that could affect complex generations.
|
138 |
+
* **OpenAI:** Requires an OpenAI API key with billing set up. Costs will be incurred based on usage.
|
139 |
+
* **Tavily:** Requires a Tavily API key. Check their pricing for usage limits.
|
140 |
+
* Other providers (if added) will have their own key requirements and potential costs/limitations.
|
141 |
+
|
142 |
+
## Hugging Face Spaces Deployment Guide
|
143 |
+
|
144 |
+
You can deploy this application as a Streamlit app on Hugging Face Spaces.
|
145 |
+
|
146 |
+
### Steps
|
147 |
+
|
148 |
+
1. **Hugging Face Account:** Ensure you have a Hugging Face account.
|
149 |
+
2. **Create New Space:**
|
150 |
+
* Go to [huggingface.co/new-space](https://huggingface.co/new-space).
|
151 |
+
* Choose an **Owner** (your user or an org).
|
152 |
+
* Enter a **Space name** (e.g., `ai-sdlc-orchestrator`).
|
153 |
+
* Select **Streamlit** as the Space SDK.
|
154 |
+
* Choose hardware (CPU basic is likely sufficient to start).
|
155 |
+
* Choose **Public** or **Private** visibility. (Use Private if testing with sensitive keys initially).
|
156 |
+
* Click **Create Space**.
|
157 |
+
3. **Upload Files:** You have two main options:
|
158 |
+
* **(Recommended) Use Git:** Clone the Space repository locally, add your files, commit, and push.
|
159 |
+
```bash
|
160 |
+
# Clone your newly created space repo
|
161 |
+
git clone https://huggingface.co/spaces/<your-username>/<your-space-name>
|
162 |
+
cd <your-space-name>
|
163 |
+
|
164 |
+
# Copy your project files here:
|
165 |
+
# app.py, newSDLC.py, requirements.txt, SDLC_Workflow_Graph_Diagram.png
|
166 |
+
|
167 |
+
# Add, commit, and push
|
168 |
+
git add .
|
169 |
+
git commit -m "Add initial application files"
|
170 |
+
git push
|
171 |
+
```
|
172 |
+
* **Upload via UI:** Go to the "Files" tab in your Space settings and upload `app.py`, `newSDLC.py`, `requirements.txt`, and optionally `SDLC_Workflow_Graph_Diagram.png`.
|
173 |
+
|
174 |
+
4. **Configure Secrets (CRITICAL):**
|
175 |
+
* **DO NOT put API keys directly in your code or `requirements.txt` or `.env` when deploying!**
|
176 |
+
* Go to your Space settings (click the gear icon or navigate to `https://huggingface.co/spaces/<your-username>/<your-space-name>/settings`).
|
177 |
+
* Scroll down to the **"Secrets"** section.
|
178 |
+
* Click **"New secret"**.
|
179 |
+
* Add secrets for your API keys. **Crucially, the "Secret name" must exactly match the variable names your UI configuration expects to retrieve or the names used if `newSDLC.py` were loading them directly (though it shouldn't be for deployment).** Since the UI handles input, you might not *need* secrets if users always enter them, *but it's much safer and more convenient to use secrets*. Let's assume you *want* to pre-fill the keys from secrets:
|
180 |
+
* Name: `LLM_API_KEY` -> Value: `<Your-OpenAI-or-Groq-Key>` (Enter the key you'll use most often, or leave blank if users *must* enter it).
|
181 |
+
* Name: `TAVILY_API_KEY` -> Value: `<Your-Tavily-Key>` (Or leave blank).
|
182 |
+
* *Modify `app.py` (Optional):* If you use secrets, you could pre-fill the `st.text_input` `value` fields by reading the secrets:
|
183 |
+
```python
|
184 |
+
# Inside sidebar configuration expander in app.py
|
185 |
+
llm_key_secret = os.environ.get("LLM_API_KEY", "") # Read from env (set by HF secrets)
|
186 |
+
tavily_key_secret = os.environ.get("TAVILY_API_KEY", "")
|
187 |
+
llm_api_key_input = st.text_input(..., value=st.session_state.get("llm_api_key", llm_key_secret))
|
188 |
+
tavily_api_key_input = st.text_input(..., value=st.session_state.get("tavily_api_key", tavily_key_secret))
|
189 |
+
```
|
190 |
+
* Secrets are injected as environment variables into your Space container.
|
191 |
+
|
192 |
+
5. **PlantUML / Java Dependency (Limitation):**
|
193 |
+
* The default Streamlit SDK environment on Hugging Face Spaces **does not include Java**.
|
194 |
+
* Therefore, the `plantuml` library **will likely fail** when trying to generate PNG images (`save_final_uml_diagrams` will log errors for PNG generation).
|
195 |
+
* **Workarounds:**
|
196 |
+
* **Accept Limitation:** The app will still function, and `.puml` files will be saved. Users just won't get PNG download buttons in the sidebar. This is the simplest approach. You might want to update the sidebar caption in `app.py` for UML downloads to explicitly state PNGs are unavailable on this deployment.
|
197 |
+
* **Modify `newSDLC.py`:** Comment out or remove the PNG generation block within `save_final_uml_diagrams` to prevent errors in the logs.
|
198 |
+
* **(Advanced) Use Docker:** Create a custom Dockerfile for your Space that starts from a base image including Python and Java, installs PlantUML, copies your app files, and runs Streamlit. This requires Docker knowledge.
|
199 |
+
|
200 |
+
6. **Check Build & Runtime Logs:**
|
201 |
+
* Go to your Space page. Hugging Face will automatically try to build the environment based on `requirements.txt`.
|
202 |
+
* Monitor the "Build logs" and "Runtime logs" for any errors during installation or application startup. Fix any dependency issues in `requirements.txt` if needed.
|
203 |
+
|
204 |
+
7. **Access Your App:** Once the build is complete, your Streamlit app should be running at `https://huggingface.co/spaces/<your-username>/<your-space-name>`.
|
205 |
+
|
206 |
+
## How it Works
|
207 |
+
|
208 |
+
1. **Configuration (`app.py` Sidebar):** The user selects the LLM provider/model and enters API keys. Clicking "Apply" calls `initialize_llm_clients` in `newSDLC.py`.
|
209 |
+
2. **Initialization (`newSDLC.py`):** `initialize_llm_clients` attempts to create LangChain LLM and Tavily client instances using the provided keys and settings. It returns the instances (or None) and any error messages.
|
210 |
+
3. **State Setup (`app.py`):** If initialization succeeds, the instances are stored in `st.session_state`. When the user starts the workflow via the "Project Configuration" form, these instances are copied into the main `st.session_state.workflow_state` dictionary under the keys `llm_instance` and `tavily_instance`.
|
211 |
+
4. **Workflow Execution (`app.py` + `newSDLC.py`):**
|
212 |
+
* `app.py` uses the `current_stage` in session state to determine what UI elements to show (input boxes, buttons).
|
213 |
+
* User actions trigger transitions to "run\_..." stages.
|
214 |
+
* `app.py`'s `run_workflow_step` function looks up the appropriate backend function from `newSDLC.py` in the `workflow_map`.
|
215 |
+
* It calls the backend function, passing the entire `workflow_state` dictionary (which includes the LLM/Tavily instances).
|
216 |
+
* Backend functions in `newSDLC.py` access `state['llm_instance']` or `state['tavily_instance']` to perform their tasks (LLM calls, searches). They perform checks to ensure the instance exists before using it.
|
217 |
+
* Backend functions update the `state` dictionary and return it.
|
218 |
+
* `run_workflow_step` updates the session state, determines the next display content, sets the next UI stage, and triggers a Streamlit rerun.
|
219 |
+
5. **Artifact Saving (`newSDLC.py`):** `save_...` functions write artifacts to subdirectories within the `project_folder` defined during setup. Path keys are added to the state for `app.py` to create download links/ZIPs.
|
220 |
+
|
221 |
+
## Limitations & Future Work
|
222 |
+
|
223 |
+
* **PlantUML on Spaces:** PNG generation for UML diagrams is unlikely to work on default HF Spaces due to the missing Java dependency. Only `.puml` files are reliably saved.
|
224 |
+
* **Error Handling:** Basic error handling exists, but complex LLM errors or unexpected workflow states might require a manual restart. UI feedback on specific errors could be improved.
|
225 |
+
* **No Persistence:** Project state is lost when the Streamlit session ends or the app restarts. Implementing database storage or saving/loading state would be needed for persistence.
|
226 |
+
* **Context Window Limits:** Code context sent to the LLM is truncated to avoid errors, which might limit the AI's understanding in complex refinement steps.
|
227 |
+
* **Model Support:** Only OpenAI and Groq are currently implemented in `initialize_llm_clients`. Adding more providers requires updating `newSDLC.py` and `app.py`.
|
228 |
+
* **UI for UML Feedback:** Currently, UML feedback is collected via a single text box (`collect_uml_human_feedback`), not per-diagram.
|
229 |
+
|
230 |
+
## Contributing
|
231 |
+
|
232 |
+
(Optional: Add guidelines if you expect contributions)
|
233 |
+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
234 |
+
|
235 |
+
## License
|
236 |
+
|
237 |
+
(Optional: Specify a license, e.g., MIT, Apache 2.0)
|
238 |
+
[MIT](https://choosealicense.com/licenses/mit/)
|