-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
88 lines (77 loc) · 2.95 KB
/
app.py
File metadata and controls
88 lines (77 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import streamlit as st
import os
import time
#import base64
# Page Configuration
st.set_page_config(page_title="AI Security Analyzer", page_icon="🚀", layout="centered")
# Custom CSS for Styling
st.markdown(
"""
<style>
body {
background-color: #1e1e2f;
color: #e0e0e0;
}
.stApp {
background: linear-gradient(135deg, #4A00E0, #8E2DE2);
}
.title {
text-align: center;
font-size: 42px;
font-weight: bold;
color: #FFFFFF;
animation: glow 2s ease-in-out infinite alternate;
}
@keyframes glow {
from { text-shadow: 0 0 10px #FFFFFF; }
to { text-shadow: 0 0 20px #8E2DE2; }
}
.upload-box {
border: 3px dashed #ffffff;
background-color: rgba(255, 255, 255, 0.1);
padding: 30px;
border-radius: 15px;
text-align: center;
margin-top: 20px;
}
.success-text {
color: #00FF7F;
}
.error-text {
color: #FF6347;
}
</style>
""",
unsafe_allow_html=True
)
# Header
st.markdown("<p class='title'>Code Quality Analysis(Prob State: 9)</p>", unsafe_allow_html=True)
UPLOAD_FOLDER = "uploads"
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
# File Upload Section
st.markdown("<div class='upload-box'>📥 Upload a file for detailed security analysis (Supported: .py, .js, .java, .cpp)</div>", unsafe_allow_html=True)
uploaded_file = st.file_uploader("", type=["py", "js", "java", "cpp"], label_visibility="collapsed")
if uploaded_file:
file_path = os.path.join(UPLOAD_FOLDER, uploaded_file.name)
with open(file_path, "wb") as f:
f.write(uploaded_file.getbuffer())
st.success(f"✅ File {uploaded_file.name} uploaded successfully!")
# Security Analysis Simulation
with st.spinner("⚙ Performing AI-Powered Security Analysis..."):
docker_cmd = f"docker run -v {os.getcwd()}:/target " \
f"-e GOOGLE_API_KEY={os.environ.get('GOOGLE_API_KEY')} " \
f"-e GEMINI_API_KEY={os.environ.get('GEMINI_API_KEY')} " \
f"ai-security-analyzer dir -v -t /target/uploads -o /target/security_design.md " \
f"--agent-provider google --agent-model gemini-2.0-flash-thinking-exp"
time.sleep(3)
os.system(docker_cmd)
st.success("🎉 Analysis Complete! Download your security report below.")
# Report Display and Download
report_path = "security_design.md"
if os.path.exists(report_path):
with open(report_path, "r") as f:
report_content = f.read()
st.text_area("📜 Security Report:", report_content, height=400)
st.download_button("⬇ Download Report", data=report_content, file_name="security_design.md", mime="text/markdown")
else:
st.error("❌ Analysis failed! Please check the logs.")