|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
code_analyzer = pipeline("text-classification", model="mrm8488/codebert-base-finetuned-detect-insecure-code") |
|
|
|
|
|
def analyze_code(code_snippet): |
|
result = code_analyzer(code_snippet) |
|
if result[0]["label"] == "LABEL_1": |
|
return ( |
|
f"β οΈ Potential Issue Detected: Insecure Code " |
|
f"(Confidence: {result[0]['score']:.2f})\n" |
|
"π‘ Suggestion: Avoid using unsafe practices." |
|
) |
|
else: |
|
return "β
Code appears secure!" |
|
|
|
|
|
interface = gr.Interface( |
|
fn=analyze_code, |
|
inputs="text", |
|
outputs="text", |
|
title="Secure Code Reviewer", |
|
description="Paste a code snippet to analyze for vulnerabilities." |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
interface.launch() |
|
|