Spaces:
Sleeping
Sleeping
fixed index
Browse files- backend.py +8 -25
backend.py
CHANGED
@@ -50,39 +50,22 @@ Settings.llm = GemmaLLMInterface(model=model, tokenizer=tokenizer)
|
|
50 |
|
51 |
############################---------------------------------
|
52 |
|
53 |
-
#
|
54 |
-
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
global index
|
59 |
-
try:
|
60 |
-
# Reading documents from disk
|
61 |
-
documents = SimpleDirectoryReader(input_files=["data/blockchainprova.txt"]).load_data()
|
62 |
-
|
63 |
-
# Splitting the document into chunks
|
64 |
-
parser = SentenceSplitter.from_defaults(
|
65 |
chunk_size=256, chunk_overlap=64, paragraph_separator="\n\n"
|
66 |
)
|
67 |
-
|
68 |
-
|
69 |
-
# BUILD A VECTOR STORE
|
70 |
-
index = VectorStoreIndex(nodes)
|
71 |
-
print("Index initialized successfully")
|
72 |
-
except Exception as e:
|
73 |
-
print(f"Error initializing index: {str(e)}")
|
74 |
-
index = None
|
75 |
|
|
|
|
|
76 |
|
77 |
-
initialize_index()
|
78 |
|
79 |
@spaces.GPU(duration=120)
|
80 |
def handle_query(query_str, chathistory):
|
81 |
-
|
82 |
-
|
83 |
-
if index is None:
|
84 |
-
yield "Error: Index not initialized. Please try again later."
|
85 |
-
return
|
86 |
|
87 |
qa_prompt_str = (
|
88 |
"Context information is below.\n"
|
|
|
50 |
|
51 |
############################---------------------------------
|
52 |
|
53 |
+
# Reading documents from disk
|
54 |
+
documents = SimpleDirectoryReader(input_files=["data/blockchainprova.txt"]).load_data()
|
55 |
|
56 |
+
# Splitting the document into chunks
|
57 |
+
parser = SentenceSplitter.from_defaults(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
chunk_size=256, chunk_overlap=64, paragraph_separator="\n\n"
|
59 |
)
|
60 |
+
nodes = parser.get_nodes_from_documents(documents)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
+
# BUILD A VECTOR STORE
|
63 |
+
index = VectorStoreIndex(nodes)
|
64 |
|
|
|
65 |
|
66 |
@spaces.GPU(duration=120)
|
67 |
def handle_query(query_str, chathistory):
|
68 |
+
|
|
|
|
|
|
|
|
|
69 |
|
70 |
qa_prompt_str = (
|
71 |
"Context information is below.\n"
|