Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -63,43 +63,6 @@ def get_text_embedding(text):
|
|
63 |
doc_path = hf_hub_download(repo_id="xavierbarbier/rag_ngap", filename="resource/embeddings_ngap.faiss", repo_type="space")
|
64 |
|
65 |
index = faiss.read_index(doc_path)
|
66 |
-
"""
|
67 |
-
reader = PdfReader( doc_path )
|
68 |
-
|
69 |
-
|
70 |
-
text = []
|
71 |
-
for p in np.arange(0, len(reader.pages), 1):
|
72 |
-
page = reader.pages[int(p)]
|
73 |
-
|
74 |
-
# extracting text from page
|
75 |
-
text.append(page.extract_text())
|
76 |
-
|
77 |
-
text = ' '.join(text)
|
78 |
-
|
79 |
-
chunks = [text[i:i + chunk_size] for i in range(0, len(text), chunk_size)]
|
80 |
-
|
81 |
-
text_embeddings = np.array([get_text_embedding(chunk) for chunk in chunks])
|
82 |
-
|
83 |
-
d = text_embeddings.shape[1]
|
84 |
-
index = faiss.IndexFlatL2(d)
|
85 |
-
index.add(text_embeddings)"""
|
86 |
-
|
87 |
-
|
88 |
-
def extract_text(file):
|
89 |
-
|
90 |
-
|
91 |
-
reader = PdfReader(file)
|
92 |
-
|
93 |
-
text = []
|
94 |
-
for p in np.arange(0, len(reader.pages), 1):
|
95 |
-
page = reader.pages[int(p)]
|
96 |
-
|
97 |
-
# extracting text from page
|
98 |
-
text.append(page.extract_text())
|
99 |
-
|
100 |
-
text = ' '.join(text)
|
101 |
-
|
102 |
-
return text
|
103 |
|
104 |
def qa(question):
|
105 |
|
@@ -122,8 +85,6 @@ def qa(question):
|
|
122 |
|
123 |
return prompt
|
124 |
|
125 |
-
def test_func(text):
|
126 |
-
return len(index)
|
127 |
|
128 |
with gr.Blocks() as demo:
|
129 |
|
@@ -133,7 +94,7 @@ with gr.Blocks() as demo:
|
|
133 |
promp_output = gr.Textbox(label="prompt")
|
134 |
|
135 |
|
136 |
-
qa_button.click(
|
137 |
|
138 |
|
139 |
|
|
|
63 |
doc_path = hf_hub_download(repo_id="xavierbarbier/rag_ngap", filename="resource/embeddings_ngap.faiss", repo_type="space")
|
64 |
|
65 |
index = faiss.read_index(doc_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
def qa(question):
|
68 |
|
|
|
85 |
|
86 |
return prompt
|
87 |
|
|
|
|
|
88 |
|
89 |
with gr.Blocks() as demo:
|
90 |
|
|
|
94 |
promp_output = gr.Textbox(label="prompt")
|
95 |
|
96 |
|
97 |
+
qa_button.click(qa, question_input, promp_output)
|
98 |
|
99 |
|
100 |
|