Update app.py
Browse files
app.py
CHANGED
@@ -1,67 +1,67 @@
|
|
1 |
-
|
2 |
-
from
|
3 |
-
from transformers import pipeline
|
4 |
-
from modules import parser, vectorizer
|
5 |
-
from datetime import datetime
|
6 |
-
import re
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
"""
|
12 |
-
if not start_time or not end_time:
|
13 |
-
return logs_text # Skip filtering if not both are set
|
14 |
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
26 |
|
27 |
-
|
28 |
-
|
|
|
|
|
29 |
|
30 |
-
#
|
31 |
-
|
32 |
-
|
33 |
-
if text_input:
|
34 |
-
logs_text += "\n" + text_input
|
35 |
|
36 |
-
|
37 |
-
|
|
|
38 |
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
41 |
|
42 |
-
#
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
if not query_text:
|
47 |
-
return "❌ No query or quick action selected.", None, None, None
|
48 |
|
49 |
-
#
|
50 |
-
|
51 |
-
vectordb = vectorizer.create_vectorstore(docs)
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
# Dummy charts and alerts for testing
|
60 |
-
bar_data = {"Hour": ["14:00", "15:00"], "Count": [8, 4]}
|
61 |
-
pie_data = {"Event Type": ["Blocked", "Scan"], "Count": [8, 4]}
|
62 |
-
alerts = [("CRITICAL", "8 blocked SSH attempts from 192.168.1.5"),
|
63 |
-
("WARNING", "4 port scanning alerts from 10.0.0.8")]
|
64 |
-
|
65 |
-
return result, bar_data, pie_data, alerts
|
66 |
|
|
|
67 |
demo.launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from modules import analysis # Make sure this matches your folder structure
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
# Create the Gradio interface using Blocks
|
5 |
+
with gr.Blocks(title="Log Intelligence Assistant") as demo:
|
6 |
+
gr.Markdown("## 🔍 Interactive Network Log Assistant")
|
|
|
|
|
|
|
7 |
|
8 |
+
# ---------- Inputs ----------
|
9 |
+
with gr.Tab("Inputs 🔽"):
|
10 |
+
with gr.Row():
|
11 |
+
uploaded_files = gr.File(
|
12 |
+
file_types=[".pdf", ".log", ".txt"],
|
13 |
+
file_count="multiple",
|
14 |
+
label="📁 Upload Log Files"
|
15 |
+
)
|
16 |
+
text_input = gr.Textbox(
|
17 |
+
label="Paste Logs Here",
|
18 |
+
lines=15,
|
19 |
+
placeholder="2023-10-05 14:22:11 [Firewall] BLOCKED: 192.168.1.5..."
|
20 |
+
)
|
21 |
|
22 |
+
with gr.Row():
|
23 |
+
query_input = gr.Textbox(
|
24 |
+
label="Ask About Logs",
|
25 |
+
placeholder="Find failed login attempts from 192.168.1.5"
|
26 |
+
)
|
27 |
+
quick_query = gr.Dropdown(
|
28 |
+
choices=["", "Detect anomalies", "Show blocked IPs", "Generate summary"],
|
29 |
+
label="Quick Actions"
|
30 |
+
)
|
31 |
|
32 |
+
with gr.Accordion("⚙️ Configuration Controls", open=False):
|
33 |
+
temperature = gr.Slider(minimum=0.1, maximum=1.0, value=0.7, label="Creativity (Temperature)")
|
34 |
+
start_time = gr.DateTime(label="Start Time")
|
35 |
+
end_time = gr.DateTime(label="End Time")
|
36 |
|
37 |
+
# ---------- Outputs ----------
|
38 |
+
with gr.Tab("Outputs 🔼"):
|
39 |
+
analysis_result = gr.Textbox(label="Analysis Results", lines=10, interactive=False)
|
|
|
|
|
40 |
|
41 |
+
# Use gr.Plot for matplotlib/plotly compatibility
|
42 |
+
bar_plot = gr.Plot(label="Event Frequency by Hour")
|
43 |
+
pie_chart = gr.Plot(label="Event Type Distribution")
|
44 |
|
45 |
+
alert_feed = gr.HighlightedText(label="Security Alerts", color_map={
|
46 |
+
"CRITICAL": "red",
|
47 |
+
"WARNING": "orange",
|
48 |
+
"INFO": "blue"
|
49 |
+
})
|
50 |
|
51 |
+
# ---------- Export ----------
|
52 |
+
with gr.Tab("Export 📤"):
|
53 |
+
export_csv = gr.Button("Save as CSV")
|
54 |
+
export_pdf = gr.Button("Export PDF Report")
|
|
|
|
|
55 |
|
56 |
+
# ---------- Action Button ----------
|
57 |
+
run_button = gr.Button("🔎 Analyze Logs")
|
|
|
58 |
|
59 |
+
# Bind the Analyze button to your backend function
|
60 |
+
run_button.click(
|
61 |
+
fn=analysis.run_analysis,
|
62 |
+
inputs=[uploaded_files, text_input, query_input, quick_query, temperature, start_time, end_time],
|
63 |
+
outputs=[analysis_result, bar_plot, pie_chart, alert_feed]
|
64 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
+
# ✅ Make sure this line exists — it launches the app!
|
67 |
demo.launch()
|