svjack commited on
Commit
98dff20
1 Parent(s): 03c1af1

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +56 -0
  2. requirements.txt +11 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from wiki_kb_qa_migrate import *
2
+
3
+ '''
4
+ zh_question = "哈利波特的血缘是什么?"
5
+ #output = from_zh_question_to_consider_queries(zh_question)
6
+ output = from_zh_question_to_consider_queries(zh_question,
7
+ top_k = 32, top_p_k = 30, top_e_k = 50
8
+ )
9
+ if type(output) == type((1,)):
10
+ query_list, output = output
11
+ zh_output = trans_output(zh_question ,output)
12
+ else:
13
+ zh_output = None
14
+ zh_output
15
+ ranking_output(zh_question, zh_output)
16
+ '''
17
+
18
+ import gradio as gr
19
+
20
+ example_sample = [
21
+ "哈利波特的血缘是什么?",
22
+ "哈利波特的生日是什么?",
23
+ "占卜会议的领导者是谁?",
24
+ "纽约卫生局的创立时间是什么?",
25
+ "哥布林叛乱发生在什么日期?",
26
+ "赫敏的丈夫是谁?",
27
+ ]
28
+
29
+ def demo_func(zh_question):
30
+ assert type(zh_question) == type("")
31
+ output = from_zh_question_to_consider_queries(zh_question,
32
+ top_k = 32, top_p_k = 30, top_e_k = 50
33
+ )
34
+ if type(output) == type((1,)):
35
+ query_list, output = output
36
+ zh_output = trans_output(zh_question ,output)
37
+ else:
38
+ zh_output = None
39
+ #zh_output
40
+ zh_output = ranking_output(zh_question, zh_output)
41
+ if hasattr(zh_output, "to_dict"):
42
+ zh_output = zh_output.head(5)
43
+ zh_output = zh_output[["answer", "sparql_query"]].values.tolist()
44
+ return {"output": zh_output}
45
+
46
+
47
+ demo = gr.Interface(
48
+ fn=demo_func,
49
+ inputs="text",
50
+ outputs="json",
51
+ title=f"Harry Potter Knowledge Question Answer in Chinese 🧙 demonstration",
52
+ examples=example_sample if example_sample else None,
53
+ cache_examples = False,
54
+ )
55
+
56
+ demo.launch(server_name=None, server_port=None)
requirements.txt ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ editdistance==0.6.1
2
+ fuzzywuzzy==0.18.0
3
+ jionlp==1.4.7
4
+ numpy==1.23.0
5
+ pandas==1.4.3
6
+ rapidfuzz==2.0.15
7
+ synonyms==3.18.0
8
+ torch
9
+ tqdm==4.64.0
10
+ "farm-haystack[inmemorygraph]"
11
+ rdflib