File size: 1,838 Bytes
98dff20 |
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 |
from wiki_kb_qa_migrate import *
'''
zh_question = "哈利波特的血缘是什么?"
#output = from_zh_question_to_consider_queries(zh_question)
output = from_zh_question_to_consider_queries(zh_question,
top_k = 32, top_p_k = 30, top_e_k = 50
)
if type(output) == type((1,)):
query_list, output = output
zh_output = trans_output(zh_question ,output)
else:
zh_output = None
zh_output
ranking_output(zh_question, zh_output)
'''
import gradio as gr
example_sample = [
"哈利波特的血缘是什么?",
"哈利波特的生日是什么?",
"占卜会议的领导者是谁?",
"纽约卫生局的创立时间是什么?",
"哥布林叛乱发生在什么日期?",
"赫敏的丈夫是谁?",
]
def demo_func(zh_question):
assert type(zh_question) == type("")
output = from_zh_question_to_consider_queries(zh_question,
top_k = 32, top_p_k = 30, top_e_k = 50
)
if type(output) == type((1,)):
query_list, output = output
zh_output = trans_output(zh_question ,output)
else:
zh_output = None
#zh_output
zh_output = ranking_output(zh_question, zh_output)
if hasattr(zh_output, "to_dict"):
zh_output = zh_output.head(5)
zh_output = zh_output[["answer", "sparql_query"]].values.tolist()
return {"output": zh_output}
demo = gr.Interface(
fn=demo_func,
inputs="text",
outputs="json",
title=f"Harry Potter Knowledge Question Answer in Chinese 🧙 demonstration",
examples=example_sample if example_sample else None,
cache_examples = False,
)
demo.launch(server_name=None, server_port=None)
|