Spaces:
Sleeping
Sleeping
add newfiles
Browse files- .gitattributes +1 -0
- app.py +53 -0
- local_qdrant/.lock +1 -0
- local_qdrant/collection/qa_data/storage.sqlite +3 -0
- local_qdrant/meta.json +1 -0
- requirements.txt +4 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
local_qdrant/collection/qa_data/storage.sqlite filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from langchain.vectorstores import Qdrant
|
2 |
+
from langchain.embeddings import HuggingFaceEmbeddings
|
3 |
+
from qdrant_client import QdrantClient
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
def process_text(input_text, top_k):
|
7 |
+
embeddings = HuggingFaceEmbeddings(model_name="intfloat/multilingual-e5-base")
|
8 |
+
client = QdrantClient(
|
9 |
+
path="./local_qdrant", prefer_grpc=True
|
10 |
+
)
|
11 |
+
db = Qdrant(client=client, embeddings=embeddings, collection_name="qa_data")
|
12 |
+
|
13 |
+
query = input_text
|
14 |
+
|
15 |
+
all_answers = []
|
16 |
+
docs = db.similarity_search_with_score(query=query, k=top_k)
|
17 |
+
for i in docs:
|
18 |
+
doc, score = i
|
19 |
+
print({"score": score, "content": doc.page_content, "metadata": doc.metadata} )
|
20 |
+
all_answers.append(doc.metadata["source"])
|
21 |
+
|
22 |
+
return "\n***\\n".join(all_answers)
|
23 |
+
|
24 |
+
CSS ="""
|
25 |
+
.contain { display: flex; flex-direction: column; }
|
26 |
+
.gradio-container { height: 100vh !important; }
|
27 |
+
#component-0 { height: 100%; }
|
28 |
+
#textbox { flex-grow: 1; overflow: auto; resize: vertical; }
|
29 |
+
.secondary {background-color: #6366f1; }
|
30 |
+
"""
|
31 |
+
#with gr.Blocks() as demo:
|
32 |
+
with gr.Blocks(theme=gr.themes.Monochrome(radius_size=gr.themes.sizes.radius_sm)) as demo:
|
33 |
+
with gr.Row():
|
34 |
+
gr.Markdown("# 裁定検索")
|
35 |
+
with gr.Row():
|
36 |
+
output = gr.TextArea(
|
37 |
+
elem_id="検索結果",
|
38 |
+
label="検索結果",
|
39 |
+
)
|
40 |
+
with gr.Row():
|
41 |
+
input = gr.Textbox(
|
42 |
+
label="質問",
|
43 |
+
placeholder="芸魔龍王アメイジンの出た時の効果は、後から出たクリーチャーも影響しますか",
|
44 |
+
lines=3,
|
45 |
+
)
|
46 |
+
with gr.Row():
|
47 |
+
submit = gr.Button(value="検索", variant="secondary").style(full_width=True)
|
48 |
+
top_k = gr.Slider(1, 10, label="表示数", step=1, value=5, interactive=True)
|
49 |
+
|
50 |
+
submit_click_event = submit.click(fn=process_text, inputs=[input, top_k], outputs=output)
|
51 |
+
|
52 |
+
demo.launch()
|
53 |
+
# demo.queue(max_size=128, concurrency_count=48).launch(debug=True, server_name="0.0.0.0", server_port=7860)
|
local_qdrant/.lock
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
tmp lock file
|
local_qdrant/collection/qa_data/storage.sqlite
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:59593dd8ca06ee6d0708e9e27e1fe1383e67db9a14145b0000e0ae75ca7a0279
|
3 |
+
size 26202112
|
local_qdrant/meta.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"collections": {"qa_data": {"vectors": {"size": 768, "distance": "Cosine", "hnsw_config": null, "quantization_config": null, "on_disk": null}, "shard_number": null, "replication_factor": null, "write_consistency_factor": null, "on_disk_payload": null, "hnsw_config": null, "wal_config": null, "optimizers_config": null, "init_from": null, "quantization_config": null}}, "aliases": {}}
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
langchain==0.0.312
|
2 |
+
qdrant-client==1.6.0
|
3 |
+
sentence-transformers==2.2.2
|
4 |
+
gradio==3.47.1
|