Spaces:
Sleeping
Sleeping
added text streamer
Browse files- app.py +16 -9
- backend.py +3 -3
app.py
CHANGED
@@ -1,16 +1,23 @@
|
|
1 |
-
from backend import handle_query
|
2 |
import gradio as gr
|
3 |
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
#
|
10 |
-
|
11 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
|
14 |
if __name__ == "__main__":
|
15 |
progress=gr.Progress(track_tqdm=True)
|
16 |
-
|
|
|
1 |
+
from backend import handle_query, build_index
|
2 |
import gradio as gr
|
3 |
|
4 |
|
5 |
+
|
6 |
+
|
7 |
+
def setup_and_run():
|
8 |
+
# Call build_index() before starting the chat interface
|
9 |
+
build_index() # This builds the index on app initialization
|
10 |
+
|
11 |
+
# Pass the index into handle_query (you can modify handle_query to accept it as an argument if needed)
|
12 |
+
iface = gr.ChatInterface(
|
13 |
+
fn=handle_query, # Query handling remains here
|
14 |
+
title="PDF Information and Inference",
|
15 |
+
description="Retrieval-Augmented Generation - Ask me anything about the content of the PDF.",
|
16 |
+
)
|
17 |
+
|
18 |
+
iface.launch()
|
19 |
|
20 |
|
21 |
if __name__ == "__main__":
|
22 |
progress=gr.Progress(track_tqdm=True)
|
23 |
+
setup_and_run()
|
backend.py
CHANGED
@@ -41,7 +41,9 @@ parser = SentenceSplitter.from_defaults(
|
|
41 |
chunk_size=256, chunk_overlap=64, paragraph_separator="\n\n"
|
42 |
)
|
43 |
|
|
|
44 |
def build_index():
|
|
|
45 |
# Load documents from a file
|
46 |
documents = SimpleDirectoryReader(input_files=["data/blockchainprova.txt"]).load_data()
|
47 |
# Parse the documents into nodes
|
@@ -52,11 +54,9 @@ def build_index():
|
|
52 |
return index
|
53 |
|
54 |
|
55 |
-
index = build_index()
|
56 |
-
|
57 |
@spaces.GPU(duration=20)
|
58 |
def handle_query(query_str, chathistory):
|
59 |
-
|
60 |
|
61 |
qa_prompt_str = (
|
62 |
"Context information is below.\n"
|
|
|
41 |
chunk_size=256, chunk_overlap=64, paragraph_separator="\n\n"
|
42 |
)
|
43 |
|
44 |
+
index = None
|
45 |
def build_index():
|
46 |
+
global index
|
47 |
# Load documents from a file
|
48 |
documents = SimpleDirectoryReader(input_files=["data/blockchainprova.txt"]).load_data()
|
49 |
# Parse the documents into nodes
|
|
|
54 |
return index
|
55 |
|
56 |
|
|
|
|
|
57 |
@spaces.GPU(duration=20)
|
58 |
def handle_query(query_str, chathistory):
|
59 |
+
global index
|
60 |
|
61 |
qa_prompt_str = (
|
62 |
"Context information is below.\n"
|