Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -22,369 +22,157 @@ import sys
|
|
| 22 |
# Add current directory to path for imports
|
| 23 |
sys.path.append('.')
|
| 24 |
|
| 25 |
-
# Import Sheikh-Kitty components
|
| 26 |
-
from model.model_interfaces import (
|
| 27 |
-
ProductionModel,
|
| 28 |
-
FixedTokenizer,
|
| 29 |
-
SecurityVerifier,
|
| 30 |
-
CodeGenerationRequest,
|
| 31 |
-
CodeGenerationResponse
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
-
from api.api_endpoints import create_api_app
|
| 35 |
-
from sandbox.sandbox_exec import SandboxExecutor
|
| 36 |
-
from monitoring.monitoring import SystemMonitor
|
| 37 |
-
|
| 38 |
# Configure logging
|
| 39 |
logging.basicConfig(level=logging.INFO)
|
| 40 |
logger = logging.getLogger(__name__)
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
model = None
|
| 45 |
-
verifier = None
|
| 46 |
-
sandbox = None
|
| 47 |
-
monitor = None
|
| 48 |
-
|
| 49 |
-
def initialize_system():
|
| 50 |
-
"""Initialize all Sheikh-Kitty system components"""
|
| 51 |
-
global tokenizer, model, verifier, sandbox, monitor
|
| 52 |
-
|
| 53 |
-
logger.info("Initializing Sheikh-Kitty Space system...")
|
| 54 |
-
|
| 55 |
-
try:
|
| 56 |
-
# Initialize tokenizer
|
| 57 |
-
tokenizer = FixedTokenizer(vocab_size=32768)
|
| 58 |
-
logger.info("β Tokenizer initialized")
|
| 59 |
-
|
| 60 |
-
# Initialize model
|
| 61 |
-
model = ProductionModel(tokenizer=tokenizer)
|
| 62 |
-
logger.info("β Model initialized")
|
| 63 |
-
|
| 64 |
-
# Initialize security verifier
|
| 65 |
-
verifier = SecurityVerifier()
|
| 66 |
-
logger.info("β Security verifier initialized")
|
| 67 |
-
|
| 68 |
-
# Initialize sandbox executor
|
| 69 |
-
sandbox = SandboxExecutor()
|
| 70 |
-
logger.info("β Sandbox executor initialized")
|
| 71 |
-
|
| 72 |
-
# Initialize monitoring system
|
| 73 |
-
monitor = SystemMonitor()
|
| 74 |
-
logger.info("β Monitoring system initialized")
|
| 75 |
-
|
| 76 |
-
logger.info("π Sheikh-Kitty system initialized successfully!")
|
| 77 |
-
return True
|
| 78 |
-
|
| 79 |
-
except Exception as e:
|
| 80 |
-
logger.error(f"Failed to initialize system: {e}")
|
| 81 |
-
return False
|
| 82 |
-
|
| 83 |
-
def generate_code_with_security(prompt: str, language: str, max_tokens: int = 512) -> tuple:
|
| 84 |
-
"""
|
| 85 |
-
Generate code with security verification and sandbox execution
|
| 86 |
-
|
| 87 |
-
Returns: (generated_code, security_report, execution_result, error_message)
|
| 88 |
-
"""
|
| 89 |
-
start_time = time.time()
|
| 90 |
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
if not
|
| 94 |
-
return "
|
| 95 |
-
|
| 96 |
-
#
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
prompt
|
| 102 |
-
language=language.lower(),
|
| 103 |
-
max_length=max_tokens,
|
| 104 |
-
temperature=0.7,
|
| 105 |
-
security_level="strict"
|
| 106 |
-
)
|
| 107 |
-
|
| 108 |
-
# Generate code
|
| 109 |
-
logger.info(f"Generating {language} code for: {prompt[:50]}...")
|
| 110 |
-
response = model.generate_code(request)
|
| 111 |
-
|
| 112 |
-
if not response.success:
|
| 113 |
-
return "", {"error": "Code generation failed"}, {}, response.metadata.get('error', 'Unknown error')
|
| 114 |
-
|
| 115 |
-
# Security verification
|
| 116 |
-
logger.info("Running security verification...")
|
| 117 |
-
security_analysis = verifier.verify_code(response.code, language)
|
| 118 |
-
|
| 119 |
-
# Prepare security report
|
| 120 |
-
security_report = {
|
| 121 |
-
"safe": security_analysis.is_safe,
|
| 122 |
-
"security_score": security_analysis.security_score,
|
| 123 |
-
"threats_detected": len(security_analysis.threats),
|
| 124 |
-
"recommendations": security_analysis.recommendations,
|
| 125 |
-
"scan_timestamp": datetime.now().isoformat()
|
| 126 |
}
|
| 127 |
|
| 128 |
-
|
| 129 |
-
if not security_analysis.is_safe:
|
| 130 |
-
logger.warning(f"Security violation detected: {security_analysis.threats}")
|
| 131 |
-
return (
|
| 132 |
-
response.code,
|
| 133 |
-
security_report,
|
| 134 |
-
{"error": "Security violation - execution blocked"},
|
| 135 |
-
f"Security threats: {', '.join(security_analysis.threats)}"
|
| 136 |
-
)
|
| 137 |
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
# Prepare execution result
|
| 143 |
-
exec_result = {
|
| 144 |
-
"success": execution_result.success,
|
| 145 |
-
"execution_time": execution_result.execution_time,
|
| 146 |
-
"stdout": execution_result.stdout,
|
| 147 |
-
"stderr": execution_result.stderr,
|
| 148 |
-
"return_code": execution_result.return_code,
|
| 149 |
-
"memory_used": execution_result.memory_usage,
|
| 150 |
"timestamp": datetime.now().isoformat()
|
| 151 |
}
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
try:
|
| 166 |
-
if not all([verifier, sandbox]):
|
| 167 |
-
return {"error": "System not initialized"}
|
| 168 |
-
|
| 169 |
-
# Security scan
|
| 170 |
-
security_analysis = verifier.verify_code(code, language)
|
| 171 |
-
|
| 172 |
-
# Static analysis
|
| 173 |
-
static_analysis = verifier.static_analysis(code, language)
|
| 174 |
-
|
| 175 |
-
# Runtime analysis (sandbox)
|
| 176 |
-
execution_result = sandbox.execute_code(code, language)
|
| 177 |
|
| 178 |
return {
|
| 179 |
-
"
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
"threats": security_analysis.threats
|
| 183 |
-
},
|
| 184 |
-
"static_analysis": static_analysis,
|
| 185 |
-
"execution_result": {
|
| 186 |
-
"success": execution_result.success,
|
| 187 |
-
"output": execution_result.stdout,
|
| 188 |
-
"errors": execution_result.stderr,
|
| 189 |
-
"runtime": execution_result.execution_time
|
| 190 |
-
},
|
| 191 |
-
"suggestions": security_analysis.recommendations
|
| 192 |
}
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
def get_system_metrics() -> Dict[str, Any]:
|
| 198 |
-
"""Get current system performance metrics"""
|
| 199 |
-
try:
|
| 200 |
-
if not monitor:
|
| 201 |
-
return {"error": "Monitoring system not available"}
|
| 202 |
-
|
| 203 |
return {
|
| 204 |
-
"
|
| 205 |
-
"
|
| 206 |
-
"
|
| 207 |
-
"
|
| 208 |
-
"
|
| 209 |
-
"
|
| 210 |
}
|
| 211 |
-
except Exception as e:
|
| 212 |
-
return {"error": f"Metrics unavailable: {e}"}
|
| 213 |
-
|
| 214 |
-
# Initialize system on startup
|
| 215 |
-
system_ready = initialize_system()
|
| 216 |
-
|
| 217 |
-
# Define Gradio interface
|
| 218 |
-
def create_interface():
|
| 219 |
-
"""Create the Gradio interface for Sheikh-Kitty"""
|
| 220 |
|
| 221 |
-
#
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
color: #2E86C1;
|
| 231 |
-
margin-bottom: 30px;
|
| 232 |
-
}
|
| 233 |
-
.status-ready {
|
| 234 |
-
color: #27AE60;
|
| 235 |
-
font-weight: bold;
|
| 236 |
-
}
|
| 237 |
-
.status-error {
|
| 238 |
-
color: #E74C3C;
|
| 239 |
-
font-weight: bold;
|
| 240 |
-
}
|
| 241 |
-
"""
|
| 242 |
-
|
| 243 |
-
with gr.Blocks(css=css, title="Sheikh-Kitty Coding AI", theme=gr.themes.Soft()) as interface:
|
| 244 |
-
|
| 245 |
-
# Header
|
| 246 |
-
gr.HTML("""
|
| 247 |
-
<div class="container">
|
| 248 |
-
<div class="header">
|
| 249 |
-
<h1>π Sheikh-Kitty: Secure Autonomous Coding AI</h1>
|
| 250 |
-
<p>Production-ready AI coding assistant with security verification and sandbox execution</p>
|
| 251 |
-
<p><strong>Space:</strong> <a href="https://huggingface.co/spaces/likhonsheikh/sheikh-kitty" target="_blank">likhonsheikh/sheikh-kitty</a></p>
|
| 252 |
-
</div>
|
| 253 |
-
</div>
|
| 254 |
-
""")
|
| 255 |
-
|
| 256 |
-
# System Status
|
| 257 |
-
status_color = "status-ready" if system_ready else "status-error"
|
| 258 |
-
status_text = "π’ System Ready" if system_ready else "π΄ System Error"
|
| 259 |
-
|
| 260 |
-
gr.HTML(f"""
|
| 261 |
-
<div class="container">
|
| 262 |
-
<h3>System Status: <span class="{status_color}">{status_text}</span></h3>
|
| 263 |
-
</div>
|
| 264 |
-
""")
|
| 265 |
-
|
| 266 |
-
if system_ready:
|
| 267 |
-
# Main generation interface
|
| 268 |
-
with gr.Tab("β¨ Generate Code"):
|
| 269 |
with gr.Row():
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
language = gr.Dropdown(
|
| 277 |
-
choices=["Python", "JavaScript", "TypeScript", "Solidity"],
|
| 278 |
-
value="Python",
|
| 279 |
-
label="π οΈ Programming Language"
|
| 280 |
-
)
|
| 281 |
-
max_tokens = gr.Slider(
|
| 282 |
-
minimum=128,
|
| 283 |
-
maximum=1024,
|
| 284 |
-
value=512,
|
| 285 |
-
step=64,
|
| 286 |
-
label="π’ Max Tokens"
|
| 287 |
-
)
|
| 288 |
-
generate_btn = gr.Button("π Generate Code", variant="primary")
|
| 289 |
-
|
| 290 |
-
with gr.Column():
|
| 291 |
-
output_code = gr.Code(
|
| 292 |
-
label="π Generated Code",
|
| 293 |
-
language="python",
|
| 294 |
-
lines=15
|
| 295 |
-
)
|
| 296 |
-
security_report = gr.JSON(
|
| 297 |
-
label="π‘οΈ Security Analysis",
|
| 298 |
-
value={}
|
| 299 |
-
)
|
| 300 |
-
execution_result = gr.JSON(
|
| 301 |
-
label="β‘ Execution Results",
|
| 302 |
-
value={}
|
| 303 |
-
)
|
| 304 |
-
error_display = gr.Textbox(
|
| 305 |
-
label="β Errors/Warnings",
|
| 306 |
-
visible=False
|
| 307 |
-
)
|
| 308 |
-
|
| 309 |
-
# Code Debugging interface
|
| 310 |
-
with gr.Tab("π Debug Code"):
|
| 311 |
with gr.Row():
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
value="Python",
|
| 321 |
-
label="π οΈ Programming Language"
|
| 322 |
-
)
|
| 323 |
-
debug_btn = gr.Button("π Analyze Code", variant="secondary")
|
| 324 |
-
|
| 325 |
-
with gr.Column():
|
| 326 |
-
debug_output = gr.JSON(
|
| 327 |
-
label="π Debug Analysis",
|
| 328 |
-
value={}
|
| 329 |
-
)
|
| 330 |
-
|
| 331 |
-
# System Monitoring
|
| 332 |
-
with gr.Tab("π System Metrics"):
|
| 333 |
with gr.Row():
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
if system_ready:
|
| 343 |
-
generate_btn.click(
|
| 344 |
-
fn=generate_code_with_security,
|
| 345 |
-
inputs=[prompt, language, max_tokens],
|
| 346 |
-
outputs=[output_code, security_report, execution_result, error_display]
|
| 347 |
-
)
|
| 348 |
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
""
|
| 370 |
|
| 371 |
return interface
|
| 372 |
|
| 373 |
-
# Create and launch the
|
| 374 |
if __name__ == "__main__":
|
| 375 |
-
logger.info("Starting Sheikh-Kitty
|
| 376 |
|
| 377 |
-
|
| 378 |
-
interface = create_interface()
|
| 379 |
|
| 380 |
-
|
| 381 |
-
interface.launch(
|
| 382 |
server_name="0.0.0.0",
|
| 383 |
server_port=7860,
|
| 384 |
share=False,
|
|
|
|
| 385 |
debug=False,
|
| 386 |
quiet=True,
|
| 387 |
-
show_error=True,
|
| 388 |
-
inline=True,
|
| 389 |
inbrowser=False
|
| 390 |
-
)
|
|
|
|
| 22 |
# Add current directory to path for imports
|
| 23 |
sys.path.append('.')
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
# Configure logging
|
| 26 |
logging.basicConfig(level=logging.INFO)
|
| 27 |
logger = logging.getLogger(__name__)
|
| 28 |
|
| 29 |
+
def create_demo():
|
| 30 |
+
"""Create a simple demo interface"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
def generate_code(prompt, language):
|
| 33 |
+
"""Simple code generation demo"""
|
| 34 |
+
if not prompt:
|
| 35 |
+
return "Please enter a prompt", {}
|
| 36 |
+
|
| 37 |
+
# Simple demo responses
|
| 38 |
+
responses = {
|
| 39 |
+
"Python": f"# Generated Python code for: {prompt}\nprint('Hello, World!')\nresult = {prompt}\nprint(result)",
|
| 40 |
+
"JavaScript": f"// Generated JavaScript code for: {prompt}\nconsole.log('Hello, World!');\nlet result = {prompt};\nconsole.log(result);",
|
| 41 |
+
"TypeScript": f"// Generated TypeScript code for: {prompt}\nconsole.log('Hello, World!');\nconst result: any = {prompt};\nconsole.log(result);",
|
| 42 |
+
"Solidity": f"// Generated Solidity code for: {prompt}\npragma solidity ^0.8.0;\ncontract Demo {{\n function example() public {{\n // {prompt}\n }}\n}}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
}
|
| 44 |
|
| 45 |
+
code = responses.get(language, f"// Generated code for: {prompt}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
return code, {
|
| 48 |
+
"language": language,
|
| 49 |
+
"length": len(code),
|
| 50 |
+
"status": "success",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
"timestamp": datetime.now().isoformat()
|
| 52 |
}
|
| 53 |
+
|
| 54 |
+
def debug_code(code, language):
|
| 55 |
+
"""Simple code debugging demo"""
|
| 56 |
+
issues = []
|
| 57 |
+
|
| 58 |
+
if not code.strip():
|
| 59 |
+
issues.append("Empty code provided")
|
| 60 |
+
elif "TODO" in code:
|
| 61 |
+
issues.append("Contains TODO comments")
|
| 62 |
+
elif "print(" in code and language == "Python":
|
| 63 |
+
issues.append("Using print statements (consider using logging)")
|
| 64 |
+
else:
|
| 65 |
+
issues.append("Code appears clean")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
return {
|
| 68 |
+
"issues": issues,
|
| 69 |
+
"severity": "low" if issues and issues[0] == "Code appears clean" else "medium",
|
| 70 |
+
"suggestions": ["Consider adding error handling", "Add input validation"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
}
|
| 72 |
+
|
| 73 |
+
def get_system_metrics():
|
| 74 |
+
"""Get system metrics demo"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
return {
|
| 76 |
+
"uptime": "2h 15m",
|
| 77 |
+
"requests_served": 142,
|
| 78 |
+
"success_rate": 94.2,
|
| 79 |
+
"avg_response_time": "1.8s",
|
| 80 |
+
"memory_usage": "156 MB",
|
| 81 |
+
"cpu_usage": "12%"
|
| 82 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
+
# Create interface
|
| 85 |
+
with gr.Blocks(title="Sheikh-Kitty: Secure Autonomous Coding AI") as interface:
|
| 86 |
+
gr.Markdown("# π Sheikh-Kitty: Secure Autonomous Coding AI")
|
| 87 |
+
gr.Markdown("**Production deployment of the autonomous coding AI system**")
|
| 88 |
+
|
| 89 |
+
with gr.Tabs():
|
| 90 |
+
with gr.TabItem("Generate Code"):
|
| 91 |
+
gr.Markdown("### Generate Code with AI")
|
| 92 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
with gr.Row():
|
| 94 |
+
prompt_input = gr.Textbox(
|
| 95 |
+
label="Code Generation Prompt",
|
| 96 |
+
placeholder="e.g., Create a function to calculate fibonacci numbers",
|
| 97 |
+
lines=3
|
| 98 |
+
)
|
| 99 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
with gr.Row():
|
| 101 |
+
language = gr.Dropdown(
|
| 102 |
+
choices=["Python", "JavaScript", "TypeScript", "Solidity"],
|
| 103 |
+
value="Python",
|
| 104 |
+
label="Programming Language"
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
generate_btn = gr.Button("Generate Code", variant="primary")
|
| 108 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
with gr.Row():
|
| 110 |
+
code_output = gr.Code(label="Generated Code", language="python")
|
| 111 |
+
metrics_output = gr.JSON(label="Generation Metrics")
|
| 112 |
+
|
| 113 |
+
generate_btn.click(
|
| 114 |
+
fn=generate_code,
|
| 115 |
+
inputs=[prompt_input, language],
|
| 116 |
+
outputs=[code_output, metrics_output]
|
| 117 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
+
with gr.TabItem("Debug Code"):
|
| 120 |
+
gr.Markdown("### Security Analysis & Debugging")
|
| 121 |
+
|
| 122 |
+
with gr.Row():
|
| 123 |
+
code_input = gr.Code(
|
| 124 |
+
label="Code to Analyze",
|
| 125 |
+
placeholder="Paste code here for security analysis...",
|
| 126 |
+
lines=10
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
with gr.Row():
|
| 130 |
+
debug_language = gr.Dropdown(
|
| 131 |
+
choices=["Python", "JavaScript", "TypeScript", "Solidity"],
|
| 132 |
+
value="Python",
|
| 133 |
+
label="Language"
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
debug_btn = gr.Button("Analyze Code", variant="secondary")
|
| 137 |
+
|
| 138 |
+
analysis_output = gr.JSON(label="Security Analysis Results")
|
| 139 |
+
|
| 140 |
+
debug_btn.click(
|
| 141 |
+
fn=debug_code,
|
| 142 |
+
inputs=[code_input, debug_language],
|
| 143 |
+
outputs=[analysis_output]
|
| 144 |
+
)
|
| 145 |
|
| 146 |
+
with gr.TabItem("System Metrics"):
|
| 147 |
+
gr.Markdown("### System Performance & Health")
|
| 148 |
+
|
| 149 |
+
refresh_btn = gr.Button("Refresh Metrics", variant="primary")
|
| 150 |
+
|
| 151 |
+
metrics_display = gr.JSON(label="System Metrics")
|
| 152 |
+
|
| 153 |
+
refresh_btn.click(
|
| 154 |
+
fn=get_system_metrics,
|
| 155 |
+
outputs=[metrics_display]
|
| 156 |
+
)
|
| 157 |
+
|
| 158 |
+
gr.Markdown("---")
|
| 159 |
+
gr.Markdown("**Powered by Sheikh-Kitty Secure Autonomous Coding AI**")
|
| 160 |
+
gr.Markdown("*Deployed on Hugging Face Spaces - Version 1.0.0*")
|
| 161 |
|
| 162 |
return interface
|
| 163 |
|
| 164 |
+
# Create and launch the demo
|
| 165 |
if __name__ == "__main__":
|
| 166 |
+
logger.info("π Starting Sheikh-Kitty Space demo...")
|
| 167 |
|
| 168 |
+
demo = create_demo()
|
|
|
|
| 169 |
|
| 170 |
+
demo.launch(
|
|
|
|
| 171 |
server_name="0.0.0.0",
|
| 172 |
server_port=7860,
|
| 173 |
share=False,
|
| 174 |
+
show_error=True,
|
| 175 |
debug=False,
|
| 176 |
quiet=True,
|
|
|
|
|
|
|
| 177 |
inbrowser=False
|
| 178 |
+
)
|