CoolFace
Apppublic

ITR8RI/AI_Cybersecurity

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
app.py59 linesDownload Raw Back to root
1import gradio as gr2from ai_engine import analyze_logs3import time4 5css = """6.analysis-box { border: 1px solid #e0e0e0; border-radius: 8px; padding: 20px; }7.file-upload { border: 2px dashed #4facfe; padding: 20px; }8.spinner { display: inline-block; width: 20px; height: 20px; border: 3px solid rgba(0,0,0,.3); border-radius: 50%; border-top-color: #4facfe; animation: spin 1s ease-in-out infinite; }9@keyframes spin { to { transform: rotate(360deg); } }10"""11 12def process_file(file):13    # Initial loading state (MUST return 2 values)14    yield (15        "๐Ÿ” Analyzing your logs... <div class='spinner'></div>",  # First Markdown16        ""  # Second Markdown (empty)17    )18    19    try:20        with open(file.name, 'r') as f:21            content = f.read(100000)  # Read first 100KB22        23        results = analyze_logs(content)24        25        # Format outputs (MUST return 2 values)26        yield (27            f"๐Ÿ“‹ <strong>Summary:</strong> {results.get('summary', 'No summary')}\n\n"28            f"โš ๏ธ <strong>Threats:</strong>\n{results.get('threats', 'None')}",29            30            f"๐Ÿ›ก๏ธ <strong>Recommendations:</strong>\n{results.get('recommendations', 'No actions needed')}"31        )32        33    except Exception as e:34        yield (35            f"โŒ Error: {str(e)}",36            "Please check your file and try again"37        )38 39with gr.Blocks(css=css) as app:40    gr.Markdown("# ๐Ÿ”’ AI Security Analyzer")41    42    with gr.Row():43        upload = gr.File(44            label="Drag & Drop Logs",45            file_types=[".log", ".txt"],46            elem_classes=["file-upload"]47        )48    49    with gr.Row():50        analysis = gr.Markdown(elem_classes=["analysis-box"])51        recommendations = gr.Markdown(elem_classes=["analysis-box"])52    53    upload.change(54        fn=process_file,55        inputs=upload,56        outputs=[analysis, recommendations]  # Matches the 2 return values57    )58 59app.launch()