File size: 1,020 Bytes
9ff56ed
 
 
49c5ddf
 
9ff56ed
 
 
 
49c5ddf
 
9ff56ed
49c5ddf
 
 
9ff56ed
 
49c5ddf
9ff56ed
 
 
 
 
 
49c5ddf
 
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
32
import gradio as gr
from transformers import pipeline

# Load the Microsoft CodeReviewer model
code_analyzer = pipeline("text-classification", model="microsoft/codereviewer")

# Function to analyze code snippets
def analyze_code(code_snippet):
    result = code_analyzer(code_snippet)
    # Interpret the model's output
    if result[0]["label"] == "LABEL_1":  # Assuming LABEL_1 means insecure or problematic
        return (
            f"⚠️ chi haja matmach ajmi: {result[0]['label']} "
            f"(ti9a: {result[0]['score']:.2f})\n"
            "💡 Suggestion: Review the flagged code section and improve it according to best practices."
        )
    else:
        return "✅ Code m9wd wlah!"

# Gradio interface setup
interface = gr.Interface(
    fn=analyze_code,
    inputs="text",
    outputs="text",
    title="Microsoft Code Reviewer",
    description="Paste a code snippet to analyze for vulnerabilities or improvements."
)

# Launch the interface
if __name__ == "__main__":
    interface.launch()