Skip to content

Commit 81f0036

Browse files
authored
feat: add GUI based explorer (#1)
1 parent c3451e1 commit 81f0036

File tree

9 files changed

+277
-1
lines changed

9 files changed

+277
-1
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @olunusib

.github/ISSUE_TEMPLATE.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Overview Description
2+
3+
## Steps to Reproduce
4+
5+
1.
6+
2.
7+
3.
8+
9+
## Actual Results
10+
11+
## Expected Results
12+
13+
## Reproducibility
14+
15+
## Additional Information

.github/dependabot.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: weekly
7+
groups:
8+
actions-minor:
9+
update-types:
10+
- minor
11+
- patch
12+
commit-message:
13+
include: scope
14+
prefix: "chore"
15+
16+
- package-ecosystem: pip
17+
directory: /
18+
schedule:
19+
interval: weekly
20+
groups:
21+
actions-minor:
22+
update-types:
23+
- minor
24+
- patch
25+
commit-message:
26+
include: scope
27+
prefix: "chore"

.github/workflows/ci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
jobs:
9+
explorer-ci:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Check out code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: "3.10"
20+
cache: "pip"
21+
22+
- name: Install dependencies
23+
run: |
24+
pip install -r requirements.txt
25+
pip install -r requirements-dev.txt
26+
27+
- name: Check code formatting with isort
28+
run: |
29+
isort --profile=black --check-only .
30+
31+
- name: Check code formatting with black
32+
run: |
33+
black --check .

README.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,48 @@
1-
# vulnerability-explorer
1+
# Vulnerability Explorer
2+
3+
This is a simple web application built with Streamlit that allows users to scan code for vulnerabilities using [Groq](https://groq.com/).
4+
5+
![Explorer Demo](demo.gif)
6+
7+
## Prerequisites
8+
9+
- Python 3.10 or higher
10+
- Groq API key
11+
12+
## Installation
13+
14+
1. **Clone the Repository**
15+
16+
```bash
17+
git clone https://github.com/codeguardai/explorer.git
18+
cd explorer
19+
```
20+
21+
2. **Set the Groq API Key**
22+
23+
```bash
24+
export GROQ_API_KEY=<your_api_key_here>
25+
```
26+
27+
3. **Install Dependencies**
28+
29+
```bash
30+
pip install -r requirements.txt
31+
```
32+
33+
4. **Run the Application**
34+
35+
```bash
36+
streamlit run app.py
37+
```
38+
39+
## Usage
40+
41+
1. **Select a Programming Language**: Choose the programming language from the dropdown menu.
42+
2. **Input Your Code**: Write or paste your code into the editor.
43+
3. **Click 'Evaluate'**: The application will analyze your code for vulnerabilities and display the results.
44+
45+
46+
## License
47+
48+
This project is licensed under the Apache License 2.0 License. See the [LICENSE](LICENSE) file for details.

app.py

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
import os
2+
3+
import streamlit as st
4+
from guard.clients import GroqClient
5+
from streamlit_ace import st_ace
6+
from streamlit_theme import st_theme
7+
8+
st.set_page_config(
9+
layout="wide",
10+
page_icon="🔍",
11+
page_title="Vulnerability Explorer",
12+
menu_items={
13+
"Get Help": "https://github.com/codeguardai/explorer/issues",
14+
"Report a bug": "https://github.com/codeguardai/explorer/issues",
15+
},
16+
)
17+
st.title("Vulnerability Explorer")
18+
19+
# Ensure the Groq API key is set
20+
if not os.environ.get("GROQ_API_KEY"):
21+
st.error(
22+
"Groq API key not found. Please set the 'GROQ_API_KEY' environment variable."
23+
)
24+
st.stop()
25+
26+
# Initialize the AI client using GroqClient from guard
27+
ai_client = GroqClient("llama3-8b-8192")
28+
29+
LANGUAGE_DISPLAY_MAP = {
30+
"C": "c_cpp",
31+
"C++": "c_cpp",
32+
"C#": "csharp",
33+
"Go": "golang",
34+
"Python": "python",
35+
"JavaScript": "javascript",
36+
"Java": "java",
37+
"Ruby": "ruby",
38+
"PHP": "php",
39+
"Swift": "swift",
40+
"Kotlin": "kotlin",
41+
"HTML": "html",
42+
"CSS": "css",
43+
"TypeScript": "typescript",
44+
"JSON": "json",
45+
"Markdown": "markdown",
46+
"Elixir": "elixir",
47+
"Rust": "rust",
48+
"Erlang": "erlang",
49+
}
50+
available_languages = sorted(LANGUAGE_DISPLAY_MAP.keys())
51+
52+
# Set the Ace editor theme based on the base theme
53+
theme = st_theme()
54+
base_theme = (
55+
theme.get("base")
56+
if theme and isinstance(theme, dict) and "base" in theme
57+
else "dark"
58+
)
59+
ace_theme = "twilight" if base_theme == "dark" else "chrome"
60+
61+
# Initialize session state for the result if not already initialized
62+
if "result" not in st.session_state:
63+
st.session_state["result"] = "Results will appear here."
64+
65+
# Default Python code snippet
66+
default_python_code = """import os
67+
68+
def read_file(filepath):
69+
return open(filepath).read()
70+
71+
def login(user, pwd):
72+
if user == "admin" and pwd == "password123":
73+
print("Welcome!")
74+
else:
75+
print("Access denied!")
76+
77+
filepath = input("File path: ")
78+
print(read_file(filepath))
79+
80+
user = input("Username: ")
81+
pwd = input("Password: ")
82+
login(user, pwd)
83+
"""
84+
85+
# Define layout columns for input and results
86+
input_column, result_column = st.columns(2)
87+
88+
with input_column:
89+
st.header("📝 Input Code")
90+
91+
display_language = st.selectbox(
92+
"Choose Language:",
93+
available_languages,
94+
index=available_languages.index("Python"),
95+
)
96+
ace_language = LANGUAGE_DISPLAY_MAP[display_language]
97+
98+
# Code editor with syntax highlighting using st_ace
99+
code_input = st_ace(
100+
value=default_python_code if display_language == "Python" else "",
101+
placeholder="Enter your code here...",
102+
language=ace_language,
103+
theme=ace_theme,
104+
keybinding="vscode",
105+
font_size=14,
106+
tab_size=4,
107+
show_gutter=True,
108+
wrap=False,
109+
auto_update=True,
110+
min_lines=20,
111+
key="ace_editor",
112+
)
113+
114+
evaluate = st.button("Evaluate")
115+
116+
st.markdown(
117+
"""
118+
<style>
119+
.scrollable-container {
120+
max-height: 100vh;
121+
overflow-y: auto;
122+
padding: 1em;
123+
}
124+
</style>
125+
""",
126+
unsafe_allow_html=True,
127+
)
128+
129+
with result_column:
130+
st.header("🔍 Analysis")
131+
132+
if evaluate:
133+
if code_input.strip() == "":
134+
st.warning("Please enter some code before evaluating.")
135+
else:
136+
with st.spinner("Analyzing code..."):
137+
try:
138+
code_with_language = f"Language: {display_language}\n{code_input}"
139+
result = ai_client.scan_code(code_with_language)
140+
st.session_state["result"] = result
141+
except Exception as e:
142+
st.session_state["result"] = f"An error occurred: {e}"
143+
144+
st.markdown(
145+
f'<div class="scrollable-container">{st.session_state["result"]}</div>',
146+
unsafe_allow_html=True,
147+
)

demo.gif

398 KB
Loading

requirements-dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
black
2+
isort

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
streamlit==1.38.0
2+
streamlit-ace==0.1.1
3+
st-theme==1.2.3
4+
guardai==0.2.0

0 commit comments

Comments
 (0)