Update app.py
Browse files
app.py
CHANGED
|
@@ -3,604 +3,281 @@ import google.generativeai as genai
|
|
| 3 |
import requests
|
| 4 |
import subprocess
|
| 5 |
import os
|
|
|
|
| 6 |
import pandas as pd
|
| 7 |
-
import numpy as np
|
| 8 |
from sklearn.model_selection import train_test_split
|
| 9 |
-
from sklearn.ensemble import RandomForestClassifier
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
from
|
| 13 |
-
import
|
| 14 |
-
import
|
| 15 |
-
import
|
| 16 |
-
from
|
| 17 |
-
import
|
| 18 |
-
import networkx as nx
|
| 19 |
import matplotlib.pyplot as plt
|
| 20 |
-
import
|
| 21 |
-
import javalang
|
| 22 |
-
import clang.cindex
|
| 23 |
-
import radon.metrics as radon_metrics
|
| 24 |
-
import radon.complexity as radon_complexity
|
| 25 |
-
import black
|
| 26 |
-
import isort
|
| 27 |
-
import autopep8
|
| 28 |
-
from typing import List, Dict, Any
|
| 29 |
-
import joblib
|
| 30 |
-
from fastapi import FastAPI
|
| 31 |
-
from pydantic import BaseModel
|
| 32 |
-
import uvicorn
|
| 33 |
|
| 34 |
# Configure the Gemini API
|
| 35 |
genai.configure(api_key=st.secrets["GOOGLE_API_KEY"])
|
| 36 |
|
| 37 |
# Create the model with optimized parameters and enhanced system instructions
|
| 38 |
generation_config = {
|
| 39 |
-
"temperature": 0.
|
| 40 |
-
"top_p": 0.
|
| 41 |
-
"top_k":
|
| 42 |
-
"max_output_tokens":
|
| 43 |
}
|
| 44 |
|
| 45 |
model = genai.GenerativeModel(
|
| 46 |
model_name="gemini-1.5-pro",
|
| 47 |
generation_config=generation_config,
|
| 48 |
system_instruction="""
|
| 49 |
-
You are Ath,
|
|
|
|
| 50 |
"""
|
| 51 |
)
|
| 52 |
chat_session = model.start_chat(history=[])
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
codebert_model = AutoModel.from_pretrained("microsoft/codebert-base")
|
| 57 |
-
code_generation_model = pipeline("text-generation", model="EleutherAI/gpt-neo-2.7B")
|
| 58 |
-
|
| 59 |
-
# Load GPT-2 for more advanced text generation
|
| 60 |
-
gpt2_model = GPT2LMHeadModel.from_pretrained("gpt2-large")
|
| 61 |
-
gpt2_tokenizer = GPT2Tokenizer.from_pretrained("gpt2-large")
|
| 62 |
-
|
| 63 |
-
class AdvancedCodeImprovement(nn.Module):
|
| 64 |
-
def __init__(self, input_dim):
|
| 65 |
-
super(AdvancedCodeImprovement, self).__init__()
|
| 66 |
-
self.lstm = nn.LSTM(input_dim, 512, num_layers=2, batch_first=True, bidirectional=True)
|
| 67 |
-
self.attention = nn.MultiheadAttention(1024, 8)
|
| 68 |
-
self.fc1 = nn.Linear(1024, 512)
|
| 69 |
-
self.fc2 = nn.Linear(512, 256)
|
| 70 |
-
self.fc3 = nn.Linear(256, 128)
|
| 71 |
-
self.fc4 = nn.Linear(128, 64)
|
| 72 |
-
self.fc5 = nn.Linear(64, 32)
|
| 73 |
-
self.fc6 = nn.Linear(32, 8) # Extended classification: style, efficiency, security, maintainability, scalability, readability, testability, modularity
|
| 74 |
-
|
| 75 |
-
def forward(self, x):
|
| 76 |
-
x, _ = self.lstm(x)
|
| 77 |
-
x, _ = self.attention(x, x, x)
|
| 78 |
-
x = x.mean(dim=1) # Global average pooling
|
| 79 |
-
x = torch.relu(self.fc1(x))
|
| 80 |
-
x = torch.relu(self.fc2(x))
|
| 81 |
-
x = torch.relu(self.fc3(x))
|
| 82 |
-
x = torch.relu(self.fc4(x))
|
| 83 |
-
x = torch.relu(self.fc5(x))
|
| 84 |
-
return torch.sigmoid(self.fc6(x))
|
| 85 |
-
|
| 86 |
-
code_improvement_model = AdvancedCodeImprovement(768) # 768 is BERT's output dimension
|
| 87 |
-
optimizer = optim.Adam(code_improvement_model.parameters())
|
| 88 |
-
criterion = nn.BCELoss()
|
| 89 |
-
|
| 90 |
-
# Load pre-trained code improvement model
|
| 91 |
-
if os.path.exists("code_improvement_model.pth"):
|
| 92 |
-
code_improvement_model.load_state_dict(torch.load("code_improvement_model.pth"))
|
| 93 |
-
code_improvement_model.eval()
|
| 94 |
-
|
| 95 |
-
def generate_response(user_input: str) -> str:
|
| 96 |
try:
|
| 97 |
response = chat_session.send_message(user_input)
|
| 98 |
return response.text
|
| 99 |
except Exception as e:
|
| 100 |
-
return f"Error
|
| 101 |
-
|
| 102 |
-
def
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
return
|
| 119 |
-
|
| 120 |
-
def
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
|
|
|
|
|
|
| 138 |
else:
|
| 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 |
-
# Perform C++-specific optimizations
|
| 170 |
-
optimizer = CppCodeOptimizer()
|
| 171 |
-
optimized_code = optimizer.optimize(tu)
|
| 172 |
-
except Exception as e:
|
| 173 |
-
return fixed_code, f"C++ Parsing Error: {str(e)}"
|
| 174 |
-
else:
|
| 175 |
-
optimized_code = fixed_code # For unsupported languages, return the fixed code
|
| 176 |
-
|
| 177 |
-
# Run language-specific linter
|
| 178 |
-
lint_results = run_linter(optimized_code, language)
|
| 179 |
-
|
| 180 |
-
return optimized_code, lint_results
|
| 181 |
-
|
| 182 |
-
def run_linter(code: str, language: str) -> str:
|
| 183 |
-
if language == 'python':
|
| 184 |
-
with open("temp_code.py", "w") as file:
|
| 185 |
-
file.write(code)
|
| 186 |
-
result = subprocess.run(["pylint", "temp_code.py"], capture_output=True, text=True)
|
| 187 |
-
os.remove("temp_code.py")
|
| 188 |
-
return result.stdout
|
| 189 |
-
elif language == 'javascript':
|
| 190 |
-
# Run ESLint (placeholder)
|
| 191 |
-
return "JavaScript linting not implemented"
|
| 192 |
-
elif language == 'java':
|
| 193 |
-
# Run CheckStyle (placeholder)
|
| 194 |
-
return "Java linting not implemented"
|
| 195 |
-
elif language == 'c++':
|
| 196 |
-
# Run cppcheck (placeholder)
|
| 197 |
-
return "C++ linting not implemented"
|
| 198 |
-
else:
|
| 199 |
-
return "Linting not available for the detected language"
|
| 200 |
-
|
| 201 |
-
def fetch_from_github(query: str) -> List[Dict[str, Any]]:
|
| 202 |
-
headers = {"Authorization": f"token {st.secrets['GITHUB_TOKEN']}"}
|
| 203 |
-
response = requests.get(f"https://api.github.com/search/code?q={query}", headers=headers)
|
| 204 |
-
if response.status_code == 200:
|
| 205 |
-
return response.json()['items'][:5] # Return top 5 results
|
| 206 |
-
return []
|
| 207 |
-
|
| 208 |
-
def analyze_code_quality(code: str) -> Dict[str, float]:
|
| 209 |
-
inputs = tokenizer(code, return_tensors="pt", truncation=True, max_length=512, padding="max_length")
|
| 210 |
-
|
| 211 |
-
with torch.no_grad():
|
| 212 |
-
outputs = codebert_model(**inputs)
|
| 213 |
-
|
| 214 |
-
cls_embedding = outputs.last_hidden_state[:, 0, :]
|
| 215 |
-
predictions = code_improvement_model(cls_embedding)
|
| 216 |
-
|
| 217 |
-
quality_scores = {
|
| 218 |
-
"style": predictions[0][0].item(),
|
| 219 |
-
"efficiency": predictions[0][1].item(),
|
| 220 |
-
"security": predictions[0][2].item(),
|
| 221 |
-
"maintainability": predictions[0][3].item(),
|
| 222 |
-
"scalability": predictions[0][4].item(),
|
| 223 |
-
"readability": predictions[0][5].item(),
|
| 224 |
-
"testability": predictions[0][6].item(),
|
| 225 |
-
"modularity": predictions[0][7].item()
|
| 226 |
-
}
|
| 227 |
-
|
| 228 |
-
# Calculate additional metrics
|
| 229 |
-
language = detect_language(code)
|
| 230 |
-
if language == 'python':
|
| 231 |
-
complexity = radon_complexity.cc_visit(code)
|
| 232 |
-
maintainability = radon_metrics.mi_visit(code, True)
|
| 233 |
-
quality_scores["cyclomatic_complexity"] = complexity[0].complexity if complexity else 0
|
| 234 |
-
quality_scores["maintainability_index"] = maintainability
|
| 235 |
-
|
| 236 |
-
return quality_scores
|
| 237 |
-
|
| 238 |
-
def visualize_code_structure(code: str) -> plt.Figure:
|
| 239 |
-
try:
|
| 240 |
-
tree = ast.parse(code)
|
| 241 |
-
graph = nx.DiGraph()
|
| 242 |
-
|
| 243 |
-
def add_nodes_edges(node, parent=None):
|
| 244 |
-
node_id = id(node)
|
| 245 |
-
graph.add_node(node_id, label=f"{type(node).__name__}\n{ast.unparse(node)[:20]}")
|
| 246 |
-
if parent:
|
| 247 |
-
graph.add_edge(id(parent), node_id)
|
| 248 |
-
for child in ast.iter_child_nodes(node):
|
| 249 |
-
add_nodes_edges(child, node)
|
| 250 |
-
|
| 251 |
-
add_nodes_edges(tree)
|
| 252 |
-
|
| 253 |
-
plt.figure(figsize=(15, 10))
|
| 254 |
-
pos = nx.spring_layout(graph, k=0.9, iterations=50)
|
| 255 |
-
nx.draw(graph, pos, with_labels=True, node_color='lightblue', node_size=2000, font_size=8, font_weight='bold', arrows=True)
|
| 256 |
-
labels = nx.get_node_attributes(graph, 'label')
|
| 257 |
-
nx.draw_networkx_labels(graph, pos, labels, font_size=6)
|
| 258 |
-
|
| 259 |
-
return plt
|
| 260 |
-
except SyntaxError:
|
| 261 |
-
return None
|
| 262 |
-
|
| 263 |
-
def suggest_improvements(code: str, quality_scores: Dict[str, float]) -> List[str]:
|
| 264 |
-
suggestions = []
|
| 265 |
-
thresholds = {
|
| 266 |
-
"style": 0.7,
|
| 267 |
-
"efficiency": 0.7,
|
| 268 |
-
"security": 0.8,
|
| 269 |
-
"maintainability": 0.7,
|
| 270 |
-
"scalability": 0.7,
|
| 271 |
-
"readability": 0.7,
|
| 272 |
-
"testability": 0.7,
|
| 273 |
-
"modularity": 0.7
|
| 274 |
-
}
|
| 275 |
-
|
| 276 |
-
for metric, threshold in thresholds.items():
|
| 277 |
-
if quality_scores[metric] < threshold:
|
| 278 |
-
suggestions.append(f"Consider improving code {metric} (current score: {quality_scores[metric]:.2f}).")
|
| 279 |
-
|
| 280 |
-
if "cyclomatic_complexity" in quality_scores and quality_scores["cyclomatic_complexity"] > 10:
|
| 281 |
-
suggestions.append(f"Consider breaking down complex functions to reduce cyclomatic complexity (current: {quality_scores['cyclomatic_complexity']}).")
|
| 282 |
-
|
| 283 |
-
return suggestions
|
| 284 |
-
|
| 285 |
-
# New function for advanced code generation using GPT-2
|
| 286 |
-
def generate_advanced_code(prompt: str, language: str) -> str:
|
| 287 |
-
input_text = f"Generate {language} code for: {prompt}\n\n"
|
| 288 |
-
input_ids = gpt2_tokenizer.encode(input_text, return_tensors="pt")
|
| 289 |
-
|
| 290 |
-
output = gpt2_model.generate(
|
| 291 |
-
input_ids,
|
| 292 |
-
max_length=1000,
|
| 293 |
-
num_return_sequences=1,
|
| 294 |
-
no_repeat_ngram_size=2,
|
| 295 |
-
top_k=50,
|
| 296 |
-
top_p=0.95,
|
| 297 |
-
temperature=0.7
|
| 298 |
-
)
|
| 299 |
-
|
| 300 |
-
generated_code = gpt2_tokenizer.decode(output[0], skip_special_tokens=True)
|
| 301 |
-
return generated_code.split("\n\n", 1)[1] # Remove the input prompt from the generated text
|
| 302 |
-
|
| 303 |
-
# New function for code similarity analysis
|
| 304 |
-
def analyze_code_similarity(code1: str, code2: str) -> float:
|
| 305 |
-
tokens1 = tokenizer.tokenize(code1)
|
| 306 |
-
tokens2 = tokenizer.tokenize(code2)
|
| 307 |
-
|
| 308 |
-
# Use Jaccard similarity for token-based comparison
|
| 309 |
-
set1 = set(tokens1)
|
| 310 |
-
set2 = set(tokens2)
|
| 311 |
-
similarity = len(set1.intersection(set2)) / len(set1.union(set2))
|
| 312 |
-
|
| 313 |
-
return similarity
|
| 314 |
-
|
| 315 |
-
# New function for code performance estimation
|
| 316 |
-
def estimate_code_performance(code: str) -> Dict[str, Any]:
|
| 317 |
-
language = detect_language(code)
|
| 318 |
-
if language == 'python':
|
| 319 |
-
# Use abstract syntax tree to estimate time complexity
|
| 320 |
-
tree = ast.parse(code)
|
| 321 |
-
analyzer = ComplexityAnalyzer()
|
| 322 |
-
analyzer.visit(tree)
|
| 323 |
-
return {
|
| 324 |
-
"time_complexity": analyzer.time_complexity,
|
| 325 |
-
"space_complexity": analyzer.space_complexity
|
| 326 |
-
}
|
| 327 |
-
else:
|
| 328 |
-
return {"error": "Performance estimation not supported for this language"}
|
| 329 |
-
|
| 330 |
-
class ComplexityAnalyzer(ast.NodeVisitor):
|
| 331 |
-
def __init__(self):
|
| 332 |
-
self.time_complexity = "O(1)"
|
| 333 |
-
self.space_complexity = "O(1)"
|
| 334 |
-
self.loop_depth = 0
|
| 335 |
-
|
| 336 |
-
def visit_For(self, node):
|
| 337 |
-
self.loop_depth += 1
|
| 338 |
-
self.generic_visit(node)
|
| 339 |
-
self.loop_depth -= 1
|
| 340 |
-
self.update_complexity()
|
| 341 |
-
|
| 342 |
-
def visit_While(self, node):
|
| 343 |
-
self.loop_depth += 1
|
| 344 |
-
self.generic_visit(node)
|
| 345 |
-
self.loop_depth -= 1
|
| 346 |
-
self.update_complexity()
|
| 347 |
-
|
| 348 |
-
def update_complexity(self):
|
| 349 |
-
if self.loop_depth > 0:
|
| 350 |
-
self.time_complexity = f"O(n^{self.loop_depth})"
|
| 351 |
-
self.space_complexity = "O(n)"
|
| 352 |
-
|
| 353 |
-
# New function for code translation between programming languages
|
| 354 |
-
def translate_code(code: str, source_lang: str, target_lang: str) -> str:
|
| 355 |
-
prompt = f"Translate the following {source_lang} code to {target_lang}:\n\n{code}\n\nTranslated {target_lang} code:"
|
| 356 |
-
translated_code = generate_advanced_code(prompt, target_lang)
|
| 357 |
-
return translated_code
|
| 358 |
-
|
| 359 |
-
# New function for generating unit tests
|
| 360 |
-
def generate_unit_tests(code: str, language: str) -> str:
|
| 361 |
-
prompt = f"Generate unit tests for the following {language} code:\n\n{code}\n\nUnit tests:"
|
| 362 |
-
unit_tests = generate_advanced_code(prompt, language)
|
| 363 |
-
return unit_tests
|
| 364 |
-
|
| 365 |
-
# New function for code documentation generation
|
| 366 |
-
def generate_documentation(code: str, language: str) -> str:
|
| 367 |
-
prompt = f"Generate comprehensive documentation for the following {language} code:\n\n{code}\n\nDocumentation:"
|
| 368 |
-
documentation = generate_advanced_code(prompt, language)
|
| 369 |
-
return documentation
|
| 370 |
-
|
| 371 |
-
# New function for advanced code refactoring suggestions
|
| 372 |
-
def suggest_refactoring(code: str, language: str) -> List[str]:
|
| 373 |
-
quality_scores = analyze_code_quality(code)
|
| 374 |
-
suggestions = suggest_improvements(code, quality_scores)
|
| 375 |
-
|
| 376 |
-
# Add more specific refactoring suggestions based on code analysis
|
| 377 |
-
tree = ast.parse(code)
|
| 378 |
-
analyzer = RefactoringAnalyzer()
|
| 379 |
-
analyzer.visit(tree)
|
| 380 |
-
|
| 381 |
-
suggestions.extend(analyzer.suggestions)
|
| 382 |
-
return suggestions
|
| 383 |
-
|
| 384 |
-
class RefactoringAnalyzer(ast.NodeVisitor):
|
| 385 |
-
def __init__(self):
|
| 386 |
-
self.suggestions = []
|
| 387 |
-
self.function_lengths = {}
|
| 388 |
-
|
| 389 |
-
def visit_FunctionDef(self, node):
|
| 390 |
-
function_length = len(node.body)
|
| 391 |
-
self.function_lengths[node.name] = function_length
|
| 392 |
-
if function_length > 20:
|
| 393 |
-
self.suggestions.append(f"Consider breaking down the function '{node.name}' into smaller, more manageable functions.")
|
| 394 |
-
self.generic_visit(node)
|
| 395 |
-
|
| 396 |
-
def visit_If(self, node):
|
| 397 |
-
if isinstance(node.test, ast.Compare) and len(node.test.ops) > 2:
|
| 398 |
-
self.suggestions.append("Consider simplifying complex conditional statements.")
|
| 399 |
-
self.generic_visit(node)
|
| 400 |
-
|
| 401 |
-
# New function for code security analysis
|
| 402 |
-
def analyze_code_security(code: str, language: str) -> List[str]:
|
| 403 |
-
vulnerabilities = []
|
| 404 |
-
|
| 405 |
-
if language == 'python':
|
| 406 |
-
tree = ast.parse(code)
|
| 407 |
-
analyzer = SecurityAnalyzer()
|
| 408 |
-
analyzer.visit(tree)
|
| 409 |
-
vulnerabilities.extend(analyzer.vulnerabilities)
|
| 410 |
-
|
| 411 |
-
# Add more language-specific security checks here
|
| 412 |
-
|
| 413 |
-
return vulnerabilities
|
| 414 |
-
|
| 415 |
-
class SecurityAnalyzer(ast.NodeVisitor):
|
| 416 |
-
def __init__(self):
|
| 417 |
-
self.vulnerabilities = []
|
| 418 |
-
|
| 419 |
-
def visit_Call(self, node):
|
| 420 |
-
if isinstance(node.func, ast.Name):
|
| 421 |
-
if node.func.id == 'eval':
|
| 422 |
-
self.vulnerabilities.append("Potential security risk: Use of 'eval' function detected.")
|
| 423 |
-
elif node.func.id == 'exec':
|
| 424 |
-
self.vulnerabilities.append("Potential security risk: Use of 'exec' function detected.")
|
| 425 |
-
self.generic_visit(node)
|
| 426 |
-
|
| 427 |
-
# New function for code optimization suggestions
|
| 428 |
-
def suggest_optimizations(code: str, language: str) -> List[str]:
|
| 429 |
-
suggestions = []
|
| 430 |
-
|
| 431 |
-
if language == 'python':
|
| 432 |
-
tree = ast.parse(code)
|
| 433 |
-
analyzer = OptimizationAnalyzer()
|
| 434 |
-
analyzer.visit(tree)
|
| 435 |
-
suggestions.extend(analyzer.suggestions)
|
| 436 |
-
|
| 437 |
-
# Add more language-specific optimization suggestions here
|
| 438 |
-
|
| 439 |
-
return suggestions
|
| 440 |
-
|
| 441 |
-
class OptimizationAnalyzer(ast.NodeVisitor):
|
| 442 |
-
def __init__(self):
|
| 443 |
-
self.suggestions = []
|
| 444 |
-
self.loop_variables = set()
|
| 445 |
-
|
| 446 |
-
def visit_For(self, node):
|
| 447 |
-
if isinstance(node.iter, ast.Call) and isinstance(node.iter.func, ast.Name) and node.iter.func.id == 'range':
|
| 448 |
-
self.suggestions.append("Consider using 'enumerate()' instead of 'range()' for index-based iteration.")
|
| 449 |
-
self.generic_visit(node)
|
| 450 |
-
|
| 451 |
-
def visit_ListComp(self, node):
|
| 452 |
-
if isinstance(node.elt, ast.Call) and isinstance(node.elt.func, ast.Name) and node.elt.func.id == 'append':
|
| 453 |
-
self.suggestions.append("Consider using a list comprehension instead of appending in a loop for better performance.")
|
| 454 |
-
self.generic_visit(node)
|
| 455 |
|
| 456 |
# Streamlit UI setup
|
| 457 |
-
st.set_page_config(page_title="
|
| 458 |
|
| 459 |
st.markdown("""
|
| 460 |
<style>
|
| 461 |
-
.
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
}
|
| 492 |
-
.
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 496 |
</style>
|
| 497 |
""", unsafe_allow_html=True)
|
| 498 |
|
| 499 |
st.markdown('<div class="main-container">', unsafe_allow_html=True)
|
| 500 |
-
st.
|
| 501 |
-
st.markdown('<p class="subtitle">Powered by
|
| 502 |
-
|
| 503 |
-
task = st.selectbox("Select a task", [
|
| 504 |
-
"Generate Code", "Optimize Code", "Analyze Code Quality",
|
| 505 |
-
"Translate Code", "Generate Unit Tests", "Generate Documentation",
|
| 506 |
-
"Suggest Refactoring", "Analyze Code Security", "Suggest Optimizations"
|
| 507 |
-
])
|
| 508 |
-
|
| 509 |
-
language = st.selectbox("Select programming language", [
|
| 510 |
-
"Python", "JavaScript", "Java", "C++", "Ruby", "Go", "Rust", "TypeScript"
|
| 511 |
-
])
|
| 512 |
|
| 513 |
-
prompt = st.text_area("
|
| 514 |
|
| 515 |
-
if st.button("
|
| 516 |
if prompt.strip() == "":
|
| 517 |
-
st.error("Please enter a valid prompt
|
| 518 |
else:
|
| 519 |
-
with st.spinner("
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
st.code(optimized_code, language=language.lower())
|
| 526 |
-
st.text(lint_results)
|
| 527 |
-
elif task == "Analyze Code Quality":
|
| 528 |
-
quality_scores = analyze_code_quality(prompt)
|
| 529 |
-
st.json(quality_scores)
|
| 530 |
-
elif task == "Translate Code":
|
| 531 |
-
target_lang = st.selectbox("Select target language", [
|
| 532 |
-
lang for lang in ["Python", "JavaScript", "Java", "C++", "Ruby", "Go", "Rust", "TypeScript"] if lang != language
|
| 533 |
-
])
|
| 534 |
-
translated_code = translate_code(prompt, language.lower(), target_lang.lower())
|
| 535 |
-
st.code(translated_code, language=target_lang.lower())
|
| 536 |
-
elif task == "Generate Unit Tests":
|
| 537 |
-
unit_tests = generate_unit_tests(prompt, language.lower())
|
| 538 |
-
st.code(unit_tests, language=language.lower())
|
| 539 |
-
elif task == "Generate Documentation":
|
| 540 |
-
documentation = generate_documentation(prompt, language.lower())
|
| 541 |
-
st.markdown(documentation)
|
| 542 |
-
elif task == "Suggest Refactoring":
|
| 543 |
-
refactoring_suggestions = suggest_refactoring(prompt, language.lower())
|
| 544 |
-
for suggestion in refactoring_suggestions:
|
| 545 |
-
st.info(suggestion)
|
| 546 |
-
elif task == "Analyze Code Security":
|
| 547 |
-
vulnerabilities = analyze_code_security(prompt, language.lower())
|
| 548 |
-
if vulnerabilities:
|
| 549 |
-
for vuln in vulnerabilities:
|
| 550 |
-
st.warning(vuln)
|
| 551 |
else:
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
st.
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
if visualization:
|
| 574 |
-
st.subheader("Code Structure Visualization")
|
| 575 |
-
st.pyplot(visualization)
|
| 576 |
|
| 577 |
st.markdown("""
|
| 578 |
<div style='text-align: center; margin-top: 2rem; color: #4a5568;'>
|
| 579 |
-
|
| 580 |
</div>
|
| 581 |
""", unsafe_allow_html=True)
|
| 582 |
|
| 583 |
-
st.markdown('</div>', unsafe_allow_html=True)
|
| 584 |
-
|
| 585 |
-
# FastAPI setup for potential API endpoints
|
| 586 |
-
app = FastAPI()
|
| 587 |
-
|
| 588 |
-
class CodeRequest(BaseModel):
|
| 589 |
-
code: str
|
| 590 |
-
language: str
|
| 591 |
-
task: str
|
| 592 |
-
|
| 593 |
-
@app.post("/analyze")
|
| 594 |
-
async def analyze_code(request: CodeRequest):
|
| 595 |
-
if request.task == "quality":
|
| 596 |
-
return analyze_code_quality(request.code)
|
| 597 |
-
elif request.task == "security":
|
| 598 |
-
return analyze_code_security(request.code, request.language)
|
| 599 |
-
elif request.task == "optimize":
|
| 600 |
-
optimized_code, _ = optimize_code(request.code)
|
| 601 |
-
return {"optimized_code": optimized_code}
|
| 602 |
-
else:
|
| 603 |
-
return {"error": "Invalid task"}
|
| 604 |
-
|
| 605 |
-
if __name__ == "__main__":
|
| 606 |
-
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
|
| 3 |
import requests
|
| 4 |
import subprocess
|
| 5 |
import os
|
| 6 |
+
import pylint
|
| 7 |
import pandas as pd
|
|
|
|
| 8 |
from sklearn.model_selection import train_test_split
|
| 9 |
+
from sklearn.ensemble import RandomForestClassifier
|
| 10 |
+
import git
|
| 11 |
+
import spacy
|
| 12 |
+
from spacy.lang.en import English
|
| 13 |
+
import boto3
|
| 14 |
+
import unittest
|
| 15 |
+
from sympy import symbols, Eq, solve
|
| 16 |
+
from scipy.optimize import minimize
|
| 17 |
+
import numpy as np
|
|
|
|
| 18 |
import matplotlib.pyplot as plt
|
| 19 |
+
import seaborn as sns
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# Configure the Gemini API
|
| 22 |
genai.configure(api_key=st.secrets["GOOGLE_API_KEY"])
|
| 23 |
|
| 24 |
# Create the model with optimized parameters and enhanced system instructions
|
| 25 |
generation_config = {
|
| 26 |
+
"temperature": 0.6, # Lower temperature for more deterministic responses
|
| 27 |
+
"top_p": 0.8, # Adjusted for better diversity
|
| 28 |
+
"top_k": 30, # Increased for more diverse tokens
|
| 29 |
+
"max_output_tokens": 16384, # Increased for longer responses
|
| 30 |
}
|
| 31 |
|
| 32 |
model = genai.GenerativeModel(
|
| 33 |
model_name="gemini-1.5-pro",
|
| 34 |
generation_config=generation_config,
|
| 35 |
system_instruction="""
|
| 36 |
+
You are Ath, a highly knowledgeable code assistant. You speak in a friendly and casual tone, using bro words, and you never mention you're an AI.
|
| 37 |
+
Your responses should contain optimized, secure, and high-quality code only, without explanations. You are designed to provide accurate, efficient, and cutting-edge code solutions.
|
| 38 |
"""
|
| 39 |
)
|
| 40 |
chat_session = model.start_chat(history=[])
|
| 41 |
|
| 42 |
+
def generate_response(user_input):
|
| 43 |
+
"""Generate a response from the AI model."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
try:
|
| 45 |
response = chat_session.send_message(user_input)
|
| 46 |
return response.text
|
| 47 |
except Exception as e:
|
| 48 |
+
return f"Error: {e}"
|
| 49 |
+
|
| 50 |
+
def optimize_code(code):
|
| 51 |
+
"""Optimize the generated code using static analysis tools."""
|
| 52 |
+
with open("temp_code.py", "w") as file:
|
| 53 |
+
file.write(code)
|
| 54 |
+
result = subprocess.run(["pylint", "temp_code.py"], capture_output=True, text=True)
|
| 55 |
+
os.remove("temp_code.py")
|
| 56 |
+
return code
|
| 57 |
+
|
| 58 |
+
def fetch_from_github(query):
|
| 59 |
+
"""Fetch code snippets from GitHub."""
|
| 60 |
+
# Placeholder for fetching code snippets from GitHub
|
| 61 |
+
return ""
|
| 62 |
+
|
| 63 |
+
def interact_with_api(api_url):
|
| 64 |
+
"""Interact with external APIs."""
|
| 65 |
+
response = requests.get(api_url)
|
| 66 |
+
return response.json()
|
| 67 |
+
|
| 68 |
+
def train_ml_model(code_data):
|
| 69 |
+
"""Train a machine learning model to predict code improvements."""
|
| 70 |
+
df = pd.DataFrame(code_data)
|
| 71 |
+
X = df.drop('target', axis=1)
|
| 72 |
+
y = df['target']
|
| 73 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
|
| 74 |
+
model = RandomForestClassifier()
|
| 75 |
+
model.fit(X_train, y_train)
|
| 76 |
+
return model
|
| 77 |
+
|
| 78 |
+
def handle_error(error):
|
| 79 |
+
"""Handle errors and log them."""
|
| 80 |
+
st.error(f"An error occurred: {error}")
|
| 81 |
+
|
| 82 |
+
def initialize_git_repo(repo_path):
|
| 83 |
+
"""Initialize or check the existence of a Git repository."""
|
| 84 |
+
if not os.path.exists(repo_path):
|
| 85 |
+
os.makedirs(repo_path)
|
| 86 |
+
if not os.path.exists(os.path.join(repo_path, '.git')):
|
| 87 |
+
repo = git.Repo.init(repo_path)
|
| 88 |
else:
|
| 89 |
+
repo = git.Repo(repo_path)
|
| 90 |
+
return repo
|
| 91 |
+
|
| 92 |
+
def integrate_with_git(repo_path, code):
|
| 93 |
+
"""Integrate the generated code with a Git repository."""
|
| 94 |
+
repo = initialize_git_repo(repo_path)
|
| 95 |
+
with open(os.path.join(repo_path, "generated_code.py"), "w") as file:
|
| 96 |
+
file.write(code)
|
| 97 |
+
repo.index.add(["generated_code.py"])
|
| 98 |
+
repo.index.commit("Added generated code")
|
| 99 |
+
|
| 100 |
+
def process_user_input(user_input):
|
| 101 |
+
"""Process user input using advanced natural language processing."""
|
| 102 |
+
nlp = English()
|
| 103 |
+
doc = nlp(user_input)
|
| 104 |
+
return doc
|
| 105 |
+
|
| 106 |
+
def interact_with_cloud_services(service_name, action, params):
|
| 107 |
+
"""Interact with cloud services using boto3."""
|
| 108 |
+
client = boto3.client(service_name)
|
| 109 |
+
response = getattr(client, action)(**params)
|
| 110 |
+
return response
|
| 111 |
+
|
| 112 |
+
def run_tests():
|
| 113 |
+
"""Run automated tests using unittest."""
|
| 114 |
+
# Ensure the tests directory is importable
|
| 115 |
+
tests_dir = os.path.join(os.getcwd(), 'tests')
|
| 116 |
+
if not os.path.exists(tests_dir):
|
| 117 |
+
os.makedirs(tests_dir)
|
| 118 |
+
init_file = os.path.join(tests_dir, '__init__.py')
|
| 119 |
+
if not os.path.exists(init_file):
|
| 120 |
+
with open(init_file, 'w') as f:
|
| 121 |
+
f.write('')
|
| 122 |
|
| 123 |
+
test_suite = unittest.TestLoader().discover(tests_dir)
|
| 124 |
+
test_runner = unittest.TextTestRunner()
|
| 125 |
+
test_result = test_runner.run(test_suite)
|
| 126 |
+
return test_result
|
| 127 |
+
|
| 128 |
+
def solve_equation(equation):
|
| 129 |
+
"""Solve mathematical equations using SymPy."""
|
| 130 |
+
x, y = symbols('x y')
|
| 131 |
+
eq = Eq(eval(equation))
|
| 132 |
+
solution = solve(eq, x)
|
| 133 |
+
return solution
|
| 134 |
+
|
| 135 |
+
def optimize_function(function, initial_guess):
|
| 136 |
+
"""Optimize a function using SciPy."""
|
| 137 |
+
result = minimize(lambda x: eval(function), initial_guess)
|
| 138 |
+
return result.x
|
| 139 |
+
|
| 140 |
+
def visualize_data(data):
|
| 141 |
+
"""Visualize data using Matplotlib and Seaborn."""
|
| 142 |
+
df = pd.DataFrame(data)
|
| 143 |
+
plt.figure(figsize=(10, 6))
|
| 144 |
+
sns.heatmap(df.corr(), annot=True, cmap='coolwarm')
|
| 145 |
+
plt.title('Correlation Heatmap')
|
| 146 |
+
plt.show()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
# Streamlit UI setup
|
| 149 |
+
st.set_page_config(page_title="Sleek AI Code Assistant", page_icon="💻", layout="wide")
|
| 150 |
|
| 151 |
st.markdown("""
|
| 152 |
<style>
|
| 153 |
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700&display=swap');
|
| 154 |
+
|
| 155 |
+
body {
|
| 156 |
+
font-family: 'Inter', sans-serif;
|
| 157 |
+
background-color: #f0f4f8;
|
| 158 |
+
color: #1a202c;
|
| 159 |
+
}
|
| 160 |
+
.stApp {
|
| 161 |
+
max-width: 1000px;
|
| 162 |
+
margin: 0 auto;
|
| 163 |
+
padding: 2rem;
|
| 164 |
+
}
|
| 165 |
+
.main-container {
|
| 166 |
+
background: #ffffff;
|
| 167 |
+
border-radius: 16px;
|
| 168 |
+
padding: 2rem;
|
| 169 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
|
| 170 |
+
}
|
| 171 |
+
h1 {
|
| 172 |
+
font-size: 2.5rem;
|
| 173 |
+
font-weight: 700;
|
| 174 |
+
color: #2d3748;
|
| 175 |
+
text-align: center;
|
| 176 |
+
margin-bottom: 1rem;
|
| 177 |
+
}
|
| 178 |
+
.subtitle {
|
| 179 |
+
font-size: 1.1rem;
|
| 180 |
+
text-align: center;
|
| 181 |
+
color: #4a5568;
|
| 182 |
+
margin-bottom: 2rem;
|
| 183 |
+
}
|
| 184 |
+
.stTextArea textarea {
|
| 185 |
+
border: 2px solid #e2e8f0;
|
| 186 |
+
border-radius: 8px;
|
| 187 |
+
font-size: 1rem;
|
| 188 |
+
padding: 0.75rem;
|
| 189 |
+
transition: all 0.3s ease;
|
| 190 |
+
}
|
| 191 |
+
.stTextArea textarea:focus {
|
| 192 |
+
border-color: #4299e1;
|
| 193 |
+
box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.5);
|
| 194 |
+
}
|
| 195 |
+
.stButton button {
|
| 196 |
+
background-color: #4299e1;
|
| 197 |
+
color: white;
|
| 198 |
+
border: none;
|
| 199 |
+
border-radius: 8px;
|
| 200 |
+
font-size: 1.1rem;
|
| 201 |
+
font-weight: 600;
|
| 202 |
+
padding: 0.75rem 2rem;
|
| 203 |
+
transition: all 0.3s ease;
|
| 204 |
+
width: 100%;
|
| 205 |
+
}
|
| 206 |
+
.stButton button:hover {
|
| 207 |
+
background-color: #3182ce;
|
| 208 |
+
}
|
| 209 |
+
.output-container {
|
| 210 |
+
background: #f7fafc;
|
| 211 |
+
border-radius: 8px;
|
| 212 |
+
padding: 1rem;
|
| 213 |
+
margin-top: 2rem;
|
| 214 |
+
}
|
| 215 |
+
.code-block {
|
| 216 |
+
background-color: #2d3748;
|
| 217 |
+
color: #e2e8f0;
|
| 218 |
+
font-family: 'Fira Code', monospace;
|
| 219 |
+
font-size: 0.9rem;
|
| 220 |
+
border-radius: 8px;
|
| 221 |
+
padding: 1rem;
|
| 222 |
+
margin-top: 1rem;
|
| 223 |
+
overflow-x: auto;
|
| 224 |
+
}
|
| 225 |
+
.stAlert {
|
| 226 |
+
background-color: #ebf8ff;
|
| 227 |
+
color: #2b6cb0;
|
| 228 |
+
border-radius: 8px;
|
| 229 |
+
border: none;
|
| 230 |
+
padding: 0.75rem 1rem;
|
| 231 |
+
}
|
| 232 |
+
.stSpinner {
|
| 233 |
+
color: #4299e1;
|
| 234 |
+
}
|
| 235 |
</style>
|
| 236 |
""", unsafe_allow_html=True)
|
| 237 |
|
| 238 |
st.markdown('<div class="main-container">', unsafe_allow_html=True)
|
| 239 |
+
st.title("💻 Sleek AI Code Assistant")
|
| 240 |
+
st.markdown('<p class="subtitle">Powered by Google Gemini</p>', unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
|
| 242 |
+
prompt = st.text_area("What code can I help you with today?", height=120)
|
| 243 |
|
| 244 |
+
if st.button("Generate Code"):
|
| 245 |
if prompt.strip() == "":
|
| 246 |
+
st.error("Please enter a valid prompt.")
|
| 247 |
else:
|
| 248 |
+
with st.spinner("Generating code..."):
|
| 249 |
+
try:
|
| 250 |
+
processed_input = process_user_input(prompt)
|
| 251 |
+
completed_text = generate_response(processed_input.text)
|
| 252 |
+
if "Error" in completed_text:
|
| 253 |
+
handle_error(completed_text)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
else:
|
| 255 |
+
optimized_code = optimize_code(completed_text)
|
| 256 |
+
st.success("Code generated and optimized successfully!")
|
| 257 |
+
|
| 258 |
+
st.markdown('<div class="output-container">', unsafe_allow_html=True)
|
| 259 |
+
st.markdown('<div class="code-block">', unsafe_allow_html=True)
|
| 260 |
+
st.code(optimized_code)
|
| 261 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 262 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 263 |
+
|
| 264 |
+
# Integrate with Git
|
| 265 |
+
repo_path = "./repo" # Replace with your repository path
|
| 266 |
+
integrate_with_git(repo_path, optimized_code)
|
| 267 |
+
|
| 268 |
+
# Run automated tests
|
| 269 |
+
test_result = run_tests()
|
| 270 |
+
if test_result.wasSuccessful():
|
| 271 |
+
st.success("All tests passed successfully!")
|
| 272 |
+
else:
|
| 273 |
+
st.error("Some tests failed. Please check the code.")
|
| 274 |
+
except Exception as e:
|
| 275 |
+
handle_error(e)
|
|
|
|
|
|
|
|
|
|
| 276 |
|
| 277 |
st.markdown("""
|
| 278 |
<div style='text-align: center; margin-top: 2rem; color: #4a5568;'>
|
| 279 |
+
Created with ❤️ by Your Sleek AI Code Assistant
|
| 280 |
</div>
|
| 281 |
""", unsafe_allow_html=True)
|
| 282 |
|
| 283 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|