Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import streamlit as st
|
3 |
+
from git import Repo
|
4 |
+
import shutil
|
5 |
+
from llama_index import VectorStoreIndex, SimpleDirectoryReader, ServiceContext
|
6 |
+
from llama_index.llms.llama_cpp import LlamaCPP
|
7 |
+
from llama_index.embeddings import HuggingFaceEmbedding
|
8 |
+
from llama_index.node_parser import SimpleNodeParser
|
9 |
+
|
10 |
+
st.set_page_config(page_title="π GitHub Repo Explainer", layout="wide")
|
11 |
+
st.title("π GitHub Repository Explainer")
|
12 |
+
|
13 |
+
github_url = st.text_input("Enter GitHub URL:", placeholder="https://github.com/user/repo")
|
14 |
+
|
15 |
+
if st.button("Analyze Repo") and github_url:
|
16 |
+
try:
|
17 |
+
# Cleanup old repo
|
18 |
+
if os.path.exists("repo"):
|
19 |
+
shutil.rmtree("repo")
|
20 |
+
|
21 |
+
# Clone repo
|
22 |
+
Repo.clone_from(github_url, "repo")
|
23 |
+
|
24 |
+
# Load model + embeddings
|
25 |
+
llm = LlamaCPP(
|
26 |
+
model_path="tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf",
|
27 |
+
temperature=0.7,
|
28 |
+
max_new_tokens=512,
|
29 |
+
context_window=2048,
|
30 |
+
model_kwargs={"n_gpu_layers": 0},
|
31 |
+
verbose=True
|
32 |
+
)
|
33 |
+
|
34 |
+
embed_model = HuggingFaceEmbedding(model_name="sentence-transformers/all-MiniLM-L6-v2")
|
35 |
+
service_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model)
|
36 |
+
|
37 |
+
# Load documents and build index
|
38 |
+
documents = SimpleDirectoryReader("repo").load_data()
|
39 |
+
parser = SimpleNodeParser()
|
40 |
+
nodes = parser.get_nodes_from_documents(documents)
|
41 |
+
index = VectorStoreIndex(nodes, service_context=service_context)
|
42 |
+
|
43 |
+
# Query the index
|
44 |
+
query_engine = index.as_query_engine()
|
45 |
+
response = query_engine.query("Explain the purpose, structure, and setup of this repository.")
|
46 |
+
st.subheader("π§ Repository Summary")
|
47 |
+
st.write(str(response))
|
48 |
+
|
49 |
+
except Exception as e:
|
50 |
+
st.error(f"Error: {e}")
|