int_det / app.py
hari6677's picture
Update app.py
cf09545 verified
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)}"}
# Simple simulation (remove when TensorFlow works)
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)}"}
# Create interface
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()