Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,29 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
# Load the
|
| 5 |
-
code_analyzer = pipeline("text-classification", model="
|
| 6 |
|
| 7 |
# Function to analyze code snippets
|
| 8 |
def analyze_code(code_snippet):
|
| 9 |
result = code_analyzer(code_snippet)
|
| 10 |
-
|
|
|
|
| 11 |
return (
|
| 12 |
-
f"⚠️
|
| 13 |
-
f"(
|
| 14 |
-
"💡 Suggestion:
|
| 15 |
)
|
| 16 |
else:
|
| 17 |
-
return "✅ Code
|
| 18 |
|
| 19 |
# Gradio interface setup
|
| 20 |
interface = gr.Interface(
|
| 21 |
fn=analyze_code,
|
| 22 |
inputs="text",
|
| 23 |
outputs="text",
|
| 24 |
-
title="
|
| 25 |
-
description="Paste a code snippet to analyze for vulnerabilities."
|
| 26 |
)
|
| 27 |
|
| 28 |
# Launch the interface
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Load the Microsoft CodeReviewer model
|
| 5 |
+
code_analyzer = pipeline("text-classification", model="microsoft/codereviewer")
|
| 6 |
|
| 7 |
# Function to analyze code snippets
|
| 8 |
def analyze_code(code_snippet):
|
| 9 |
result = code_analyzer(code_snippet)
|
| 10 |
+
# Interpret the model's output
|
| 11 |
+
if result[0]["label"] == "LABEL_1": # Assuming LABEL_1 means insecure or problematic
|
| 12 |
return (
|
| 13 |
+
f"⚠️ chi haja matmach ajmi: {result[0]['label']} "
|
| 14 |
+
f"(ti9a: {result[0]['score']:.2f})\n"
|
| 15 |
+
"💡 Suggestion: Review the flagged code section and improve it according to best practices."
|
| 16 |
)
|
| 17 |
else:
|
| 18 |
+
return "✅ Code m9wd wlah!"
|
| 19 |
|
| 20 |
# Gradio interface setup
|
| 21 |
interface = gr.Interface(
|
| 22 |
fn=analyze_code,
|
| 23 |
inputs="text",
|
| 24 |
outputs="text",
|
| 25 |
+
title="Microsoft Code Reviewer",
|
| 26 |
+
description="Paste a code snippet to analyze for vulnerabilities or improvements."
|
| 27 |
)
|
| 28 |
|
| 29 |
# Launch the interface
|