Spaces:
Build error
Build error
Commit ·
5f01ac8
1
Parent(s): 2c0c67c
intial implementation
Browse files- .env.template +4 -0
- .gitignore +2 -0
- app.py +69 -0
- requirements.txt +6 -0
.env.template
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
NUMEXPR_MAX_THREADS
|
| 2 |
+
NUMEXPR_NUM_THREADS
|
| 3 |
+
OPENAI_API_KEY
|
| 4 |
+
GITHUB_TOKEN
|
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.env
|
| 2 |
+
*.pkl
|
app.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import openai
|
| 3 |
+
import numexpr as ne
|
| 4 |
+
import pickle
|
| 5 |
+
import os
|
| 6 |
+
import nest_asyncio
|
| 7 |
+
import streamlit as st
|
| 8 |
+
|
| 9 |
+
from dotenv import load_dotenv
|
| 10 |
+
from llama_index import download_loader, VectorStoreIndex
|
| 11 |
+
from llama_hub.github_repo import GithubClient, GithubRepositoryReader
|
| 12 |
+
|
| 13 |
+
load_dotenv()
|
| 14 |
+
|
| 15 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 16 |
+
|
| 17 |
+
nest_asyncio.apply()
|
| 18 |
+
|
| 19 |
+
def load_repo(owner, repo):
|
| 20 |
+
download_loader("GithubRepositoryReader")
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def load_answer(question):
|
| 24 |
+
download_loader("GithubRepositoryReader")
|
| 25 |
+
|
| 26 |
+
docs = None
|
| 27 |
+
if os.path.exists("docs.pkl"):
|
| 28 |
+
with open("docs.pkl", "rb") as f:
|
| 29 |
+
docs = pickle.load(f)
|
| 30 |
+
|
| 31 |
+
if docs is None:
|
| 32 |
+
github_client = GithubClient(os.getenv("GITHUB_TOKEN"))
|
| 33 |
+
loader = GithubRepositoryReader(
|
| 34 |
+
github_client,
|
| 35 |
+
owner = "bcatania18",
|
| 36 |
+
repo = "onerail-core-shared",
|
| 37 |
+
filter_directories = (["src", "test"], GithubRepositoryReader.FilterType.INCLUDE),
|
| 38 |
+
filter_file_extensions = ([".ts"], GithubRepositoryReader.FilterType.INCLUDE),
|
| 39 |
+
verbose = True,
|
| 40 |
+
concurrent_requests = 10,
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
docs = loader.load_data(branch="main")
|
| 44 |
+
|
| 45 |
+
with open("docs.pkl", "wb") as f:
|
| 46 |
+
pickle.dump(docs, f)
|
| 47 |
+
|
| 48 |
+
index = VectorStoreIndex.from_documents(docs)
|
| 49 |
+
|
| 50 |
+
query_engine = index.as_query_engine()
|
| 51 |
+
|
| 52 |
+
response = query_engine.query(question)
|
| 53 |
+
return response
|
| 54 |
+
|
| 55 |
+
def get_text():
|
| 56 |
+
input_text = st.text_input("Question", key="input")
|
| 57 |
+
return input_text
|
| 58 |
+
|
| 59 |
+
st.set_page_config(page_title="Code Analysis", page_icon=":robot:")
|
| 60 |
+
st.header("Ask a question")
|
| 61 |
+
|
| 62 |
+
user_input = get_text()
|
| 63 |
+
answer = load_answer(user_input)
|
| 64 |
+
|
| 65 |
+
submit = st.button("Generate answer")
|
| 66 |
+
|
| 67 |
+
if submit:
|
| 68 |
+
st.subheader("Answer:")
|
| 69 |
+
st.write(answer.response)
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
nltk
|
| 2 |
+
numexpr
|
| 3 |
+
llama_index
|
| 4 |
+
langchain
|
| 5 |
+
Openai
|
| 6 |
+
Streamlit
|