File size: 2,716 Bytes
5c1462f
 
 
 
3e0d532
 
 
 
 
 
 
5c1462f
3e0d532
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import streamlit as st
from git import Repo
import shutil

from llama_index.core import (
    VectorStoreIndex,
    SimpleDirectoryReader,
    ServiceContext,
    SentenceSplitter,
)
from llama_index.llms.llama_cpp import LlamaCPP
from llama_index.embeddings.huggingface import HuggingFaceEmbedding

st.set_page_config(page_title="GitHub Repo Explainer", layout="wide")
st.title("πŸ“˜ GitHub Repository Explainer (100% Free)")

github_url = st.text_input("GitHub URL", placeholder="https://github.com/user/repo")

if st.button("Load and Analyze"):
    if github_url:
        try:
            # Clean previous repo if exists
            if os.path.exists("repo"):
                shutil.rmtree("repo")

            with st.spinner("πŸ“₯ Cloning GitHub repository..."):
                Repo.clone_from(github_url, "repo")
                st.success("βœ… Repo cloned successfully.")

            with st.spinner("πŸ”§ Loading LLM and embeddings..."):
                llm = LlamaCPP(
                    model_path="tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf",
                    temperature=0.7,
                    max_new_tokens=512,
                    context_window=2048,
                    generate_kwargs={"top_p": 0.95, "top_k": 50},
                    model_kwargs={"n_gpu_layers": 20, "n_batch": 512},
                    verbose=True,
                )

                embed_model = HuggingFaceEmbedding(
                    model_name="sentence-transformers/all-MiniLM-L6-v2"
                )

                service_context = ServiceContext.from_defaults(
                    llm=llm,
                    embed_model=embed_model,
                    node_parser=SentenceSplitter(chunk_size=512, chunk_overlap=50),
                )

            with st.spinner("πŸ“„ Reading and parsing files..."):
                docs = SimpleDirectoryReader("repo").load_data()
                st.write(f"πŸ“š {len(docs)} documents loaded.")

            with st.spinner("πŸ” Building index..."):
                index = VectorStoreIndex.from_documents(docs, service_context=service_context)
                query_engine = index.as_query_engine()

            with st.spinner("🧠 Querying the model..."):
                query = "Explain the purpose, structure, and setup steps of this GitHub repository."
                response = query_engine.query(query)

            st.subheader("🧾 Repository Summary")
            st.write(str(response))

        except Exception as e:
            st.error(f"❌ Something went wrong:\n\n{e}")
    else:
        st.warning("⚠️ Please enter a GitHub repo URL.")

if st.button("Reset"):
    shutil.rmtree("repo", ignore_errors=True)
    st.experimental_rerun()