Anaghasss commited on
Commit
334dffa
·
verified ·
1 Parent(s): 361a8ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -57
app.py CHANGED
@@ -1,57 +0,0 @@
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
- # Streamlit app setup
11
- st.set_page_config(page_title="GitHub Repo Explainer", layout="wide")
12
- st.title("📘 GitHub Repository Explainer (100% Free)")
13
-
14
- github_url = st.text_input("Enter GitHub Repository URL:", placeholder="https://github.com/user/repo")
15
-
16
- if st.button("Load and Analyze"):
17
- if github_url:
18
- try:
19
- # Clone repo
20
- if os.path.exists("repo"):
21
- shutil.rmtree("repo")
22
- Repo.clone_from(github_url, "repo")
23
-
24
- # Load the TinyLlama model
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": 20, "n_batch": 512},
31
- verbose=True,
32
- )
33
-
34
- # Setup embedding and service context
35
- embed_model = HuggingFaceEmbedding(model_name="sentence-transformers/all-MiniLM-L6-v2")
36
- service_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model)
37
- parser = SimpleNodeParser.from_defaults()
38
-
39
- # Load and parse docs
40
- documents = SimpleDirectoryReader("repo").load_data()
41
- nodes = parser.get_nodes_from_documents(documents)
42
- index = VectorStoreIndex(nodes, service_context=service_context)
43
-
44
- query_engine = index.as_query_engine()
45
- response = query_engine.query("Explain the purpose, structure, and setup steps of this GitHub repository.")
46
-
47
- st.subheader("🧠 Repository Summary")
48
- st.write(str(response))
49
-
50
- except Exception as e:
51
- st.error(f"Error: {e}")
52
- else:
53
- st.warning("Please enter a GitHub URL.")
54
-
55
- if st.button("Reset"):
56
- shutil.rmtree("repo", ignore_errors=True)
57
- st.experimental_rerun()