Spaces:
Sleeping
Sleeping
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() | |