SilverDragon9 commited on
Commit
ff52d50
·
1 Parent(s): fe24735

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -68,13 +68,23 @@ def detect_intrusion(file):
68
  # Only output whether it's an attack or normal
69
  log_data['Prediction'] = ['Attack' if class_labels.get(pred, 'Unknown') != "normal" else "Normal" for pred in predictions]
70
 
71
- return log_data[['date', 'time', 'Prediction']].to_string(index=False)
 
 
 
 
 
 
 
 
 
 
72
 
73
  # Create Gradio interface
74
  iface = gr.Interface(
75
  fn=detect_intrusion,
76
  inputs=[gr.File(label="Upload Log File (CSV format)")],
77
- outputs="text",
78
  title="Intrusion Detection System",
79
  description=("""
80
  Upload a CSV log file with the following features:
 
68
  # Only output whether it's an attack or normal
69
  log_data['Prediction'] = ['Attack' if class_labels.get(pred, 'Unknown') != "normal" else "Normal" for pred in predictions]
70
 
71
+ # Format date for output
72
+ log_data['date'] = log_data['date'].dt.strftime('%Y-%m-%d')
73
+
74
+ # Select final output columns
75
+ output_df = log_data[['date', 'time', 'Prediction']]
76
+
77
+ # Save the output to a CSV file for download
78
+ output_file = "intrusion_results.csv"
79
+ output_df.to_csv(output_file, index=False)
80
+
81
+ return output_df, output_file
82
 
83
  # Create Gradio interface
84
  iface = gr.Interface(
85
  fn=detect_intrusion,
86
  inputs=[gr.File(label="Upload Log File (CSV format)")],
87
+ outputs=[gr.Dataframe(label="Intrusion Detection Results"), gr.File(label="Download Predictions CSV")],
88
  title="Intrusion Detection System",
89
  description=("""
90
  Upload a CSV log file with the following features: