Update app.py
Browse files
app.py
CHANGED
|
@@ -1,77 +1,119 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import requests
|
| 3 |
-
import os
|
| 4 |
import pandas as pd
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
API_URL = os.getenv("INTELLIGUARD_API", "http://127.0.0.1:8000/scan")
|
| 10 |
|
| 11 |
-
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
return None
|
| 17 |
-
try:
|
| 18 |
-
response = requests.post(API_URL, json={"text": text}, timeout=5)
|
| 19 |
-
return response.json()
|
| 20 |
-
except Exception:
|
| 21 |
-
# Fallback simulation for demo safety
|
| 22 |
-
is_threat = any(word in text.lower() for word in ["ignore", "base64", "system", "override", "bhool"])
|
| 23 |
-
return {
|
| 24 |
-
"verdict": "INJECTION" if is_threat else "SAFE",
|
| 25 |
-
"score": 0.98,
|
| 26 |
-
"attack_category": "SEMANTIC INJECTION" if is_threat else "N/A",
|
| 27 |
-
"details": {"spine_score": 0.95, "brain_score": 0.98}
|
| 28 |
-
}
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
|
| 53 |
-
|
| 54 |
-
# UI LAYOUT
|
| 55 |
-
# ==========================================
|
| 56 |
-
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", neutral_hue="slate")) as demo:
|
| 57 |
-
gr.Markdown("# π‘οΈ IntelliGuard | AMD AI Security")
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
|
|
|
| 64 |
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
batch_table = gr.Dataframe(interactive=False)
|
| 70 |
-
batch_btn.click(fn=run_batch_demo, outputs=batch_table)
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
|
| 75 |
-
#
|
| 76 |
-
# Enabling queue() helps Gradio handle the Hugging Face proxy better
|
| 77 |
demo.queue().launch()
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
|
| 4 |
+
# Custom CSS to match the screenshot exactly
|
| 5 |
+
custom_css = """
|
| 6 |
+
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap');
|
|
|
|
| 7 |
|
| 8 |
+
.gradio-container {
|
| 9 |
+
background-color: #06090f !important;
|
| 10 |
+
font-family: 'Inter', sans-serif !important;
|
| 11 |
+
color: white !important;
|
| 12 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
/* Sidebar Styling */
|
| 15 |
+
.sidebar-content { padding: 20px; background: #0b0f19; height: 100%; border-right: 1px solid #1f2937; }
|
| 16 |
+
.logo-area { text-align: center; margin-bottom: 30px; }
|
| 17 |
+
.status-badge {
|
| 18 |
+
background: rgba(16, 185, 129, 0.1);
|
| 19 |
+
border: 1px solid #10b981;
|
| 20 |
+
color: #10b981;
|
| 21 |
+
padding: 8px 15px;
|
| 22 |
+
border-radius: 20px;
|
| 23 |
+
font-size: 12px;
|
| 24 |
+
text-align: center;
|
| 25 |
+
margin-bottom: 40px;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
/* Metric Cards */
|
| 29 |
+
.metrics-row { display: flex; gap: 15px; margin-bottom: 25px; }
|
| 30 |
+
.card {
|
| 31 |
+
flex: 1;
|
| 32 |
+
background: #111827;
|
| 33 |
+
padding: 20px;
|
| 34 |
+
border-radius: 12px;
|
| 35 |
+
text-align: center;
|
| 36 |
+
border-top: 3px solid #3b82f6; /* Default blue */
|
| 37 |
+
}
|
| 38 |
+
.card.threat { border-top-color: #ef4444; }
|
| 39 |
+
.card.safe { border-top-color: #10b981; }
|
| 40 |
+
.card.rate { border-top-color: #8b5cf6; }
|
| 41 |
+
|
| 42 |
+
.card-val { font-size: 28px; font-weight: 700; margin-bottom: 5px; }
|
| 43 |
+
.card-label { font-size: 10px; color: #9ca3af; text-transform: uppercase; letter-spacing: 1px; }
|
| 44 |
+
|
| 45 |
+
/* Accordion & Buttons */
|
| 46 |
+
.establish-btn {
|
| 47 |
+
background: linear-gradient(90deg, #3b82f6 0%, #00d4ff 100%) !important;
|
| 48 |
+
border: none !important;
|
| 49 |
+
color: white !important;
|
| 50 |
+
font-weight: 600 !important;
|
| 51 |
+
}
|
| 52 |
|
| 53 |
+
/* Bottom Input Bar */
|
| 54 |
+
.chat-container {
|
| 55 |
+
background: #111827 !important;
|
| 56 |
+
border: 1px solid #3b82f6 !important;
|
| 57 |
+
border-radius: 10px !important;
|
| 58 |
+
}
|
| 59 |
+
"""
|
| 60 |
|
| 61 |
+
with gr.Blocks(css=custom_css, theme=gr.themes.Default()) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
+
# --- SIDEBAR PANEL ---
|
| 64 |
+
with gr.Sidebar(elem_id="sidebar"):
|
| 65 |
+
with gr.Column(elem_classes="sidebar-content"):
|
| 66 |
+
with gr.Column(elem_classes="logo-area"):
|
| 67 |
+
gr.HTML("""<div style='font-size: 40px;'>π‘οΈ</div>""")
|
| 68 |
+
gr.Markdown("## **INTELLIGUARD**\nSECURITY PLATFORM")
|
| 69 |
|
| 70 |
+
gr.HTML("<div class='status-badge'>β INTELLIGUARD PROTECTED</div>")
|
| 71 |
+
|
| 72 |
+
gr.Markdown("### π AUDIT LOG")
|
| 73 |
+
gr.Markdown("<p style='color: #6b7280; font-size: 13px;'>No activity recorded yet.</p>")
|
| 74 |
+
|
| 75 |
+
gr.Markdown("---")
|
| 76 |
+
gr.Markdown("### π DOCUMENT UPLOAD")
|
| 77 |
+
gr.File(label=None, file_count="multiple", elem_id="file-upload")
|
| 78 |
+
gr.Markdown("<p style='color: #6b7280; font-size: 11px;'>200MB per file β’ PDF, TXT, DOCX</p>")
|
| 79 |
+
|
| 80 |
+
# --- MAIN CONTENT AREA ---
|
| 81 |
+
with gr.Column():
|
| 82 |
+
# Header Section
|
| 83 |
+
gr.HTML("""
|
| 84 |
+
<div style="text-align: center; margin-top: 20px;">
|
| 85 |
+
<div style='font-size: 30px; margin-bottom: 10px;'>π‘οΈ</div>
|
| 86 |
+
<h1 style="font-size: 32px; margin: 0;">TechCorp Employee Portal</h1>
|
| 87 |
+
<p style="color: #6b7280;">Secured by <span style="color: #10b981;">IntelliGuard</span> β’ 4-Layer Prompt Injection Detection</p>
|
| 88 |
+
</div>
|
| 89 |
+
""")
|
| 90 |
+
|
| 91 |
+
# Metrics Grid
|
| 92 |
+
with gr.Row(elem_classes="metrics-row"):
|
| 93 |
+
gr.HTML("<div class='card'><div class='card-val' style='color:#3b82f6'>0</div><div class='card-label'>Total Queries</div></div>")
|
| 94 |
+
gr.HTML("<div class='card threat'><div class='card-val' style='color:#ef4444'>0</div><div class='card-label'>Threats Blocked</div></div>")
|
| 95 |
+
gr.HTML("<div class='card safe'><div class='card-val' style='color:#10b981'>0</div><div class='card-label'>Safe Queries</div></div>")
|
| 96 |
+
gr.HTML("<div class='card rate'><div class='card-val' style='color:#8b5cf6'>100%</div><div class='card-label'>Safe Rate</div></div>")
|
| 97 |
+
|
| 98 |
+
# Email Gateway Accordion
|
| 99 |
+
with gr.Accordion("π§ Enterprise Email Gateway", open=True):
|
| 100 |
+
with gr.Row():
|
| 101 |
+
email_input = gr.Textbox(label="Target Email", value="security-ops@techcorp.com", interactive=True)
|
| 102 |
+
pwd_input = gr.Textbox(label="App Password", type="password", placeholder="β’β’β’β’β’β’β’β’β’β’β’β’", interactive=True)
|
| 103 |
+
connect_btn = gr.Button("π Establish Secure Connection", elem_classes="establish-btn")
|
| 104 |
|
| 105 |
+
# Spacing
|
| 106 |
+
gr.Markdown("<div style='height: 100px;'></div>")
|
|
|
|
|
|
|
| 107 |
|
| 108 |
+
# Footer Chat Bar
|
| 109 |
+
with gr.Row():
|
| 110 |
+
chat_input = gr.Textbox(
|
| 111 |
+
show_label=False,
|
| 112 |
+
placeholder="Ask about company policies, benefits, security guidelines...",
|
| 113 |
+
scale=10,
|
| 114 |
+
elem_classes="chat-container"
|
| 115 |
+
)
|
| 116 |
+
submit_btn = gr.Button("β", scale=1, variant="primary")
|
| 117 |
|
| 118 |
+
# Launch
|
|
|
|
| 119 |
demo.queue().launch()
|