File size: 2,794 Bytes
bcbfa25
 
66f25b3
 
 
 
a429de7
bcbfa25
a429de7
 
bcbfa25
 
66f25b3
 
bd8dfe3
 
66f25b3
bcbfa25
66f25b3
bd8dfe3
 
66f25b3
 
 
 
 
 
 
 
74960c8
66f25b3
 
 
 
 
 
 
 
 
 
 
660ebeb
 
5d94033
f83444a
f78916b
660ebeb
 
 
66f25b3
 
 
 
 
 
 
 
5d94033
66f25b3
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os

from langchain.vectorstores import Qdrant
from langchain.embeddings import HuggingFaceEmbeddings
from qdrant_client import QdrantClient
import gradio as gr
from transformers.utils import logging

logging.set_verbosity_info()
logger = logging.get_logger("transformers")
qdrant_url = os.environ['QDRANT_URL']
qdrant_api_key = os.environ['QDRANT_API_KEY']

def process_text(input_text, top_k):
    embeddings = HuggingFaceEmbeddings(model_name="intfloat/multilingual-e5-base")
    # embeddings = HuggingFaceEmbeddings(model_name="cl-nagoya/sup-simcse-ja-large")
    client = QdrantClient(
        url=qdrant_url, api_key=qdrant_api_key, prefer_grpc=False,
    )
    db = Qdrant(client=client, embeddings=embeddings, collection_name="qa_data_without_cardname")
    # db = Qdrant(client=client, embeddings=embeddings, collection_name="qa_data_without_cardname_ssjl")
    query = input_text

    all_answers = []
    docs = db.similarity_search_with_score(query=query, k=top_k)
    for i in docs:
        doc, score = i
        all_answers.append(doc.metadata["source"])

    return "\n***\n".join(all_answers)

CSS ="""
.contain { display: flex; flex-direction: column; }
.gradio-container { height: 100vh !important; }
#component-0 { height: 100%; }
#textbox { flex-grow: 1; overflow: auto; resize: vertical; }
.secondary {background-color: #6366f1; }
"""
#with gr.Blocks() as demo:
with gr.Blocks(theme=gr.themes.Monochrome(radius_size=gr.themes.sizes.radius_sm)) as demo:
    with gr.Row():
        with gr.Column():
            gr.Markdown(f"""
                    ### ・非公式サイトです  
                    ### ・デモでしかないので速度・精度・動作は保証しないし新しい裁定にも対応しません。突然消す可能性もあり
                    ### ・ですます調で質問をすると精度が上がるかも
                    """)
    with gr.Row():
        gr.Markdown("# デュエマ裁定検索(非公式)")
    with gr.Row():
        output = gr.TextArea(
            elem_id="検索結果",
            label="検索結果",
        )
    with gr.Row():
        input = gr.Textbox(
            label="質問",
            placeholder="ここに質問を入力(ex:芸魔龍王アメイジンの出た時の効果は、後から出たクリーチャーも影響しますか)",
            lines=3,
        )
    with gr.Row():
        submit = gr.Button(value="検索", variant="secondary").style(full_width=True)
        top_k = gr.Slider(1, 10, label="表示数", step=1, value=5, interactive=True)
    
    submit_click_event = submit.click(fn=process_text, inputs=[input, top_k], outputs=output)

demo.launch()
# demo.queue(max_size=128, concurrency_count=48).launch(debug=True, server_name="0.0.0.0", server_port=7860)