Spaces:
Runtime error
Runtime error
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) | |