|
import gradio as gr |
|
from transformers import pipeline |
|
|
|
|
|
code_analyzer = pipeline("text-classification", model="microsoft/codereviewer") |
|
|
|
|
|
def analyze_code(code_snippet): |
|
result = code_analyzer(code_snippet) |
|
|
|
if result[0]["label"] == "LABEL_1": |
|
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!" |
|
|
|
|
|
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." |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
interface.launch() |
|
|