Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,7 @@ import textwrap
|
|
| 8 |
API_KEY = st.secrets["GOOGLE_API_KEY"]
|
| 9 |
|
| 10 |
# Page configuration
|
| 11 |
-
st.set_page_config(page_title="
|
| 12 |
|
| 13 |
# --- Helper Functions ---
|
| 14 |
def send_message_to_model(message, model_name, temperature, top_p, top_k, max_tokens):
|
|
@@ -33,64 +33,100 @@ def send_message_to_model(message, model_name, temperature, top_p, top_k, max_to
|
|
| 33 |
st.error(f"β Error communicating with the AI: {e}")
|
| 34 |
return None
|
| 35 |
|
| 36 |
-
def
|
| 37 |
-
"""Generates a
|
| 38 |
prompt = f"""
|
| 39 |
-
You are an expert
|
| 40 |
|
| 41 |
-
**Goal:** Create the most complete, detailed, and efficient
|
| 42 |
|
| 43 |
-
**
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
**
|
| 47 |
-
**
|
|
|
|
|
|
|
| 48 |
**Custom Requirements:** {custom_requirements if custom_requirements else "None"}
|
| 49 |
**Specific Details:** {specific_details if specific_details else "None"}
|
| 50 |
|
| 51 |
**Response Format:**
|
| 52 |
-
- Respond in Markdown format, including a
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
- Do not include comments, explanations, or any other text outside the code block, unless the prompt requires.
|
| 55 |
- The code must maintain its full vertical formatting, respecting indentation and line breaks.
|
| 56 |
- The code must be realistic, using real-world examples, data, and situations.
|
| 57 |
- Explore different approaches, techniques, and advanced practices, always prioritizing security and efficiency.
|
| 58 |
-
|
| 59 |
-
- Unless the user specifies otherwise, use the most current and secure versions of
|
| 60 |
-
-
|
| 61 |
-
- The code must be well structured according to PEP8 guidelines, with docstrings and clear naming conventions.
|
| 62 |
-
- Use incremental reasoning to add improvements, expansions, and considerations to your code.
|
| 63 |
- Use the history of the conversations so that the response is incremental.
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
**Important:**
|
| 67 |
-
- Generate only one
|
| 68 |
- Create the longest, most complete, and detailed code possible to cover a wide range of possibilities and scenarios.
|
| 69 |
-
|
| 70 |
-
- If the user does not provide details on connection parameters, create placeholders in the code with comments like 'PLEASE FILL THIS' indicating where the user should fill in.
|
| 71 |
-
- If the user does not provide the details about source and target, use MySQL as source and SQLite as target, and include comments on what the user should change, use the comments '# SOURCE DATABASE' and '# TARGET DATABASE'.
|
| 72 |
-
- Provide in your code all necessary comments for the user to understand the process of migration and where he should add his parameters.
|
| 73 |
-
- Use `try/except` blocks for error handling, and document what could cause the errors.
|
| 74 |
"""
|
| 75 |
response = send_message_to_model(prompt, model_name, temperature, top_p, top_k, max_tokens)
|
| 76 |
return response
|
| 77 |
|
| 78 |
-
def
|
| 79 |
-
"""Parses the markdown and saves the
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
|
|
|
| 90 |
|
| 91 |
def main():
|
| 92 |
-
st.title("
|
| 93 |
-
st.markdown("Generate advanced
|
| 94 |
st.markdown("---")
|
| 95 |
|
| 96 |
# Layout in columns (sidebar and main area)
|
|
@@ -106,64 +142,68 @@ def main():
|
|
| 106 |
top_k = st.slider("Top K", min_value=1, max_value=100, value=40, step=1, help="Adjust the AI's number of candidate tokens.")
|
| 107 |
max_tokens = st.number_input("π Max Tokens", min_value=128, max_value=8192, value=8192, step=128, help="Adjust the maximum size of the response.")
|
| 108 |
|
| 109 |
-
with st.expander("π§°
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
|
| 118 |
with col2:
|
| 119 |
-
|
| 120 |
-
prompt_base = st.text_area("π Describe the
|
| 121 |
placeholder=textwrap.dedent("""
|
| 122 |
-
Describe your
|
| 123 |
Include:
|
| 124 |
-
-
|
| 125 |
-
- Specific
|
| 126 |
-
-
|
| 127 |
-
-
|
| 128 |
-
|
|
|
|
| 129 |
"""), key="prompt_base",
|
| 130 |
-
|
| 131 |
|
| 132 |
-
if st.button("β¨ Generate
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
|
| 137 |
-
|
| 138 |
-
ai_code =
|
| 139 |
prompt_base,
|
| 140 |
model_name,
|
| 141 |
temperature,
|
| 142 |
top_p,
|
| 143 |
top_k,
|
| 144 |
max_tokens,
|
| 145 |
-
|
| 146 |
-
target_type,
|
| 147 |
custom_requirements,
|
| 148 |
specific_details,
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
| 150 |
)
|
| 151 |
|
| 152 |
if ai_code:
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
|
|
|
| 165 |
else:
|
| 166 |
-
st.error("β Error generating the
|
| 167 |
|
| 168 |
if __name__ == "__main__":
|
| 169 |
main()
|
|
|
|
| 8 |
API_KEY = st.secrets["GOOGLE_API_KEY"]
|
| 9 |
|
| 10 |
# Page configuration
|
| 11 |
+
st.set_page_config(page_title="πβ¨ Gemini2 CI/CD Gen Pro", page_icon="πβ¨", layout="wide")
|
| 12 |
|
| 13 |
# --- Helper Functions ---
|
| 14 |
def send_message_to_model(message, model_name, temperature, top_p, top_k, max_tokens):
|
|
|
|
| 33 |
st.error(f"β Error communicating with the AI: {e}")
|
| 34 |
return None
|
| 35 |
|
| 36 |
+
def generate_cicd_pipeline(prompt_base, model_name, temperature, top_p, top_k, max_tokens, target_systems, custom_requirements, specific_details, deploy_details, docker_details, kubernetes_details, test_details):
|
| 37 |
+
"""Generates a CI/CD pipeline based on user settings."""
|
| 38 |
prompt = f"""
|
| 39 |
+
You are an expert DevOps engineer specializing in CI/CD pipelines. Your task is to generate complete, secure, and efficient CI/CD pipeline configurations based on the following description:
|
| 40 |
|
| 41 |
+
**Goal:** Create the most complete, detailed, and efficient CI/CD pipeline possible, considering all variables, edge cases, and potential scenarios.
|
| 42 |
|
| 43 |
+
**Pipeline Description:** {prompt_base}
|
| 44 |
+
|
| 45 |
+
**Target Systems:** {target_systems if target_systems else "None"}
|
| 46 |
+
**Deployment Details:** {deploy_details if deploy_details else "None"}
|
| 47 |
+
**Docker Details:** {docker_details if docker_details else "None"}
|
| 48 |
+
**Kubernetes Details:** {kubernetes_details if kubernetes_details else "None"}
|
| 49 |
+
**Test Details:** {test_details if test_details else "None"}
|
| 50 |
**Custom Requirements:** {custom_requirements if custom_requirements else "None"}
|
| 51 |
**Specific Details:** {specific_details if specific_details else "None"}
|
| 52 |
|
| 53 |
**Response Format:**
|
| 54 |
+
- Respond in Markdown format, including YAML code blocks for Argo CD, GitHub Actions, GitLab Runner, Jenkins, CircleCI, and a Docker Compose, with their original formatting and without line breaks.
|
| 55 |
+
- The Argo CD code block must be delimited by ```yaml argocd and ```.
|
| 56 |
+
- The GitHub Actions code block must be delimited by ```yaml githubactions and ```.
|
| 57 |
+
- The GitLab Runner code block must be delimited by ```yaml gitlabrunner and ```.
|
| 58 |
+
- The Jenkins code block must be delimited by ```yaml jenkins and ```.
|
| 59 |
+
- The CircleCI code block must be delimited by ```yaml circleci and ```.
|
| 60 |
+
- The Docker Compose code block must be delimited by ```yaml dockercompose and ```.
|
| 61 |
- Do not include comments, explanations, or any other text outside the code block, unless the prompt requires.
|
| 62 |
- The code must maintain its full vertical formatting, respecting indentation and line breaks.
|
| 63 |
- The code must be realistic, using real-world examples, data, and situations.
|
| 64 |
- Explore different approaches, techniques, and advanced practices, always prioritizing security and efficiency.
|
| 65 |
+
- Use best practices for building images, running tests, and deploying applications.
|
| 66 |
+
- Unless the user specifies otherwise, use the most current and secure versions of the tools and resources, using YAML and following best practices.
|
| 67 |
+
- Use incremental reasoning to add improvements, expansions, and considerations to your code.
|
|
|
|
|
|
|
| 68 |
- Use the history of the conversations so that the response is incremental.
|
| 69 |
+
- If Docker is required, generate configurations to build Docker Images and push to Dockerhub.
|
| 70 |
+
- If kubernetes is required, use Argo CD for deployments and create the necessary configurations, generating the application.yaml, and any other resources.
|
| 71 |
+
- If any connection parameters are needed, use placeholders in the code with comments like 'PLEASE FILL THIS' indicating where the user should fill in.
|
| 72 |
+
- Use comments to explain the configurations.
|
| 73 |
+
- If the user does not specify target systems, generate for Argo CD, Github Actions and Gitlab Runner.
|
| 74 |
|
| 75 |
**Important:**
|
| 76 |
+
- Generate only one pipeline at a time.
|
| 77 |
- Create the longest, most complete, and detailed code possible to cover a wide range of possibilities and scenarios.
|
| 78 |
+
- Consider all the details of the request, expanding the response and improving the code.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
"""
|
| 80 |
response = send_message_to_model(prompt, model_name, temperature, top_p, top_k, max_tokens)
|
| 81 |
return response
|
| 82 |
|
| 83 |
+
def parse_and_save_yaml(ai_code, short_title):
|
| 84 |
+
"""Parses the markdown and saves the YAML code."""
|
| 85 |
+
argocd_match = re.search(r'```yaml argocd\s*(.*?)\s*```', ai_code, re.DOTALL | re.IGNORECASE)
|
| 86 |
+
github_actions_match = re.search(r'```yaml githubactions\s*(.*?)\s*```', ai_code, re.DOTALL | re.IGNORECASE)
|
| 87 |
+
gitlab_runner_match = re.search(r'```yaml gitlabrunner\s*(.*?)\s*```', ai_code, re.DOTALL | re.IGNORECASE)
|
| 88 |
+
jenkins_match = re.search(r'```yaml jenkins\s*(.*?)\s*```', ai_code, re.DOTALL | re.IGNORECASE)
|
| 89 |
+
circleci_match = re.search(r'```yaml circleci\s*(.*?)\s*```', ai_code, re.DOTALL | re.IGNORECASE)
|
| 90 |
+
dockercompose_match = re.search(r'```yaml dockercompose\s*(.*?)\s*```', ai_code, re.DOTALL | re.IGNORECASE)
|
| 91 |
+
|
| 92 |
+
argocd_code = argocd_match.group(1).strip() if argocd_match else None
|
| 93 |
+
github_actions_code = github_actions_match.group(1).strip() if github_actions_match else None
|
| 94 |
+
gitlab_runner_code = gitlab_runner_match.group(1).strip() if gitlab_runner_match else None
|
| 95 |
+
jenkins_code = jenkins_match.group(1).strip() if jenkins_match else None
|
| 96 |
+
circleci_code = circleci_match.group(1).strip() if circleci_match else None
|
| 97 |
+
dockercompose_code = dockercompose_match.group(1).strip() if dockercompose_match else None
|
| 98 |
+
|
| 99 |
+
base_file_name = f"cicd_pipeline_{short_title}"
|
| 100 |
+
|
| 101 |
+
files = {}
|
| 102 |
+
|
| 103 |
+
if argocd_code:
|
| 104 |
+
files["argocd"] = {"name":f"{base_file_name}_argocd.yaml", "code":argocd_code}
|
| 105 |
+
|
| 106 |
+
if github_actions_code:
|
| 107 |
+
files["githubactions"] = {"name":f"{base_file_name}_githubactions.yaml", "code":github_actions_code}
|
| 108 |
+
|
| 109 |
+
if gitlab_runner_code:
|
| 110 |
+
files["gitlabrunner"] = {"name":f"{base_file_name}_gitlabrunner.yaml", "code":gitlab_runner_code}
|
| 111 |
+
|
| 112 |
+
if jenkins_code:
|
| 113 |
+
files["jenkins"] = {"name":f"{base_file_name}_jenkins.yaml", "code":jenkins_code}
|
| 114 |
+
|
| 115 |
+
if circleci_code:
|
| 116 |
+
files["circleci"] = {"name":f"{base_file_name}_circleci.yaml", "code":circleci_code}
|
| 117 |
+
|
| 118 |
+
if dockercompose_code:
|
| 119 |
+
files["dockercompose"] = {"name":f"{base_file_name}_dockercompose.yaml", "code":dockercompose_code}
|
| 120 |
|
| 121 |
+
for key, value in files.items():
|
| 122 |
+
with open(value["name"], "w", encoding="utf-8") as f:
|
| 123 |
+
f.write(value["code"])
|
| 124 |
+
|
| 125 |
+
return files
|
| 126 |
|
| 127 |
def main():
|
| 128 |
+
st.title("πβ¨ Gemini2 CI/CD Gen Pro by [Elias Andrade](https://github.com/chaos4455)")
|
| 129 |
+
st.markdown("Generate advanced CI/CD pipelines with ease! π")
|
| 130 |
st.markdown("---")
|
| 131 |
|
| 132 |
# Layout in columns (sidebar and main area)
|
|
|
|
| 142 |
top_k = st.slider("Top K", min_value=1, max_value=100, value=40, step=1, help="Adjust the AI's number of candidate tokens.")
|
| 143 |
max_tokens = st.number_input("π Max Tokens", min_value=128, max_value=8192, value=8192, step=128, help="Adjust the maximum size of the response.")
|
| 144 |
|
| 145 |
+
with st.expander("π§° Pipeline Settings"):
|
| 146 |
+
target_systems = st.multiselect("π― Target Systems", ["Argo CD", "GitHub Actions", "GitLab Runner", "Jenkins", "CircleCI", "Docker Compose", "Other"], default=["Argo CD", "GitHub Actions", "GitLab Runner"], help="Select the target systems for the pipeline.")
|
| 147 |
+
deploy_details = st.text_area("π Deployment Details", placeholder="Specify deployment details, e.g., Kubernetes manifests, Dockerfiles, etc.", help="Provide any details about how and where to deploy")
|
| 148 |
+
docker_details = st.text_input("π³ Docker Details", placeholder="Specify details like Docker registry, image names, etc.", help="Provide details about docker builds")
|
| 149 |
+
kubernetes_details = st.text_input("βΈοΈ Kubernetes Details", placeholder="Specify details like namespaces, deployments, etc.", help="Provide details about kubernetes deployments")
|
| 150 |
+
test_details = st.text_input("π§ͺ Test Details", placeholder="Specify test details or test commands", help="Provide any details about the tests to be executed")
|
| 151 |
+
custom_requirements = st.text_input("β Custom Requirements:", placeholder="Specific steps or tools (e.g., terraform, ansible)", help="List any specific steps or tools.")
|
| 152 |
+
specific_details = st.text_input("βΉοΈ Specific Details", placeholder="Special options, edge cases", help="Add specific details for the pipeline generation.")
|
| 153 |
|
| 154 |
with col2:
|
| 155 |
+
# User's base prompt
|
| 156 |
+
prompt_base = st.text_area("π Describe the CI/CD Pipeline:",
|
| 157 |
placeholder=textwrap.dedent("""
|
| 158 |
+
Describe your CI/CD pipeline in detail.
|
| 159 |
Include:
|
| 160 |
+
- Steps for building, testing, and deploying your application.
|
| 161 |
+
- Specific tools to be used (e.g., Docker, Kubernetes, Argo CD, etc).
|
| 162 |
+
- DockerHub details (user, password) or any other registry details.
|
| 163 |
+
- Kubernetes cluster details.
|
| 164 |
+
- Any custom parameters, configurations, or secrets you need.
|
| 165 |
+
If those details are not included, the pipeline will be generated using defaults, and you must fill in the parameters.
|
| 166 |
"""), key="prompt_base",
|
| 167 |
+
help="Provide a detailed description of your CI/CD pipeline.")
|
| 168 |
|
| 169 |
+
if st.button("β¨ Generate CI/CD Pipeline"):
|
| 170 |
+
if not prompt_base:
|
| 171 |
+
st.error("β οΈ Please enter a pipeline description.")
|
| 172 |
+
return
|
| 173 |
|
| 174 |
+
with st.spinner("β³ Generating pipeline..."):
|
| 175 |
+
ai_code = generate_cicd_pipeline(
|
| 176 |
prompt_base,
|
| 177 |
model_name,
|
| 178 |
temperature,
|
| 179 |
top_p,
|
| 180 |
top_k,
|
| 181 |
max_tokens,
|
| 182 |
+
target_systems,
|
|
|
|
| 183 |
custom_requirements,
|
| 184 |
specific_details,
|
| 185 |
+
deploy_details,
|
| 186 |
+
docker_details,
|
| 187 |
+
kubernetes_details,
|
| 188 |
+
test_details
|
| 189 |
)
|
| 190 |
|
| 191 |
if ai_code:
|
| 192 |
+
st.markdown("### β
Generated Pipeline:")
|
| 193 |
+
st.code(ai_code, language="text")
|
| 194 |
+
|
| 195 |
+
short_title = prompt_base[:30].strip().replace(" ", "_").lower()
|
| 196 |
+
files = parse_and_save_yaml(ai_code, short_title)
|
| 197 |
+
|
| 198 |
+
for key, value in files.items():
|
| 199 |
+
st.download_button(
|
| 200 |
+
label=f"β¬οΈ Download Pipeline (.{(key)})",
|
| 201 |
+
data=value["code"],
|
| 202 |
+
file_name=value["name"],
|
| 203 |
+
mime="application/x-yaml",
|
| 204 |
+
)
|
| 205 |
else:
|
| 206 |
+
st.error("β Error generating the pipeline. Check the connection with the AI and try again.")
|
| 207 |
|
| 208 |
if __name__ == "__main__":
|
| 209 |
main()
|