Spaces:
Sleeping
Sleeping
| import os | |
| import sys | |
| from pathlib import Path | |
| from huggingface_hub import snapshot_download | |
| import shutil | |
| PRIVATE_REPO = "cybercentinel/ai-red-teaming" | |
| CACHE_DIR = Path("/tmp/sentitrust_cache") | |
| # Download the private space | |
| print("Loading SentiTrust AI Security Toolkit...") | |
| # Clear cache to force fresh download of latest version | |
| if CACHE_DIR.exists(): | |
| print("Clearing cache to get latest updates...") | |
| shutil.rmtree(CACHE_DIR) | |
| CACHE_DIR.mkdir(parents=True, exist_ok=True) | |
| try: | |
| snapshot_download( | |
| repo_id=PRIVATE_REPO, | |
| repo_type="space", | |
| local_dir=CACHE_DIR, | |
| token=os.environ.get("HF_TOKEN") | |
| ) | |
| print("Starting AI Red-Teaming Toolkit...") | |
| # Add to path and execute the downloaded app | |
| sys.path.insert(0, str(CACHE_DIR)) | |
| # Execute the app.py file directly with proper globals | |
| app_path = CACHE_DIR / "app.py" | |
| with open(app_path) as f: | |
| code = f.read() | |
| # Provide all necessary globals including __file__ | |
| exec_globals = { | |
| "__name__": "__main__", | |
| "__file__": str(app_path), | |
| "__builtins__": __builtins__ | |
| } | |
| exec(code, exec_globals) | |
| except Exception as e: | |
| # Show professional error page if loading fails | |
| print(f"Error loading toolkit: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| import gradio as gr | |
| with gr.Blocks() as demo: | |
| gr.HTML(""" | |
| <style> | |
| @media (max-width: 768px) { | |
| .error-container { | |
| padding: 30px 20px !important; | |
| margin: 20px 10px !important; | |
| } | |
| .error-container h1 { | |
| font-size: 1.8em !important; | |
| } | |
| .error-container p { | |
| font-size: 1em !important; | |
| } | |
| .error-buttons { | |
| display: flex !important; | |
| flex-direction: column !important; | |
| gap: 12px !important; | |
| } | |
| .error-buttons a { | |
| width: 100% !important; | |
| margin: 0 !important; | |
| padding: 14px 24px !important; | |
| font-size: 1em !important; | |
| } | |
| } | |
| </style> | |
| <div class="error-container" style="background: #0a0a0a; padding: 60px 30px; border-radius: 12px; text-align: center; color: white; max-width: 800px; margin: 40px auto;"> | |
| <h1 style="color: #dc2626; font-size: 2.5em; margin-bottom: 20px;"> | |
| SentiTrust AI Security Toolkit | |
| </h1> | |
| <p style="color: rgba(255,255,255,0.8); font-size: 1.2em; margin-bottom: 30px;"> | |
| The toolkit is temporarily unavailable. Please try again in a moment. | |
| </p> | |
| <p style="color: rgba(255,255,255,0.6); font-size: 0.95em; margin-bottom: 40px;"> | |
| If the issue persists, please contact our team. | |
| </p> | |
| <div class="error-buttons" style="margin-top: 30px;"> | |
| <a href="https://sentitrust.adogent.com" target="_blank" | |
| style="display: inline-block; background: #dc2626; color: white; padding: 16px 32px; | |
| border-radius: 8px; text-decoration: none; font-weight: 700; margin: 8px; font-size: 1.1em;"> | |
| Visit SentiTrust.com → | |
| </a> | |
| <a href="https://calendly.com/sentitrust/free-security-scan" target="_blank" | |
| style="display: inline-block; background: white; color: #0a0a0a; padding: 16px 32px; | |
| border-radius: 8px; text-decoration: none; font-weight: 700; margin: 8px; font-size: 1.1em;"> | |
| Book Free Scan → | |
| </a> | |
| </div> | |
| <p style="color: rgba(255,255,255,0.4); font-size: 0.85em; margin-top: 40px;"> | |
| hello@adogent.com | |
| </p> | |
| </div> | |
| """) | |
| demo.launch( | |
| server_name="0.0.0.0", | |
| server_port=7860, | |
| share=False | |
| ) | |