chaos4455 commited on
Commit
448b694
Β·
verified Β·
1 Parent(s): 89c7b66

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +116 -76
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="πŸ”„βœ¨ Gemini2 Script Mig 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,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 generate_migration_script(prompt_base, model_name, temperature, top_p, top_k, max_tokens, source_type, target_type, custom_requirements, specific_details, transformation_details):
37
- """Generates a migration script based on user settings."""
38
  prompt = f"""
39
- You are an expert automation engineer specializing in migration scripts. Your task is to generate a complete, secure, and efficient migration script based on the following description:
40
 
41
- **Goal:** Create the most complete, detailed, and efficient migration script possible, considering all variables, edge cases, and potential scenarios.
42
 
43
- **Migration Description:** {prompt_base}
44
-
45
- **Source Type:** {source_type if source_type else "None"}
46
- **Target Type:** {target_type if target_type else "None"}
47
- **Transformation Details:** {transformation_details if transformation_details else "None"}
 
 
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 python code block with its original formatting, without line breaks.
53
- - The python code block must be delimited by ```python and ```.
 
 
 
 
 
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
- - The code must use best practices for accessing resources, connecting to databases, handling errors and logging data.
59
- - Unless the user specifies otherwise, use the most current and secure versions of libraries and resources, using python and following best practices.
60
- - The code must use a valid logging system with timestamps and log levels.
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
- - If the user requests for a transformation, generate it using python code and libraries, and document every step in the code.
 
 
 
 
65
 
66
  **Important:**
67
- - Generate only one script at a time.
68
  - Create the longest, most complete, and detailed code possible to cover a wide range of possibilities and scenarios.
69
- - Consider all the details of the request, expanding the response and improving the script.
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 parse_and_save_py(ai_code, short_title):
79
- """Parses the markdown and saves the python code as .py."""
80
- match = re.search(r'```python\s*(.*?)\s*```', ai_code, re.DOTALL | re.IGNORECASE)
81
- if match:
82
- py_code = match.group(1).strip()
83
- else:
84
- py_code = ai_code.strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
- file_name = f"migration_script_{short_title}.py"
87
- with open(file_name, "w", encoding="utf-8") as f:
88
- f.write(py_code)
89
- return file_name, py_code
 
90
 
91
  def main():
92
- st.title("πŸ”„βœ¨ Gemini2 Script Mig Gen Pro by [Elias Andrade](https://github.com/chaos4455)")
93
- st.markdown("Generate advanced migration scripts with ease! πŸš€")
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("🧰 Migration Settings"):
110
- source_type = st.selectbox("πŸ“¦ Source Type", ["MySQL", "PostgreSQL", "SQLite", "MongoDB", "CSV", "JSON", "Parquet", "Excel", "BigQuery", "Snowflake", "Redis", "Kafka", "Other"], index=0, help="Select the type of the data source.")
111
- target_type = st.selectbox("🎯 Target Type", ["SQLite", "MySQL", "PostgreSQL", "MongoDB", "CSV", "JSON", "Parquet", "Excel", "BigQuery", "Snowflake", "Redis", "Kafka", "Other"], index=0, help="Select the type of the data target.")
112
- transformation_details = st.text_area("πŸ”„ Transformation Details", placeholder="Specify any transformations or filtering needed (e.g., convert date formats, filter rows, etc).",
113
- help="Provide details of any transformations you need during the migration, using Python or SQL, if it can be done with SQL.",
114
- )
115
- custom_requirements = st.text_input("βž• Custom Requirements:", placeholder="Specific libraries or parameters (e.g., version, parameters)", help="List specific libraries and versions, parameters, etc.")
116
- specific_details = st.text_input("ℹ️ Specific Details", placeholder="Special options, edge cases", help="Add specific details for the script generation.")
117
 
118
  with col2:
119
- # User's base prompt
120
- prompt_base = st.text_area("πŸ“ Describe the Migration:",
121
  placeholder=textwrap.dedent("""
122
- Describe your migration process in detail.
123
  Include:
124
- - Source and target system details (e.g., database IPs, ports, logins, passwords).
125
- - Specific tables to migrate.
126
- - Any filtering, transformations, or data cleansing needed.
127
- - Important notes about the systems (e.g., if there is an external system involved)
128
- If connection details or source and target are not included, the script will be generated using defaults, and you must fill in the parameters.
 
129
  """), key="prompt_base",
130
- help="Provide a detailed description of your migration, including source and target systems, tables, transformations, and any specific parameters.")
131
 
132
- if st.button("✨ Generate Migration Script"):
133
- if not prompt_base:
134
- st.error("⚠️ Please enter a migration description.")
135
- return
136
 
137
- with st.spinner("⏳ Generating script..."):
138
- ai_code = generate_migration_script(
139
  prompt_base,
140
  model_name,
141
  temperature,
142
  top_p,
143
  top_k,
144
  max_tokens,
145
- source_type,
146
- target_type,
147
  custom_requirements,
148
  specific_details,
149
- transformation_details
 
 
 
150
  )
151
 
152
  if ai_code:
153
- st.markdown("### βœ… Generated Migration Script:")
154
- st.code(ai_code, language="python")
155
-
156
- short_title = prompt_base[:30].strip().replace(" ", "_").lower()
157
- file_name_py, py_code = parse_and_save_py(ai_code, short_title)
158
-
159
- st.download_button(
160
- label="⬇️ Download Script (.py)",
161
- data=py_code,
162
- file_name=file_name_py,
163
- mime="application/x-python",
164
- )
 
165
  else:
166
- st.error("❌ Error generating the script. Check the connection with the AI and try again.")
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()