Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -52,6 +52,31 @@ login(HF_TOKEN)
|
|
| 52 |
api = HfApi()
|
| 53 |
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
def rag_workflow(query):
|
| 56 |
"""
|
| 57 |
RAGChain class to perform the complete RAG workflow.
|
|
@@ -98,32 +123,14 @@ def rag_workflow(query):
|
|
| 98 |
|
| 99 |
return response
|
| 100 |
|
| 101 |
-
|
| 102 |
-
def initialize():
|
| 103 |
-
global vectorstore, chunks, llm
|
| 104 |
-
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
doc_texts, doc_references = extract_repo_files(DATA_DIR, [], [])
|
| 111 |
-
|
| 112 |
-
print("LEEEEEEEEEEEENGTH of code_texts: ", len(code_texts))
|
| 113 |
-
print("LEEEEEEEEEEEENGTH of doc_files: ", len(doc_texts))
|
| 114 |
-
|
| 115 |
-
code_chunks = chunk_pythoncode_and_add_metadata(code_texts, code_references)
|
| 116 |
-
doc_chunks = chunk_text_and_add_metadata(doc_texts, doc_references, CHUNK_SIZE, CHUNK_OVERLAP)
|
| 117 |
-
|
| 118 |
-
print(f"Total number of code_chunks: {len(code_chunks)}")
|
| 119 |
-
print(f"Total number of doc_chunks: {len(doc_chunks)}")
|
| 120 |
|
| 121 |
-
|
| 122 |
-
llm = get_groq_llm(LLM_MODEL_NAME, LLM_MODEL_TEMPERATURE, GROQ_API_KEY)
|
| 123 |
|
| 124 |
-
from langchain_community.document_loaders import TextLoader
|
| 125 |
-
|
| 126 |
-
initialize()
|
| 127 |
|
| 128 |
|
| 129 |
# Gradio utils
|
|
@@ -140,14 +147,6 @@ def add_text(history, text):
|
|
| 140 |
|
| 141 |
import gradio as gr
|
| 142 |
|
| 143 |
-
|
| 144 |
-
def bot_kadi(history):
|
| 145 |
-
user_query = history[-1][0]
|
| 146 |
-
response = rag_workflow(user_query)
|
| 147 |
-
history[-1] = (user_query, response)
|
| 148 |
-
|
| 149 |
-
yield history
|
| 150 |
-
|
| 151 |
def main():
|
| 152 |
with gr.Blocks() as demo:
|
| 153 |
gr.Markdown("## KadiAPY - AI Coding-Assistant")
|
|
|
|
| 52 |
api = HfApi()
|
| 53 |
|
| 54 |
|
| 55 |
+
def initialize():
|
| 56 |
+
global vectorstore, chunks, llm
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
download_gitlab_repo_to_hfspace(GITLAB_API_URL, GITLAB_PROJECT_ID, GITLAB_PROJECT_VERSION)
|
| 60 |
+
|
| 61 |
+
code_texts, code_references = extract_repo_files(DATA_DIR, ['kadi_apy'], [])
|
| 62 |
+
#doc_texts, doc_references = extract_files_and_filepath_from_dir(DATA_DIR, ['docs/source/'], [])
|
| 63 |
+
doc_texts, doc_references = extract_repo_files(DATA_DIR, [], [])
|
| 64 |
+
|
| 65 |
+
print("LEEEEEEEEEEEENGTH of code_texts: ", len(code_texts))
|
| 66 |
+
print("LEEEEEEEEEEEENGTH of doc_files: ", len(doc_texts))
|
| 67 |
+
|
| 68 |
+
code_chunks = chunk_pythoncode_and_add_metadata(code_texts, code_references)
|
| 69 |
+
doc_chunks = chunk_text_and_add_metadata(doc_texts, doc_references, CHUNK_SIZE, CHUNK_OVERLAP)
|
| 70 |
+
|
| 71 |
+
print(f"Total number of code_chunks: {len(code_chunks)}")
|
| 72 |
+
print(f"Total number of doc_chunks: {len(doc_chunks)}")
|
| 73 |
+
|
| 74 |
+
vectorstore = setup_vectorstore(doc_chunks + code_chunks, EMBEDDING_MODEL_NAME, VECTORSTORE_DIRECTORY)
|
| 75 |
+
llm = get_groq_llm(LLM_MODEL_NAME, LLM_MODEL_TEMPERATURE, GROQ_API_KEY)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
initialize()
|
| 79 |
+
|
| 80 |
def rag_workflow(query):
|
| 81 |
"""
|
| 82 |
RAGChain class to perform the complete RAG workflow.
|
|
|
|
| 123 |
|
| 124 |
return response
|
| 125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
+
def bot_kadi(history):
|
| 128 |
+
user_query = history[-1][0]
|
| 129 |
+
response = rag_workflow(user_query)
|
| 130 |
+
history[-1] = (user_query, response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
+
yield history
|
|
|
|
| 133 |
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
|
| 136 |
# Gradio utils
|
|
|
|
| 147 |
|
| 148 |
import gradio as gr
|
| 149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
def main():
|
| 151 |
with gr.Blocks() as demo:
|
| 152 |
gr.Markdown("## KadiAPY - AI Coding-Assistant")
|