|
|
import gradio as gr |
|
|
import numpy as np |
|
|
|
|
|
print("β
App starting without TensorFlow...") |
|
|
|
|
|
def predict_intrusion(features_input): |
|
|
try: |
|
|
features = [float(x.strip()) for x in features_input.split(',') if x.strip()] |
|
|
|
|
|
if len(features) != 119: |
|
|
return {"Prediction": "ERROR", "Confidence": "0%", "Message": f"Need 119 features, got {len(features)}"} |
|
|
|
|
|
|
|
|
avg_value = sum(features) / len(features) |
|
|
|
|
|
if avg_value > 0.4: |
|
|
return { |
|
|
"Prediction": "π¨ ATTACK DETECTED", |
|
|
"Confidence": "85%", |
|
|
"Message": "Potential threat detected (SIMULATION MODE)" |
|
|
} |
|
|
else: |
|
|
return { |
|
|
"Prediction": "β
NORMAL TRAFFIC", |
|
|
"Confidence": "92%", |
|
|
"Message": "Traffic appears normal (SIMULATION MODE)" |
|
|
} |
|
|
|
|
|
except Exception as e: |
|
|
return {"Prediction": "ERROR", "Confidence": "0%", "Message": f"Error: {str(e)}"} |
|
|
|
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
gr.Markdown("# π Network Intrusion Detection System") |
|
|
gr.Markdown("**Simulation Mode - TensorFlow installing...**") |
|
|
|
|
|
with gr.Row(): |
|
|
with gr.Column(): |
|
|
features = gr.Textbox(label="Enter 119 features (comma-separated)", lines=5) |
|
|
btn = gr.Button("Analyze Traffic") |
|
|
|
|
|
with gr.Column(): |
|
|
result = gr.Label(label="Prediction Result") |
|
|
|
|
|
btn.click(fn=predict_intrusion, inputs=features, outputs=result) |
|
|
|
|
|
demo.launch() |