-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamlit_app.py
More file actions
101 lines (82 loc) · 2.93 KB
/
streamlit_app.py
File metadata and controls
101 lines (82 loc) · 2.93 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
89
90
91
92
93
94
95
96
97
98
99
100
101
import streamlit as st
import subprocess
import tempfile
import os
import glob
import json
import time
from pathlib import Path
st.set_page_config(page_title="Codebase Analyzer — Demo", layout="wide")
st.title("Codebase Analyzer — Recruiter Demo")
st.markdown(
"Analyze any GitHub repository and generate insights into its Python codebase. "
"This UI uses your existing `run_analysis.py` script and displays the generated JSON output."
)
st.divider()
# -------------------------
# INPUT SECTION
# -------------------------
git_url = st.text_input(
"Enter GitHub Repository URL",
placeholder="https://github.com/user/repo",
)
run_btn = st.button("Run Analysis")
# -------------------------
# Helper: find latest analysis JSON
# -------------------------
def find_latest_json():
json_files = glob.glob("analysis_*.json")
if not json_files:
return None
return max(json_files, key=os.path.getmtime)
# -------------------------
# RUN ANALYSIS
# -------------------------
if run_btn:
if not git_url.strip():
st.error("Please enter a GitHub repository URL.")
st.stop()
st.info("Running analysis... This may take 10–60 seconds depending on repo size.")
cmd = ["python", "run_analysis.py", "--url", git_url]
with st.spinner("Analyzing repository..."):
try:
# Run script
process = subprocess.run(
cmd, capture_output=True, text=True, timeout=300
)
except subprocess.TimeoutExpired:
st.error("❌ Script timed out. Try a smaller repository.")
st.stop()
# Display script output (stdout/stderr)
with st.expander("🔍 Script Output (stdout)"):
st.text(process.stdout)
with st.expander("⚠️ Script Errors (stderr)"):
st.text(process.stderr)
# Check return code
if process.returncode != 0:
st.error("❌ Script failed. Check stderr above.")
st.stop()
# Find latest analysis JSON
json_path = find_latest_json()
if not json_path:
st.error("❌ No analysis_*.json file generated. Script may not have run correctly.")
st.stop()
st.success(f"Analysis completed! Loaded results from `{json_path}`")
# Load JSON
with open(json_path, "r", encoding="utf-8") as f:
data = json.load(f)
# -------------------------
# DISPLAY JSON RESULTS
# -------------------------
st.header("📌 Summary")
st.json(data.get("summary", {}))
st.header("📁 File Reports")
st.write("Showing Python file analysis results:")
st.json(data.get("file_reports", []))
# Optional: Download JSON
st.download_button(
label="📥 Download Analysis JSON",
data=json.dumps(data, indent=2),
file_name=os.path.basename(json_path),
mime="application/json",
)