erayman09 commited on
Commit
9ff56ed
·
verified ·
1 Parent(s): 9bf3522

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py CHANGED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the pre-trained model
5
+ code_analyzer = pipeline("text-classification", model="huggingface/codebert-base-vulnerability-detection")
6
+
7
+ # Function to analyze code snippets
8
+ def analyze_code(code_snippet):
9
+ result = code_analyzer(code_snippet)
10
+ if result[0]["label"] == "VULNERABLE":
11
+ return (
12
+ f"⚠️ Potential Issue Detected: {result[0]['label']} "
13
+ f"(Confidence: {result[0]['score']:.2f})\n"
14
+ "💡 Suggestion: Avoid using unsafe practices like 'eval'. Replace it with safer alternatives."
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
29
+ if __name__ == "__main__":
30
+ interface.launch()