File size: 959 Bytes
9ff56ed 5a36446 9ff56ed 5a36446 9ff56ed 5a36446 9ff56ed 5a36446 9ff56ed |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import gradio as gr
from transformers import pipeline
# Load the pre-trained model for detecting insecure code
code_analyzer = pipeline("text-classification", model="mrm8488/codebert-base-finetuned-detect-insecure-code")
# Function to analyze code snippets
def analyze_code(code_snippet):
result = code_analyzer(code_snippet)
if result[0]["label"] == "LABEL_1": # Assuming LABEL_1 means insecure
return (
f"⚠️ Potential Issue Detected: Insecure Code "
f"(Confidence: {result[0]['score']:.2f})\n"
"💡 Suggestion: Avoid using unsafe practices."
)
else:
return "✅ Code appears secure!"
# Gradio interface setup
interface = gr.Interface(
fn=analyze_code,
inputs="text",
outputs="text",
title="Secure Code Reviewer",
description="Paste a code snippet to analyze for vulnerabilities."
)
# Launch the interface
if __name__ == "__main__":
interface.launch()
|