Repository navigation
Expand file tree
/
Copy pathapp.py
More file actions
73 lines (60 loc) · 1.94 KB
/
Copy pathapp.py
File metadata and controls
73 lines (60 loc) · 1.94 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
import streamlit as st
from utils import clone_repo
from backend import process_repo, ask_question, generate_summary
st.set_page_config(page_title="AI Codebase Explainer", layout="wide")
# 🎨 UI Styling
st.markdown("""
<style>
.stTextInput input {
border-radius: 10px;
padding: 8px;
}
.stButton button {
background-color: #4CAF50;
color: white;
border-radius: 10px;
}
</style>
""", unsafe_allow_html=True)
st.title("💻 AI Codebase Explainer")
# Session state
if "db" not in st.session_state:
st.session_state.db = None
if "summary" not in st.session_state:
st.session_state.summary = None
# Input
repo_url = st.text_input("🔗 Enter GitHub Repository URL")
# Analyze Repo
if st.button("🚀 Analyze Repo"):
if not repo_url.startswith("https://github.com/"):
st.error("❌ Please enter a valid GitHub URL")
else:
with st.spinner("Cloning and analyzing repo..."):
try:
path = clone_repo(repo_url)
db = process_repo(path)
st.session_state.db = db
# 🔥 Auto Summary
summary = generate_summary(db)
st.session_state.summary = summary
st.success("✅ Repo analyzed successfully!")
except Exception as e:
st.error(f"Error: {e}")
# 📊 Show Summary
if st.session_state.summary:
st.markdown("## 📊 Project Overview")
st.write(st.session_state.summary)
# 💬 Chat Section
st.markdown("## 💬 Ask Questions")
query = st.text_input("Ask something about the code")
if st.button("Ask"):
if st.session_state.db:
with st.spinner("Thinking..."):
try:
answer = ask_question(st.session_state.db, query)
st.markdown("### 🤖 Answer")
st.write(answer)
except Exception as e:
st.error(f"Error: {e}")
else:
st.warning("⚠️ Please analyze a repo first!")