Spaces:
Sleeping
Sleeping
File size: 951 Bytes
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
code_analyzer = pipeline("text-classification", model="huggingface/codebert-base-vulnerability-detection")
# Function to analyze code snippets
def analyze_code(code_snippet):
result = code_analyzer(code_snippet)
if result[0]["label"] == "VULNERABLE":
return (
f"⚠️ Potential Issue Detected: {result[0]['label']} "
f"(Confidence: {result[0]['score']:.2f})\n"
"💡 Suggestion: Avoid using unsafe practices like 'eval'. Replace it with safer alternatives."
)
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()
|