rawqubit commited on
Commit
9ee5c29
Β·
verified Β·
1 Parent(s): 33edecc

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +10 -6
  2. app.py +65 -0
  3. requirements.txt +2 -0
README.md CHANGED
@@ -1,12 +1,16 @@
1
  ---
2
- title: Smart Code Auditor
3
- emoji: πŸ“š
4
- colorFrom: yellow
5
- colorTo: red
6
  sdk: gradio
7
- sdk_version: 6.9.0
8
  app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
1
  ---
2
+ title: AI Smart Code Auditor
3
+ emoji: πŸ”
4
+ colorFrom: blue
5
+ colorTo: indigo
6
  sdk: gradio
7
+ sdk_version: 4.44.1
8
  app_file: app.py
9
  pinned: false
10
  ---
11
 
12
+ # πŸ” AI Smart Code Auditor
13
+
14
+ An interactive Application Security tool built by **Srinikhil Chakilam** to automatically detect zero-day vulnerabilities, OWASP Top 10 issues, and engineering anti-patterns.
15
+
16
+ Powered by the Hugging Face Inference API and the Qwen2.5-Coder model, this demonstrates practical MLOps applied to DevSecOps pipelines.
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+
4
+ # Qwen2.5-Coder is currently the best open-source coding model
5
+ try:
6
+ client = InferenceClient("Qwen/Qwen2.5-Coder-32B-Instruct")
7
+ except:
8
+ # Fallback if that specific model isn't on free tier right now
9
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
10
+
11
+ def analyze_code(code, language):
12
+ system_prompt = f"""You are a Senior Application Security Engineer and Expert Code Reviewer.
13
+ Analyze the following {language} code.
14
+ 1. Identify any security vulnerabilities (OWASP Top 10, Injection, etc.).
15
+ 2. Point out performance bottlenecks or bad engineering practices.
16
+ 3. Provide a secure, refactored version of the code.
17
+
18
+ Structure your response in Markdown with clear headings for 'Vulnerabilities', 'Best Practices', and 'Refactored Secure Code'.
19
+ """
20
+ messages = [
21
+ {"role": "system", "content": system_prompt},
22
+ {"role": "user", "content": f"```{language}\n{code}\n```"}
23
+ ]
24
+ try:
25
+ response = client.chat_completion(messages, max_tokens=1500)
26
+ return response.choices[0].message.content
27
+ except Exception as e:
28
+ return f"⚠️ **Error connecting to Analysis Engine**: {str(e)}"
29
+
30
+ # A sleek Gradio interface
31
+ with gr.Blocks(theme=gr.themes.Base()) as demo:
32
+ gr.Markdown("# πŸ” AI Smart Code Auditor")
33
+ gr.Markdown("Secure your application. Paste your code and have an AI Security Engineer audit it for zero-days, vulnerabilities, and bad practices.")
34
+
35
+ with gr.Row():
36
+ with gr.Column(scale=1):
37
+ lang = gr.Dropdown(choices=["Python", "JavaScript/TypeScript", "C/C++", "Java", "Go", "Rust", "PHP"], value="Python", label="Programming Language")
38
+ code_input = gr.Code(label="Source Code", language="python", lines=15)
39
+ btn = gr.Button("Analyze Code πŸš€", variant="primary")
40
+
41
+ example_code = '''import sqlite3
42
+ from flask import Flask, request
43
+
44
+ app = Flask(__name__)
45
+
46
+ @app.route('/user')
47
+ def get_user():
48
+ username = request.args.get('username')
49
+ conn = sqlite3.connect('users.db')
50
+ cursor = conn.cursor()
51
+ # Vulnerable to SQL Injection
52
+ cursor.execute(f"SELECT * FROM users WHERE username = '{username}'")
53
+ user = cursor.fetchone()
54
+ return str(user)
55
+ '''
56
+ gr.Markdown("### Try an example:")
57
+ gr.Examples(examples=[[example_code, "Python"]], inputs=[code_input, lang])
58
+
59
+ with gr.Column(scale=1):
60
+ output = gr.Markdown(label="Audit Report")
61
+
62
+ btn.click(analyze_code, inputs=[code_input, lang], outputs=output)
63
+
64
+ if __name__ == "__main__":
65
+ demo.launch(server_name="0.0.0.0")
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ gradio
2
+ huggingface_hub