File size: 2,492 Bytes
ef14d9b
 
4c2540e
ef14d9b
 
 
4c2540e
ef14d9b
 
 
 
 
 
 
 
 
 
 
 
 
4c2540e
ef14d9b
 
 
 
 
 
 
 
 
4c2540e
ef14d9b
 
 
 
4c2540e
ef14d9b
 
 
4c2540e
ef14d9b
 
 
4c2540e
ef14d9b
 
 
 
 
4c2540e
ef14d9b
 
 
 
4c2540e
ef14d9b
 
4c2540e
ef14d9b
 
 
 
 
 
f9649c3
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
55
56
57
58
59
60
61
62
63
64
65
66
67
import gradio as gr
from modules import analysis  # Make sure this matches your folder structure

# Create the Gradio interface using Blocks
with gr.Blocks(title="Log Intelligence Assistant") as demo:
    gr.Markdown("## 🔍 Interactive Network Log Assistant")

    # ---------- Inputs ----------
    with gr.Tab("Inputs 🔽"):
        with gr.Row():
            uploaded_files = gr.File(
                file_types=[".pdf", ".log", ".txt"],
                file_count="multiple",
                label="📁 Upload Log Files"
            )
            text_input = gr.Textbox(
                label="Paste Logs Here",
                lines=15,
                placeholder="2023-10-05 14:22:11 [Firewall] BLOCKED: 192.168.1.5..."
            )

        with gr.Row():
            query_input = gr.Textbox(
                label="Ask About Logs",
                placeholder="Find failed login attempts from 192.168.1.5"
            )
            quick_query = gr.Dropdown(
                choices=["", "Detect anomalies", "Show blocked IPs", "Generate summary"],
                label="Quick Actions"
            )

        with gr.Accordion("⚙️ Configuration Controls", open=False):
            temperature = gr.Slider(minimum=0.1, maximum=1.0, value=0.7, label="Creativity (Temperature)")
            start_time = gr.DateTime(label="Start Time")
            end_time = gr.DateTime(label="End Time")

    # ---------- Outputs ----------
    with gr.Tab("Outputs 🔼"):
        analysis_result = gr.Textbox(label="Analysis Results", lines=10, interactive=False)

        # Use gr.Plot for matplotlib/plotly compatibility
        bar_plot = gr.Plot(label="Event Frequency by Hour")
        pie_chart = gr.Plot(label="Event Type Distribution")

        alert_feed = gr.HighlightedText(label="Security Alerts", color_map={
            "CRITICAL": "red",
            "WARNING": "orange",
            "INFO": "blue"
        })

    # ---------- Export ----------
    with gr.Tab("Export 📤"):
        export_csv = gr.Button("Save as CSV")
        export_pdf = gr.Button("Export PDF Report")

    # ---------- Action Button ----------
    run_button = gr.Button("🔎 Analyze Logs")

    # Bind the Analyze button to your backend function
    run_button.click(
        fn=analysis.run_analysis,
        inputs=[uploaded_files, text_input, query_input, quick_query, temperature, start_time, end_time],
        outputs=[analysis_result, bar_plot, pie_chart, alert_feed]
    )

demo.launch()