erayman09's picture
Update app.py
5a36446 verified
raw
history blame
959 Bytes
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()