Spaces:
Sleeping
Sleeping
import streamlit as st | |
import tempfile | |
import os | |
from utils.apk_analyzer import ApkAnalyzer | |
from utils.report_generator import ReportGenerator | |
st.set_page_config(page_title="APK Analyzer", page_icon="π", layout="wide") | |
# Sidebar | |
with st.sidebar: | |
st.title("APK Security Analyzer") | |
st.write("Upload an APK file for security analysis") | |
uploaded_file = st.file_uploader("Choose an APK file", type=["apk"]) | |
if uploaded_file: | |
st.success("File uploaded successfully!") | |
file_details = { | |
"Filename": uploaded_file.name, | |
"File size": f"{uploaded_file.size / 1024:.2f} KB", | |
} | |
st.write("File Details:") | |
for key, value in file_details.items(): | |
st.write(f"- {key}: {value}") | |
if uploaded_file: | |
with tempfile.NamedTemporaryFile(delete=False, suffix=".apk") as tmp_file: | |
tmp_file.write(uploaded_file.getvalue()) | |
tmp_file_path = tmp_file.name | |
with st.spinner("Analyzing APK..."): | |
try: | |
analyzer = ApkAnalyzer(tmp_file_path) | |
# Create two columns for main content | |
col1, col2 = st.columns(2) | |
with col1: | |
with st.container(): | |
st.header("Basic Information") | |
basic_info = analyzer.basic_info() | |
st.json(basic_info) | |
with col2: | |
with st.container(): | |
st.header("Security Issues") | |
security_issues = analyzer.security_analysis() | |
for issue in security_issues: | |
st.warning(issue, icon="β οΈ") | |
# Bottom section for AI Analysis | |
st.markdown("---") | |
with st.container(): | |
st.header("AI Analysis Report") | |
# Create tabs for different views | |
tab1, tab2 = st.tabs(["Report", "Summary"]) | |
with tab1: | |
report_gen = ReportGenerator() | |
report = report_gen.generate_report(basic_info, security_issues) | |
st.write(report) | |
# Download report button with improved styling | |
st.download_button( | |
label="π₯ Download Full Report", | |
data=report, | |
file_name="security_report.txt", | |
mime="text/plain", | |
) | |
with tab2: | |
st.subheader("Analysis Summary") | |
# Get existing summary from session state or initialize empty | |
if 'user_summary' not in st.session_state: | |
st.session_state.user_summary = "" | |
# Text area for user input | |
user_summary = st.text_area( | |
"Write your analysis summary here:", | |
value=st.session_state.user_summary, | |
height=300, | |
placeholder="Enter your observations, findings, and recommendations..." | |
) | |
# Save button for the summary | |
if st.button("Save Summary"): | |
st.session_state.user_summary = user_summary | |
st.success("Summary saved successfully!") | |
# Option to download the summary | |
if user_summary: | |
st.download_button( | |
label="π₯ Download Summary", | |
data=user_summary, | |
file_name="apk_analysis_summary.txt", | |
mime="text/plain" | |
) | |
except Exception as e: | |
st.error(f"Error analyzing APK: {str(e)}") | |
finally: | |
os.unlink(tmp_file_path) | |
else: | |
# Display welcome message when no file is uploaded | |
st.markdown( | |
""" | |
<div style='text-align: center; padding: 50px;'> | |
<h2>Welcome to APK Security Analyzer</h2> | |
<p>Upload an APK file using the sidebar to begin analysis</p> | |
</div> | |
""", | |
unsafe_allow_html=True, | |
) | |