rahimizadeh commited on
Commit
4b47b1d
·
verified ·
1 Parent(s): 0c17261

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -52
app.py CHANGED
@@ -1,52 +1,59 @@
1
- # Import Gradio for UI and your backend analysis module
2
- import gradio as gr
3
- from modules import analysis # assumes parser.py, vectorizer.py, analysis.py are in a "modules" folder
4
-
5
- # Define the Gradio app using Blocks layout for full customization
6
- with gr.Blocks(title="Log Intelligence Assistant") as demo:
7
-
8
- # Header title
9
- gr.Markdown("## 🔍 Interactive Network Log Assistant")
10
-
11
- # -------- INPUTS TAB --------
12
- with gr.Tab("Inputs 🔽"):
13
- # File upload and raw text input
14
- with gr.Row():
15
- uploaded_files = gr.File(
16
- file_types=[".pdf", ".log", ".txt"],
17
- file_count="multiple", # allow multiple file uploads
18
- label="📁 Upload Log Files"
19
- )
20
-
21
- text_input = gr.Textbox(
22
- label="Paste Logs Here",
23
- lines=15, # height of textbox
24
- placeholder="2023-10-05 14:22:11 [Firewall] BLOCKED: 192.168.1.5..."
25
- )
26
-
27
- # Natural language query and quick predefined actions
28
- with gr.Row():
29
- query_input = gr.Textbox(
30
- label="Ask About Logs",
31
- placeholder="Find failed login attempts from 192.168.1.5"
32
- )
33
-
34
- quick_query = gr.Dropdown(
35
- choices=["", "Detect anomalies", "Show blocked IPs", "Generate summary"],
36
- label="Quick Actions"
37
- )
38
-
39
- # Optional model and filter configurations
40
- with gr.Accordion("⚙️ Configuration Controls", open=False):
41
- temperature = gr.Slider(
42
- minimum=0.1, maximum=1.0, value=0.7,
43
- label="Creativity (Temperature)"
44
- )
45
-
46
- start_time = gr.DateTime(label="Start Time")
47
- end_time = gr.DateTime(label="End Time")
48
-
49
- # -------- OUTPUTS TAB --------
50
- with gr.Tab("Outputs 🔼"):
51
- # Text output for log analysis result
52
- analys
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from modules import analysis # Correct import
3
+
4
+ # Create the Gradio Blocks UI
5
+ with gr.Blocks(title="Log Intelligence Assistant") as demo:
6
+ gr.Markdown("## 🔍 Interactive Network Log Assistant")
7
+
8
+ with gr.Tab("Inputs 🔽"):
9
+ with gr.Row():
10
+ uploaded_files = gr.File(
11
+ file_types=[".pdf", ".log", ".txt"],
12
+ file_count="multiple",
13
+ label="📁 Upload Log Files"
14
+ )
15
+ text_input = gr.Textbox(
16
+ label="Paste Logs Here",
17
+ lines=15,
18
+ placeholder="2023-10-05 14:22:11 [Firewall] BLOCKED: 192.168.1.5..."
19
+ )
20
+
21
+ with gr.Row():
22
+ query_input = gr.Textbox(
23
+ label="Ask About Logs",
24
+ placeholder="Find failed login attempts from 192.168.1.5"
25
+ )
26
+ quick_query = gr.Dropdown(
27
+ choices=["", "Detect anomalies", "Show blocked IPs", "Generate summary"],
28
+ label="Quick Actions"
29
+ )
30
+
31
+ with gr.Accordion("⚙️ Configuration Controls", open=False):
32
+ temperature = gr.Slider(minimum=0.1, maximum=1.0, value=0.7, label="Creativity (Temperature)")
33
+ start_time = gr.DateTime(label="Start Time")
34
+ end_time = gr.DateTime(label="End Time")
35
+
36
+ with gr.Tab("Outputs 🔼"):
37
+ analysis_result = gr.Textbox(label="Analysis Results", lines=10, interactive=False)
38
+ bar_plot = gr.BarPlot(label="Event Frequency by Hour", x="Hour", y="Count", interactive=False)
39
+ pie_chart = gr.PieChart(label="Event Type Distribution", interactive=False)
40
+ alert_feed = gr.HighlightedText(label="Security Alerts", color_map={
41
+ "CRITICAL": "red",
42
+ "WARNING": "orange",
43
+ "INFO": "blue"
44
+ })
45
+
46
+ with gr.Tab("Export 📤"):
47
+ export_csv = gr.Button("Save as CSV")
48
+ export_pdf = gr.Button("Export PDF Report")
49
+
50
+ run_button = gr.Button("🔎 Analyze Logs")
51
+
52
+ # ✅ Fixed the typo here: analysis not analys
53
+ run_button.click(
54
+ fn=analysis.run_analysis,
55
+ inputs=[uploaded_files, text_input, query_input, quick_query, temperature, start_time, end_time],
56
+ outputs=[analysis_result, bar_plot, pie_chart, alert_feed]
57
+ )
58
+
59
+ demo.launch()