Team Ai
Apppublic

mikemichez/codebase-genius-agentic-code-documentation-system

sourceHugging Faceupdated 11mo agoView on Hugging Face
0likes
app.py137 linesDownload Raw Back to root
1python2import streamlit as st3import requests4import time5import os6from streamlit.components.v1 import html7 8# Custom CSS for dark theme9st.markdown("""10<style>11    :root {12        --primary: #6C63FF;13        --secondary: #8E2DE2;14    }15    16    body {17        background-color: #0E1117;18        color: #FFFFFF;19    }20    21    .stTextInput input {22        background-color: #1E1E1E !important;23        color: white !important;24    }25    26    .stButton button {27        background: linear-gradient(90deg, var(--primary), var(--secondary)) !important;28        color: white !important;29        border: none !important;30        border-radius: 8px !important;31    }32    33    .card {34        background-color: #1E1E1E;35        border-radius: 10px;36        padding: 20px;37        margin-bottom: 20px;38        border-left: 4px solid var(--primary);39    }40    41    .progress-message {42        padding: 10px;43        border-radius: 5px;44        margin: 5px 0;45        background-color: #252526;46        animation: fadeIn 0.5s;47    }48    49    @keyframes fadeIn {50        from { opacity: 0; }51        to { opacity: 1; }52    }53</style>54""", unsafe_allow_html=True)55 56# App title57st.title("🧠 Codebase Genius")58st.markdown("An AI-powered agentic system for automatic code documentation")59 60# Sidebar61with st.sidebar:62    st.header("Dashboard")63    64    # Health check65    try:66        health = requests.get("http://localhost:8000/health").json()67        st.success("✅ Backend connected")68    except:69        st.error("❌ Backend not available")70    71    # Recent analyses72    st.subheader("Recent Analyses")73    try:74        history = requests.get("http://localhost:8000/history").json()75        for repo in history["repos"]:76            st.markdown(f"- {repo['name']}")77    except:78        st.warning("No history available")79 80# Main content81with st.form("repo_form"):82    repo_url = st.text_input("GitHub Repository URL", placeholder="https://github.com/user/repo")83    submitted = st.form_submit_button("Analyze Repository")84 85if submitted and repo_url:86    # Start analysis87    with st.spinner("Starting analysis..."):88        response = requests.post(89            "http://localhost:8000/analyze",90            json={"repo_url": repo_url}91        ).json()92    93    if "status" in response and response["status"] == "started":94        # Show progress messages95        progress_container = st.container()96        97        messages = [98            ("Cloning repository...", 2),99            ("Mapping file structure...", 3),100            ("Analyzing code entities...", 5),101            ("Building relationships graph...", 3),102            ("Generating documentation...", 4)103        ]104        105        progress_bar = st.progress(0)106        107        for i, (msg, delay) in enumerate(messages):108            time.sleep(delay)109            progress_container.markdown(f'<div class="progress-message">🔹 {msg}</div>', unsafe_allow_html=True)110            progress_bar.progress((i + 1) * 20)111        112        # Show completion113        progress_container.markdown('<div class="progress-message">✅ Documentation generated!</div>', unsafe_allow_html=True)114        115        # Show preview116        repo_name = repo_url.split("/")[-1].replace(".git", "")117        try:118            docs_path = f"./outputs/{repo_name}/docs.md"119            if os.path.exists(docs_path):120                with open(docs_path, "r") as f:121                    docs_content = f.read()122                123                st.subheader("Documentation Preview")124                with st.expander("View Generated Documentation"):125                    st.markdown(docs_content)126                127                # Download button128                st.download_button(129                    label="Download Documentation",130                    data=docs_content,131                    file_name=f"{repo_name}_docs.md",132                    mime="text/markdown"133                )134        except Exception as e:135            st.error(f"Error loading documentation: {str(e)}")136 137</html>