erayman09 commited on
Commit
49c5ddf
·
verified ·
1 Parent(s): 5a36446

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -1,28 +1,29 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load the pre-trained model for detecting insecure code
5
- code_analyzer = pipeline("text-classification", model="mrm8488/codebert-base-finetuned-detect-insecure-code")
6
 
7
  # Function to analyze code snippets
8
  def analyze_code(code_snippet):
9
  result = code_analyzer(code_snippet)
10
- if result[0]["label"] == "LABEL_1": # Assuming LABEL_1 means insecure
 
11
  return (
12
- f"⚠️ Potential Issue Detected: Insecure Code "
13
- f"(Confidence: {result[0]['score']:.2f})\n"
14
- "💡 Suggestion: Avoid using unsafe practices."
15
  )
16
  else:
17
- return "✅ Code appears secure!"
18
 
19
  # Gradio interface setup
20
  interface = gr.Interface(
21
  fn=analyze_code,
22
  inputs="text",
23
  outputs="text",
24
- title="Secure Code Reviewer",
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