Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -20,7 +20,7 @@ def load_vector_store(embedding_model_name, vector_store_file, k=4):
|
|
20 |
retriever = vector_store.as_retriever(search_kwargs={"k": k})
|
21 |
return retriever
|
22 |
|
23 |
-
def fetch_response(groq_api_key, user_input
|
24 |
chat = ChatGroq(
|
25 |
api_key = groq_api_key,
|
26 |
model_name = model_name
|
@@ -41,19 +41,17 @@ def fetch_response(groq_api_key, user_input, retriever1, retriever2):
|
|
41 |
# ドキュメントのリストを渡せるchainを作成
|
42 |
question_answer_chain = create_stuff_documents_chain(chat, prompt)
|
43 |
# RetrieverとQAチェーンを組み合わせてRAGチェーンを作成
|
44 |
-
rag_chain = create_retrieval_chain(
|
45 |
-
rag_chain2 = create_retrieval_chain(retriever2, question_answer_chain)
|
46 |
|
47 |
response = rag_chain.invoke({"input": user_input})
|
48 |
-
|
49 |
-
return [response["answer"], response["context"][0], response["context"][1], response2["answer"], response2["context"][0], response2["context"][1]]
|
50 |
|
51 |
|
52 |
"""
|
53 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
54 |
"""
|
55 |
retriever = load_vector_store(emb_model_name, "kaihatsu_vector_store", 4)
|
56 |
-
retriever_rechunk = load_vector_store(emb_model_name, "kaihatsu_vector_store_rechunk", 4)
|
57 |
|
58 |
with gr.Blocks() as demo:
|
59 |
gr.Markdown('''# 「スマート農業技術の開発・供給に関する事業」マスター \n
|
@@ -66,16 +64,13 @@ with gr.Blocks() as demo:
|
|
66 |
user_input = gr.Textbox(label="User Input")
|
67 |
submit = gr.Button("Submit")
|
68 |
answer = gr.Textbox(label="Answer")
|
69 |
-
answer2 = gr.Textbox(label="Answer")
|
70 |
with gr.Row():
|
71 |
with gr.Column():
|
72 |
source1 = gr.Textbox(label="回答ソース1")
|
73 |
-
source2_1 = gr.Textbox(label="回答ソース1")
|
74 |
with gr.Column():
|
75 |
source2 = gr.Textbox(label="回答ソース2")
|
76 |
-
source2_2 = gr.Textbox(label="回答ソース2")
|
77 |
|
78 |
-
submit.click(fetch_response, inputs=[api_key, user_input
|
79 |
|
80 |
if __name__ == "__main__":
|
81 |
demo.launch()
|
|
|
20 |
retriever = vector_store.as_retriever(search_kwargs={"k": k})
|
21 |
return retriever
|
22 |
|
23 |
+
def fetch_response(groq_api_key, user_input):
|
24 |
chat = ChatGroq(
|
25 |
api_key = groq_api_key,
|
26 |
model_name = model_name
|
|
|
41 |
# ドキュメントのリストを渡せるchainを作成
|
42 |
question_answer_chain = create_stuff_documents_chain(chat, prompt)
|
43 |
# RetrieverとQAチェーンを組み合わせてRAGチェーンを作成
|
44 |
+
rag_chain = create_retrieval_chain(retriever, question_answer_chain)
|
|
|
45 |
|
46 |
response = rag_chain.invoke({"input": user_input})
|
47 |
+
return [response["answer"], response["context"][0], response["context"][1]]
|
|
|
48 |
|
49 |
|
50 |
"""
|
51 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
52 |
"""
|
53 |
retriever = load_vector_store(emb_model_name, "kaihatsu_vector_store", 4)
|
54 |
+
#retriever_rechunk = load_vector_store(emb_model_name, "kaihatsu_vector_store_rechunk", 4)
|
55 |
|
56 |
with gr.Blocks() as demo:
|
57 |
gr.Markdown('''# 「スマート農業技術の開発・供給に関する事業」マスター \n
|
|
|
64 |
user_input = gr.Textbox(label="User Input")
|
65 |
submit = gr.Button("Submit")
|
66 |
answer = gr.Textbox(label="Answer")
|
|
|
67 |
with gr.Row():
|
68 |
with gr.Column():
|
69 |
source1 = gr.Textbox(label="回答ソース1")
|
|
|
70 |
with gr.Column():
|
71 |
source2 = gr.Textbox(label="回答ソース2")
|
|
|
72 |
|
73 |
+
submit.click(fetch_response, inputs=[api_key, user_input], outputs=[answer, source1, source2])
|
74 |
|
75 |
if __name__ == "__main__":
|
76 |
demo.launch()
|